Search in sources :

Example 11 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class TargetGraphHashingTest method hashChangesForDependentNodeWhenDepsChange.

@Test
public void hashChangesForDependentNodeWhenDepsChange() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
    BuildTarget nodeTarget = BuildTargetFactory.newInstance("//foo:lib");
    BuildTarget depTarget = BuildTargetFactory.newInstance("//dep:lib");
    TargetGraph targetGraphA = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(64738));
    TargetGraph targetGraphB = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(84552));
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("dep/DepLib.java"), HashCode.fromString("123456")));
    Map<BuildTarget, HashCode> resultA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(targetGraphA.get(nodeTarget))).hashTargetGraph();
    Map<BuildTarget, HashCode> resultB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(targetGraphB.get(nodeTarget))).hashTargetGraph();
    assertThat(resultA, aMapWithSize(2));
    assertThat(resultA, hasKey(nodeTarget));
    assertThat(resultA, hasKey(depTarget));
    assertThat(resultB, aMapWithSize(2));
    assertThat(resultB, hasKey(nodeTarget));
    assertThat(resultB, hasKey(depTarget));
    assertThat(resultA.get(nodeTarget), not(equalTo(resultB.get(nodeTarget))));
    assertThat(resultA.get(depTarget), not(equalTo(resultB.get(depTarget))));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) HashCode(com.google.common.hash.HashCode) BuildId(com.facebook.buck.model.BuildId) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Test(org.junit.Test)

Example 12 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache 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));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) NonHashableSourcePathContainer(com.facebook.buck.rules.NonHashableSourcePathContainer) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) 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 13 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache 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));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) 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 14 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache 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)));
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) 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 15 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache 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)));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) 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