Search in sources :

Example 46 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class ParserTest method whenBuildFileContainsSourcesUnderSymLinkDeletedSourcesNotRemovedUntilCacheCleaned.

@Test
public void whenBuildFileContainsSourcesUnderSymLinkDeletedSourcesNotRemovedUntilCacheCleaned() throws Exception {
    // This test depends on creating symbolic links which we cannot do on Windows.
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    tempDir.newFolder("bar");
    tempDir.newFile("bar/Bar.java");
    tempDir.newFolder("foo");
    Path bazSourceFile = tempDir.newFile("bar/Baz.java");
    Path rootPath = tempDir.getRoot().toRealPath();
    Files.createSymbolicLink(rootPath.resolve("foo/bar"), rootPath.resolve("bar"));
    Path testBuckFile = rootPath.resolve("foo").resolve("BUCK");
    Files.write(testBuckFile, "java_library(name = 'lib', srcs=glob(['bar/*.java']))\n".getBytes(UTF_8));
    // Fetch //:lib to put it in cache.
    BuildTarget libTarget = BuildTarget.builder(cellRoot, "//foo", "lib").build();
    Iterable<BuildTarget> buildTargets = ImmutableList.of(libTarget);
    {
        TargetGraph targetGraph = parser.buildTargetGraph(eventBus, cell, false, executorService, buildTargets);
        BuildRuleResolver resolver = buildActionGraph(eventBus, targetGraph);
        JavaLibrary libRule = (JavaLibrary) resolver.requireRule(libTarget);
        assertEquals(ImmutableSortedSet.of(new PathSourcePath(filesystem, Paths.get("foo/bar/Bar.java")), new PathSourcePath(filesystem, Paths.get("foo/bar/Baz.java"))), libRule.getJavaSrcs());
    }
    Files.delete(bazSourceFile);
    WatchEvent<Path> deleteEvent = createPathEvent(Paths.get("bar/Baz.java"), StandardWatchEventKinds.ENTRY_DELETE);
    parser.onFileSystemChange(deleteEvent);
    {
        TargetGraph targetGraph = parser.buildTargetGraph(eventBus, cell, false, executorService, buildTargets);
        BuildRuleResolver resolver = buildActionGraph(eventBus, targetGraph);
        JavaLibrary libRule = (JavaLibrary) resolver.requireRule(libTarget);
        assertEquals(ImmutableSortedSet.of(new PathSourcePath(filesystem, Paths.get("foo/bar/Bar.java"))), libRule.getJavaSrcs());
    }
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 47 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath 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 48 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.

the class InputBasedRuleKeyFactoryTest method ruleKeysForOversizedRules.

@Test
public void ruleKeysForOversizedRules() 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)));
    final int sizeLimit = 200;
    InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, sizeLimit);
    // Create rule with inputs that make it go past the size limit, and verify the rule key factory
    // doesn't create a rule key.
    final int tooLargeRuleSize = 300;
    assertThat(tooLargeRuleSize, Matchers.greaterThan(sizeLimit));
    Path tooLargeInput = filesystem.getPath("too_large_input");
    filesystem.writeBytesToPath(new byte[tooLargeRuleSize], tooLargeInput);
    BuildRule tooLargeRule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:large_rule")).setOut("out").setSrc(new PathSourcePath(filesystem, tooLargeInput)).build(resolver, filesystem);
    expectedException.expect(SizeLimiter.SizeLimitException.class);
    factory.build(tooLargeRule);
}
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 49 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath 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 50 with PathSourcePath

use of com.facebook.buck.rules.PathSourcePath 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

PathSourcePath (com.facebook.buck.rules.PathSourcePath)114 Test (org.junit.Test)82 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)69 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)68 SourcePath (com.facebook.buck.rules.SourcePath)65 Path (java.nio.file.Path)63 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)60 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)58 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)56 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)52 BuildTarget (com.facebook.buck.model.BuildTarget)51 TargetGraph (com.facebook.buck.rules.TargetGraph)37 BuildRule (com.facebook.buck.rules.BuildRule)26 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)21 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)16 RuleKey (com.facebook.buck.rules.RuleKey)15 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)15 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)14 ImmutableList (com.google.common.collect.ImmutableList)14