use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class AaptPackageResourcesTest method testThatAddingResourceDepChangesRuleKey.
@Test
public void testThatAddingResourceDepChangesRuleKey() {
// Generate a rule key for the defaults.
AaptConstructorArgs args = new AaptConstructorArgs();
RuleKey previousRuleKey = calculateRuleKey(args);
args.hasAndroidResourceDeps = ImmutableList.of(resource1);
previousRuleKey = assertKeyChanged(previousRuleKey, args);
args.hasAndroidResourceDeps = ImmutableList.of(resource2);
previousRuleKey = assertKeyChanged(previousRuleKey, args);
args.hasAndroidResourceDeps = ImmutableList.of(resource1, resource2);
previousRuleKey = assertKeyChanged(previousRuleKey, args);
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class AaptPackageResourcesTest method assertKeyChanged.
private RuleKey assertKeyChanged(RuleKey previousKey, AaptConstructorArgs args) {
RuleKey newKey = calculateRuleKey(args);
assertNotEquals(previousKey, newKey);
return newKey;
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class AppleCxxPlatformsTest method constructLinkRuleKeys.
// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<Flavor, RuleKey> constructLinkRuleKeys(ImmutableMap<Flavor, AppleCxxPlatform> cxxPlatforms) throws NoSuchBuildTargetException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("input.o", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
ImmutableMap.Builder<Flavor, RuleKey> ruleKeys = ImmutableMap.builder();
for (Map.Entry<Flavor, AppleCxxPlatform> entry : cxxPlatforms.entrySet()) {
BuildRule rule = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, entry.getValue().getCxxPlatform(), new FakeBuildRuleParamsBuilder(target).build(), resolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), Paths.get("output"), Linker.LinkableDepType.SHARED, ImmutableList.of(), Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(SourcePathArg.from(new FakeSourcePath("input.o"))).build());
ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
}
return ruleKeys.build();
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class CalculateAbiTest method inputRuleKeyDoesNotChangeIfGeneratedBinaryJarDoesNotChange.
@Test
public void inputRuleKeyDoesNotChangeIfGeneratedBinaryJarDoesNotChange() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Setup the initial java library.
Path input = Paths.get("input.java");
BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//:library");
JavaLibraryBuilder builder = JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(new PathSourcePath(filesystem, input));
DefaultJavaLibrary javaLibrary = builder.build(resolver, filesystem);
// Write something to the library source and geneated JAR, so they exist to generate rule keys.
filesystem.writeContentsToPath("stuff", input);
filesystem.writeContentsToPath("stuff", pathResolver.getRelativePath(javaLibrary.getSourcePathToOutput()));
BuildTarget target = BuildTargetFactory.newInstance("//:library-abi");
CalculateAbi calculateAbi = CalculateAbi.of(target, ruleFinder, builder.createBuildRuleParams(resolver, filesystem), new DefaultBuildTargetSourcePath(javaLibraryTarget));
FileHashCache initialHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory initialRuleKeyFactory = new DefaultRuleKeyFactory(0, initialHashCache, pathResolver, ruleFinder);
RuleKey initialKey = initialRuleKeyFactory.build(calculateAbi);
RuleKey initialInputKey = new InputBasedRuleKeyFactory(0, initialHashCache, pathResolver, ruleFinder).build(calculateAbi);
// Write something to the library source and geneated JAR, so they exist to generate rule keys.
filesystem.writeContentsToPath("new stuff", input);
// Re-setup some entities to drop internal rule key caching.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
builder.build(resolver, filesystem);
FileHashCache alteredHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory alteredRuleKeyFactory = new DefaultRuleKeyFactory(0, alteredHashCache, pathResolver, ruleFinder);
RuleKey alteredKey = alteredRuleKeyFactory.build(calculateAbi);
RuleKey alteredInputKey = new InputBasedRuleKeyFactory(0, alteredHashCache, pathResolver, ruleFinder).build(calculateAbi);
assertThat(initialKey, Matchers.not(Matchers.equalTo(alteredKey)));
assertThat(initialInputKey, Matchers.equalTo(alteredInputKey));
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class CalculateAbiTest method ruleKeysChangeIfGeneratedBinaryJarChanges.
@Test
public void ruleKeysChangeIfGeneratedBinaryJarChanges() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Setup the initial java library.
Path input = Paths.get("input.java");
BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//:library");
JavaLibraryBuilder builder = JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(new PathSourcePath(filesystem, input));
DefaultJavaLibrary javaLibrary = builder.build(resolver, filesystem);
// Write something to the library source and geneated JAR, so they exist to generate rule keys.
filesystem.writeContentsToPath("stuff", input);
filesystem.writeContentsToPath("stuff", pathResolver.getRelativePath(javaLibrary.getSourcePathToOutput()));
BuildTarget target = BuildTargetFactory.newInstance("//:library-abi");
CalculateAbi calculateAbi = CalculateAbi.of(target, ruleFinder, builder.createBuildRuleParams(resolver, filesystem), new DefaultBuildTargetSourcePath(javaLibraryTarget));
FileHashCache initialHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory initialRuleKeyFactory = new DefaultRuleKeyFactory(0, initialHashCache, pathResolver, ruleFinder);
RuleKey initialKey = initialRuleKeyFactory.build(calculateAbi);
RuleKey initialInputKey = new InputBasedRuleKeyFactory(0, initialHashCache, pathResolver, ruleFinder).build(calculateAbi);
// Write something to the library source and geneated JAR, so they exist to generate rule keys.
filesystem.writeContentsToPath("new stuff", input);
filesystem.writeContentsToPath("new stuff", pathResolver.getRelativePath(javaLibrary.getSourcePathToOutput()));
// Re-setup some entities to drop internal rule key caching.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
builder.build(resolver, filesystem);
FileHashCache alteredHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
DefaultRuleKeyFactory alteredRuleKeyFactory = new DefaultRuleKeyFactory(0, alteredHashCache, pathResolver, ruleFinder);
RuleKey alteredKey = alteredRuleKeyFactory.build(calculateAbi);
RuleKey alteredInputKey = new InputBasedRuleKeyFactory(0, alteredHashCache, pathResolver, ruleFinder).build(calculateAbi);
assertThat(initialKey, Matchers.not(Matchers.equalTo(alteredKey)));
assertThat(initialInputKey, Matchers.not(Matchers.equalTo(alteredInputKey)));
}
Aggregations