use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class PythonTestDescriptionTest method nonBuildDepsDoNotAffectRuleKey.
@Test
public void nonBuildDepsDoNotAffectRuleKey() throws Exception {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
for (PythonBuckConfig.PackageStyle packageStyle : PythonBuckConfig.PackageStyle.values()) {
// First, calculate the rule key of a python binary with no deps.
PythonTestBuilder pythonTestBuilder = PythonTestBuilder.create(BuildTargetFactory.newInstance("//:bin")).setPackageStyle(packageStyle);
TargetGraph targetGraph = TargetGraphFactory.newInstance(pythonTestBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PythonTest pythonTestWithoutDep = pythonTestBuilder.build(resolver, filesystem, targetGraph);
RuleKey ruleKeyWithoutDep = calculateRuleKey(resolver, pythonTestWithoutDep);
// Next, calculate the rule key of a python binary with a deps on another binary.
CxxBinaryBuilder cxxBinaryBuilder = new CxxBinaryBuilder(BuildTargetFactory.newInstance("//:dep"));
pythonTestBuilder.setDeps(ImmutableSortedSet.of(cxxBinaryBuilder.getTarget()));
targetGraph = TargetGraphFactory.newInstance(cxxBinaryBuilder.build(), pythonTestBuilder.build());
resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
cxxBinaryBuilder.build(resolver, filesystem, targetGraph);
PythonTest pythonBinaryWithDep = pythonTestBuilder.build(resolver, filesystem, targetGraph);
RuleKey ruleKeyWithDep = calculateRuleKey(resolver, pythonBinaryWithDep);
// Verify that the rule keys are identical.
assertThat(ruleKeyWithoutDep, Matchers.equalTo(ruleKeyWithDep));
}
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyDoesNotChangeIfNonHashingSourcePathContentChanges.
@Test
public void ruleKeyDoesNotChangeIfNonHashingSourcePathContentChanges() throws NoSuchBuildTargetException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final ProjectFilesystem fileSystem = new FakeProjectFilesystem();
// Build a rule key with a particular hash set for the output for the above rule.
Path filePath = fileSystem.getPath("file.txt");
FakeFileHashCache hashCache = new FakeFileHashCache(new HashMap<>());
hashCache.set(filePath.toAbsolutePath(), HashCode.fromInt(0));
PathSourcePath sourcePath = new PathSourcePath(fileSystem, filePath);
NonHashableSourcePathContainer nonHashablePath = new NonHashableSourcePathContainer(sourcePath);
RuleKey inputKey1 = computeRuleKey(hashCache, pathResolver, ruleFinder, nonHashablePath);
hashCache.set(filePath.toAbsolutePath(), HashCode.fromInt(1));
RuleKey inputKey2 = computeRuleKey(hashCache, pathResolver, ruleFinder, nonHashablePath);
assertThat(inputKey1, Matchers.equalTo(inputKey2));
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyDoesNotChangeWhenOnlyDependencyRuleKeyChanges.
@Test
public void ruleKeyDoesNotChangeWhenOnlyDependencyRuleKeyChanges() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Path depOutput = Paths.get("output");
FakeBuildRule dep = resolver.addToIndex(new FakeBuildRule(BuildTargetFactory.newInstance("//:dep"), filesystem, pathResolver));
dep.setOutputFile(depOutput.toString());
filesystem.writeContentsToPath("hello", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(depOutput), HashCode.fromInt(0)));
BuildRule rule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrcs(ImmutableList.of(dep.getSourcePathToOutput())).build(resolver, filesystem);
RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
assertThat(inputKey1, Matchers.equalTo(inputKey2));
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromBuildTargetSourcePathChanges.
@Test
public void ruleKeyChangesIfInputContentsFromBuildTargetSourcePathChanges() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver, filesystem);
BuildRule rule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrc(dep.getSourcePathToOutput()).build(resolver, filesystem);
// Build a rule key with a particular hash set for the output for the above rule.
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(pathResolver.getAbsolutePath(Preconditions.checkNotNull(dep.getSourcePathToOutput())), HashCode.fromInt(0)));
RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
// Now, build a rule key with a different hash for the output for the above rule.
hashCache = new FakeFileHashCache(ImmutableMap.of(pathResolver.getAbsolutePath((Preconditions.checkNotNull(dep.getSourcePathToOutput()))), HashCode.fromInt(1)));
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2)));
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges.
@Test
public void ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final Path output = Paths.get("output");
BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setProjectFilesystem(filesystem).build();
BuildRule rule = new NoopBuildRule(params) {
@AddToRuleKey
RuleKeyAppendableWithInput input = new RuleKeyAppendableWithInput(new PathSourcePath(filesystem, output));
};
// Build a rule key with a particular hash set for the output for the above rule.
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(0)));
RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
// Now, build a rule key with a different hash for the output for the above rule.
hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(1)));
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2)));
}
Aggregations