use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class AaptPackageResourcesTest method setUp.
@Before
public void setUp() throws NoSuchBuildTargetException {
filesystem = new FakeProjectFilesystem();
TargetNode<?, ?> resourceNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource1"), filesystem).setRDotJavaPackage("package1").setRes(Paths.get("res1")).setAssets(new PathSourcePath(filesystem, Paths.get("asset1"))).build();
TargetNode<?, ?> resourceNode2 = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:resource2"), filesystem).setRDotJavaPackage("package2").setRes(Paths.get("res2")).setAssets(new PathSourcePath(filesystem, Paths.get("asset2"))).build();
TargetNode<?, ?> assetsNode = AndroidResourceBuilder.createBuilder(BuildTargetFactory.newInstance("//:assets"), filesystem).setAssets(new PathSourcePath(filesystem, Paths.get("justAssets"))).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(resourceNode, resourceNode2, assetsNode);
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
resource1 = (AndroidResource) ruleResolver.requireRule(resourceNode.getBuildTarget());
resource2 = (AndroidResource) ruleResolver.requireRule(resourceNode2.getBuildTarget());
justAssets = (AndroidResource) ruleResolver.requireRule(assetsNode.getBuildTarget());
ruleFinder = new SourcePathRuleFinder(ruleResolver);
pathResolver = new SourcePathResolver(ruleFinder);
aaptTarget = BuildTargetFactory.newInstance("//foo:bar");
params = new FakeBuildRuleParamsBuilder(aaptTarget).build();
hashCache = new FakeFileHashCache(new HashMap<>());
createPathSourcePath("res1", "resources1");
createPathSourcePath("res2", "resources2");
createPathSourcePath("res3", "resources3");
createPathSourcePath("asset1", "assets1");
createPathSourcePath("asset2", "assets2");
createPathSourcePath("justAssets", "justAssets");
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class DependencyFileRuleKeyFactoryTest method testKeysGetHashed.
@Test
public void testKeysGetHashed() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
BuildRuleResolver ruleResolver = newRuleResolver();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
SourcePath unusedSourcePath = new PathSourcePath(filesystem, Paths.get("input0"));
SourcePath sourcePath = new PathSourcePath(filesystem, Paths.get("input"));
DependencyFileEntry dependencyFileEntry = DependencyFileEntry.fromSourcePath(sourcePath, pathResolver);
ImmutableMap<Path, HashCode> hashes = ImmutableMap.of(pathResolver.getAbsolutePath(sourcePath), HashCode.fromInt(42));
Predicate<SourcePath> coveredPredicate = ImmutableSet.of(sourcePath, unusedSourcePath)::contains;
FakeDepFileBuildRule rule1 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField1 = sourcePath;
@AddToRuleKey
final Object myField2 = unusedSourcePath;
};
rule1.setCoveredByDepFilePredicate(coveredPredicate);
FakeFileHashCache hashCache = new FakeFileHashCache(hashes, true, ImmutableMap.of());
RuleKeyAndInputs res1 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule1, ImmutableList.of(dependencyFileEntry));
FakeDepFileBuildRule rule2 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField1 = unusedSourcePath;
@AddToRuleKey
final Object myField2 = sourcePath;
};
rule2.setCoveredByDepFilePredicate(coveredPredicate);
hashCache = new FakeFileHashCache(hashes, true, ImmutableMap.of());
RuleKeyAndInputs res2 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule2, ImmutableList.of(dependencyFileEntry));
assertThat(res2.getRuleKey(), Matchers.not(Matchers.equalTo(res1.getRuleKey())));
assertThat(res2.getInputs(), Matchers.equalTo(ImmutableSet.of(sourcePath)));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class DependencyFileRuleKeyFactoryTest method testManifestKeyImpl.
private void testManifestKeyImpl(SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, Object fieldValueBefore, Object fieldValueAfter, ImmutableMap<Path, HashCode> hashesBefore, ImmutableMap<Path, HashCode> hashesAfter, Predicate<SourcePath> coveredInputPaths, ImmutableSet<SourcePath> interestingInputPaths, boolean expectSameKeys, ImmutableSet<SourcePath> expectedDepFileInputsAfter, String failureMessage) throws Exception {
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
FakeDepFileBuildRule rule1 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField = fieldValueBefore;
};
rule1.setCoveredByDepFilePredicate(coveredInputPaths);
rule1.setExistenceOfInterestPredicate(interestingInputPaths);
FakeFileHashCache hashCache = new FakeFileHashCache(hashesBefore, true, ImmutableMap.of());
RuleKeyAndInputs res1 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).buildManifestKey(rule1);
FakeDepFileBuildRule rule2 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField = fieldValueAfter;
};
rule2.setCoveredByDepFilePredicate(coveredInputPaths);
rule2.setExistenceOfInterestPredicate(interestingInputPaths);
hashCache = new FakeFileHashCache(hashesAfter, true, ImmutableMap.of());
RuleKeyAndInputs res2 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).buildManifestKey(rule2);
if (expectSameKeys) {
assertThat(failureMessage, res2.getRuleKey(), Matchers.equalTo(res1.getRuleKey()));
} else {
assertThat(failureMessage, res2.getRuleKey(), Matchers.not(Matchers.equalTo(res1.getRuleKey())));
}
assertThat(res2.getInputs(), Matchers.equalTo(expectedDepFileInputsAfter));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromPathSourceChanges.
@Test
public void ruleKeyChangesIfInputContentsFromPathSourceChanges() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
Path output = Paths.get("output");
BuildRule rule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrc(new PathSourcePath(filesystem, output)).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(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)));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromBuildTargetSourcePathInRuleKeyAppendableChanges.
@Test
public void ruleKeyChangesIfInputContentsFromBuildTargetSourcePathInRuleKeyAppendableChanges() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final BuildRule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver, filesystem);
BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setDeclaredDeps(ImmutableSortedSet.of(dep)).setProjectFilesystem(filesystem).build();
BuildRule rule = new NoopBuildRule(params) {
@AddToRuleKey
RuleKeyAppendableWithInput input = new RuleKeyAppendableWithInput(dep.getSourcePathToOutput());
};
// 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)));
}
Aggregations