use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class PythonPackagedBinaryTest method testRuleKeysFromModuleLayouts.
@Test
public void testRuleKeysFromModuleLayouts() throws IOException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
// Create two different sources, which we'll swap in as different modules.
Path main = tmpDir.newFile().toPath();
Files.write(main, "main".getBytes(Charsets.UTF_8));
Path source1 = tmpDir.newFile().toPath();
Files.write(source1, "hello world".getBytes(Charsets.UTF_8));
Path source2 = tmpDir.newFile().toPath();
Files.write(source2, "goodbye world".getBytes(Charsets.UTF_8));
Path mainRelative = MorePaths.relativize(tmpDir.getRoot().toPath(), main);
Path source1Relative = MorePaths.relativize(tmpDir.getRoot().toPath(), source1);
Path source2Relative = MorePaths.relativize(tmpDir.getRoot().toPath(), source2);
// Setup a rulekey builder factory.
FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of(mainRelative.toString(), Strings.repeat("a", 40), source1Relative.toString(), Strings.repeat("b", 40), source2Relative.toString(), Strings.repeat("c", 40)));
// Calculate the rule keys for the various ways we can layout the source and modules
// across different python libraries.
RuleKey pair1 = getRuleKeyForModuleLayout(new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder), ruleFinder, "main.py", mainRelative, "module/one.py", source1Relative, "module/two.py", source2Relative);
RuleKey pair2 = getRuleKeyForModuleLayout(new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder), ruleFinder, "main.py", mainRelative, "module/two.py", source2Relative, "module/one.py", source1Relative);
RuleKey pair3 = getRuleKeyForModuleLayout(new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder), ruleFinder, "main.py", mainRelative, "module/one.py", source2Relative, "module/two.py", source1Relative);
RuleKey pair4 = getRuleKeyForModuleLayout(new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder), ruleFinder, "main.py", mainRelative, "module/two.py", source1Relative, "module/one.py", source2Relative);
// Make sure only cases where the actual module layouts are different result
// in different rules keys.
assertEquals(pair1, pair2);
assertEquals(pair3, pair4);
assertNotEquals(pair1, pair3);
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class PrebuiltJarSymbolsFinderTest method generatedBinaryJarShouldNotAffectRuleKey.
@Test
public void generatedBinaryJarShouldNotAffectRuleKey() {
SourcePathResolver pathResolver = null;
SourcePathRuleFinder ruleFinder = null;
Path jarFile = tmp.getRoot().resolve("common.jar");
Map<Path, HashCode> pathsToHashes = ImmutableMap.of(jarFile, HashCode.fromString(Strings.repeat("abcd", 10)));
FakeFileHashCache fileHashCache = new FakeFileHashCache(pathsToHashes);
JavaSymbolsRule javaSymbolsRule1 = new JavaSymbolsRule(BuildTargetFactory.newInstance("//foo:rule"), createFinderForGeneratedJar("//foo:jar_genrule1"), /* generatedSymbols */
ImmutableSortedSet.of(), ObjectMappers.newDefaultInstance(), new ProjectFilesystem(tmp.getRoot()));
RuleKey key1 = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(javaSymbolsRule1);
JavaSymbolsRule javaSymbolsRule2 = new JavaSymbolsRule(BuildTargetFactory.newInstance("//foo:rule"), createFinderForGeneratedJar("//foo:jar_genrule2"), /* generatedSymbols */
ImmutableSortedSet.of(), ObjectMappers.newDefaultInstance(), new ProjectFilesystem(tmp.getRoot()));
RuleKey key2 = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(javaSymbolsRule2);
assertNotNull(key1);
assertNotNull(key2);
assertEquals("Keys should match even though different BuildTargetSourcePaths are used.", key1, key2);
}
Aggregations