Search in sources :

Example 41 with FakeFileHashCache

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);
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 42 with FakeFileHashCache

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);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) HashCode(com.google.common.hash.HashCode) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) Test(org.junit.Test)

Aggregations

FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)42 Test (org.junit.Test)38 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)24 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)24 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)22 RuleKey (com.facebook.buck.rules.RuleKey)22 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)22 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)20 Path (java.nio.file.Path)20 PathSourcePath (com.facebook.buck.rules.PathSourcePath)19 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)18 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)16 SourcePath (com.facebook.buck.rules.SourcePath)16 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)14 BuildRule (com.facebook.buck.rules.BuildRule)14 FileHashCache (com.facebook.buck.util.cache.FileHashCache)14 HashCode (com.google.common.hash.HashCode)13 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)12 BuildTarget (com.facebook.buck.model.BuildTarget)11 BorrowablePath (com.facebook.buck.io.BorrowablePath)8