Search in sources :

Example 21 with FileHashCache

use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.

the class InputBasedRuleKeyFactoryTest method ruleKeyNotCalculatedIfSizeLimitHitWithDirectory.

@Test
public void ruleKeyNotCalculatedIfSizeLimitHitWithDirectory() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    // Create a directory of files which combine to pass size limit.
    Path input = filesystem.getPath("input");
    filesystem.mkdirs(input);
    filesystem.writeBytesToPath(new byte[150], input.resolve("file1"));
    filesystem.writeBytesToPath(new byte[150], input.resolve("file2"));
    // Construct rule which uses inputs.
    BuildRule rule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrc(new PathSourcePath(filesystem, input)).build(resolver, filesystem);
    // Verify rule key isn't calculated.
    expectedException.expect(SizeLimiter.SizeLimitException.class);
    new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, 200).build(rule);
}
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) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) 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)

Example 22 with FileHashCache

use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.

the class ShTestDescriptionTest method getRuleKey.

private RuleKey getRuleKey(BuildRule rule) {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(rule.getProjectFilesystem())));
    DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
    return factory.build(rule);
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 23 with FileHashCache

use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.

the class DefaultJavaLibraryTest method testInputBasedRuleKeyWithJavaLibraryDep.

/**
   * Tests that input-based rule keys work properly with simple Java library deps.
   */
@Test
public void testInputBasedRuleKeyWithJavaLibraryDep() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    // Setup a Java library which builds against another Java library dep.
    TargetNode<JavaLibraryDescription.Arg, ?> depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep"), filesystem).addSrc(Paths.get("Source.java")).build();
    TargetNode<?, ?> libraryNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib"), filesystem).addDep(depNode.getBuildTarget()).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, libraryNode);
    ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    JavaLibrary dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
    JavaLibrary library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
    filesystem.writeContentsToPath("JAR contents", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
    writeAbiJar(filesystem, pathResolver.getRelativePath(ruleResolver.requireRule(dep.getAbiJar().get()).getSourcePathToOutput()), "Source.class", "ABI JAR contents");
    FileHashCache originalHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(0, originalHashCache, pathResolver, ruleFinder);
    RuleKey originalRuleKey = factory.build(library);
    // Now change the Java library dependency such that its rule key changes, and change its JAR
    // contents, but keep its ABI JAR the same.  This should *not* affect the input-based rule key
    // of the consuming java library, since it only cares about the contents of the ABI JAR.
    depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("Source.java")).setResourcesRoot(Paths.get("some root that changes the rule key")).build();
    targetGraph = TargetGraphFactory.newInstance(depNode, libraryNode);
    ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ruleFinder = new SourcePathRuleFinder(ruleResolver);
    pathResolver = new SourcePathResolver(ruleFinder);
    dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
    library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
    filesystem.writeContentsToPath("different JAR contents", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
    FileHashCache unaffectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    factory = new InputBasedRuleKeyFactory(0, unaffectedHashCache, pathResolver, ruleFinder);
    RuleKey unaffectedRuleKey = factory.build(library);
    assertThat(originalRuleKey, equalTo(unaffectedRuleKey));
    // Now actually change the Java library dependency's ABI JAR.  This *should* affect the
    // input-based rule key of the consuming java library.
    ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ruleFinder = new SourcePathRuleFinder(ruleResolver);
    pathResolver = new SourcePathResolver(ruleFinder);
    dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
    library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
    writeAbiJar(filesystem, pathResolver.getRelativePath(ruleResolver.requireRule(dep.getAbiJar().get()).getSourcePathToOutput()), "Source.class", "changed ABI JAR contents");
    FileHashCache affectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    factory = new InputBasedRuleKeyFactory(0, affectedHashCache, pathResolver, ruleFinder);
    RuleKey affectedRuleKey = factory.build(library);
    assertThat(originalRuleKey, Matchers.not(equalTo(affectedRuleKey)));
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 24 with FileHashCache

use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.

the class DefaultJavaLibraryTest method testInputBasedRuleKeySourceChange.

/**
   * Tests that input-based rule keys work properly with generated sources.
   */
@Test
public void testInputBasedRuleKeySourceChange() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    // Setup a Java library consuming a source generated by a genrule and grab its rule key.
    BuildRule genSrc = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_srcs")).setOut("Test.java").setCmd("something").build(ruleResolver, filesystem);
    filesystem.writeContentsToPath("class Test {}", pathResolver.getRelativePath(genSrc.getSourcePathToOutput()));
    JavaLibrary library = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addSrc(genSrc.getSourcePathToOutput()).build(ruleResolver, filesystem);
    FileHashCache originalHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(0, originalHashCache, pathResolver, ruleFinder);
    RuleKey originalRuleKey = factory.build(library);
    // Now change the genrule such that its rule key changes, but it's output stays the same (since
    // we don't change it).  This should *not* affect the input-based rule key of the consuming
    // java library, since it only cares about the contents of the source.
    ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    genSrc = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_srcs")).setOut("Test.java").setCmd("something else").build(ruleResolver, filesystem);
    library = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addSrc(genSrc.getSourcePathToOutput()).build(ruleResolver, filesystem);
    FileHashCache unaffectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    factory = new InputBasedRuleKeyFactory(0, unaffectedHashCache, pathResolver, ruleFinder);
    RuleKey unaffectedRuleKey = factory.build(library);
    assertThat(originalRuleKey, equalTo(unaffectedRuleKey));
    // Now actually modify the source, which should make the input-based rule key change.
    ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    genSrc = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_srcs")).setOut("Test.java").setCmd("something else").build(ruleResolver, filesystem);
    filesystem.writeContentsToPath("class Test2 {}", pathResolver.getRelativePath(genSrc.getSourcePathToOutput()));
    library = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addSrc(genSrc.getSourcePathToOutput()).build(ruleResolver, filesystem);
    FileHashCache affectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    factory = new InputBasedRuleKeyFactory(0, affectedHashCache, pathResolver, ruleFinder);
    RuleKey affectedRuleKey = factory.build(library);
    assertThat(originalRuleKey, Matchers.not(equalTo(affectedRuleKey)));
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) BuildRule(com.facebook.buck.rules.BuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) 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 25 with FileHashCache

use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.

the class SanitizedArgTest method createRuleKeyBuilder.

private RuleKeyBuilder<RuleKey> createRuleKeyBuilder() {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(projectFilesystem)));
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    return new UncachedRuleKeyBuilder(ruleFinder, resolver, fileHashCache, new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder));
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) UncachedRuleKeyBuilder(com.facebook.buck.rules.keys.UncachedRuleKeyBuilder) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Aggregations

FileHashCache (com.facebook.buck.util.cache.FileHashCache)46 Test (org.junit.Test)37 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)31 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)30 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)30 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)27 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)25 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)25 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)22 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)22 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)18 Path (java.nio.file.Path)17 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)14 BuildTarget (com.facebook.buck.model.BuildTarget)14 RuleKey (com.facebook.buck.rules.RuleKey)14 NullFileHashCache (com.facebook.buck.util.cache.NullFileHashCache)12 HashCode (com.google.common.hash.HashCode)12 BuildRule (com.facebook.buck.rules.BuildRule)11 PathSourcePath (com.facebook.buck.rules.PathSourcePath)11 SourcePath (com.facebook.buck.rules.SourcePath)10