Search in sources :

Example 16 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class MacroArgTest method getDeps.

@Test
public void getDeps() throws Exception {
    MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("loc", new LocationMacroExpander()));
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    Genrule rule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("output").build(resolver);
    MacroArg arg = new MacroArg(macroHandler, rule.getBuildTarget(), TestCellBuilder.createCellRoots(filesystem), resolver, "$(loc //:rule)");
    assertThat(arg.getDeps(ruleFinder), Matchers.contains(rule));
}
Also used : MacroHandler(com.facebook.buck.rules.macros.MacroHandler) LocationMacroExpander(com.facebook.buck.rules.macros.LocationMacroExpander) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 17 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class SourcePathArgTest method getDeps.

@Test
public void getDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    Genrule rule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("output").build(resolver);
    SourcePathArg arg = SourcePathArg.of(rule.getSourcePathToOutput());
    assertThat(arg.getDeps(ruleFinder), Matchers.contains(rule));
}
Also used : Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 18 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class SourcePathResolverTest method getSourcePathNameOnForwardingBuildTargetSourcePath.

@Test
public void getSourcePathNameOnForwardingBuildTargetSourcePath() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    FakeBuildRule rule = new FakeBuildRule(BuildTargetFactory.newInstance("//package:baz"), pathResolver);
    resolver.addToIndex(rule);
    // Verify that wrapping a genrule in a ForwardingBuildTargetSourcePath resolves to the output
    // name of that genrule.
    String out = "test/blah.txt";
    Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut(out).build(resolver);
    ForwardingBuildTargetSourcePath buildTargetSourcePath1 = new ForwardingBuildTargetSourcePath(rule.getBuildTarget(), genrule.getSourcePathToOutput());
    String actual1 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath1);
    assertEquals(out, actual1);
    ForwardingBuildTargetSourcePath buildTargetSourcePath2 = new ForwardingBuildTargetSourcePath(rule.getBuildTarget(), new FakeSourcePath("foo/bar"));
    String actual2 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath2);
    assertEquals(Paths.get("foo", "bar").toString(), actual2);
    BuildTarget otherFakeBuildTarget = BuildTargetFactory.newInstance("//package2:fake2");
    FakeBuildRule otherFakeBuildRule = new FakeBuildRule(new FakeBuildRuleParamsBuilder(otherFakeBuildTarget).build(), pathResolver);
    resolver.addToIndex(otherFakeBuildRule);
    ForwardingBuildTargetSourcePath buildTargetSourcePath3 = new ForwardingBuildTargetSourcePath(otherFakeBuildRule.getBuildTarget(), buildTargetSourcePath2);
    String actual3 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath3);
    assertEquals(Paths.get("foo", "bar").toString(), actual3);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) Genrule(com.facebook.buck.shell.Genrule) Test(org.junit.Test)

Example 19 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class SourcePathResolverTest method getSourcePathNameOnDefaultBuildTargetSourcePath.

@Test
public void getSourcePathNameOnDefaultBuildTargetSourcePath() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    // Verify that wrapping a genrule in a BuildTargetSourcePath resolves to the output name of
    // that genrule.
    String out = "test/blah.txt";
    Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut(out).build(resolver);
    DefaultBuildTargetSourcePath buildTargetSourcePath1 = new DefaultBuildTargetSourcePath(genrule.getBuildTarget());
    String actual1 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath1);
    assertEquals(out, actual1);
    // Test that using other BuildRule types resolves to the short name.
    BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//:fake");
    FakeBuildRule fakeBuildRule = new FakeBuildRule(new FakeBuildRuleParamsBuilder(fakeBuildTarget).build(), pathResolver);
    resolver.addToIndex(fakeBuildRule);
    DefaultBuildTargetSourcePath buildTargetSourcePath2 = new DefaultBuildTargetSourcePath(fakeBuildRule.getBuildTarget());
    String actual2 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath2);
    assertEquals(fakeBuildTarget.getShortName(), actual2);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) Genrule(com.facebook.buck.shell.Genrule) Test(org.junit.Test)

Example 20 with Genrule

use of com.facebook.buck.shell.Genrule in project buck by facebook.

the class SymlinkTreeTest method testSymlinkTreeDependentRuleKeyChangesWhenLinkSourceContentChanges.

@Test
public void testSymlinkTreeDependentRuleKeyChangesWhenLinkSourceContentChanges() throws Exception {
    // If a dependent of a symlink tree uses the symlink tree's output as an input, that dependent's
    // rulekey must change when the link contents change.
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    ruleResolver.addToIndex(symlinkTreeBuildRule);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableList.of(symlinkTreeBuildRule.getSourcePathToOutput())).setOut("out").build(ruleResolver);
    DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
    FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
    RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashLoader, pathResolver, ruleFinder).build(genrule);
    Path existingFile = pathResolver.getAbsolutePath(links.values().asList().get(0));
    Files.write(existingFile, "something new".getBytes(Charsets.UTF_8));
    hashCache.invalidateAll();
    RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashLoader, pathResolver, ruleFinder).build(genrule);
    // Verify that the rules keys are different.
    assertNotEquals(ruleKey1, ruleKey2);
}
Also used : Path(java.nio.file.Path) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Genrule(com.facebook.buck.shell.Genrule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Aggregations

Genrule (com.facebook.buck.shell.Genrule)31 Test (org.junit.Test)30 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)24 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)24 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)21 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)17 BuildTarget (com.facebook.buck.model.BuildTarget)14 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 BuildRule (com.facebook.buck.rules.BuildRule)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 TargetGraph (com.facebook.buck.rules.TargetGraph)7 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)6 PatternMatchedCollection (com.facebook.buck.rules.coercer.PatternMatchedCollection)4 GenruleBuilder (com.facebook.buck.shell.GenruleBuilder)4 ImmutableList (com.google.common.collect.ImmutableList)4 CxxLink (com.facebook.buck.cxx.CxxLink)3 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)3 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)3 Path (java.nio.file.Path)2 CxxBinary (com.facebook.buck.cxx.CxxBinary)1