Search in sources :

Example 11 with Genrule

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

the class PythonBinaryDescriptionTest method thatComponentSourcePathDepsPropagateProperly.

@Test
public void thatComponentSourcePathDepsPropagateProperly() throws Exception {
    GenruleBuilder genruleBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen")).setOut("blah.py");
    PythonLibraryBuilder libBuilder = new PythonLibraryBuilder(BuildTargetFactory.newInstance("//:lib")).setSrcs(SourceList.ofUnnamedSources(ImmutableSortedSet.of(new DefaultBuildTargetSourcePath(genruleBuilder.getTarget()))));
    PythonBinaryBuilder binaryBuilder = PythonBinaryBuilder.create(BuildTargetFactory.newInstance("//:bin")).setMainModule("main").setDeps(ImmutableSortedSet.of(libBuilder.getTarget()));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genruleBuilder.build(), libBuilder.build(), binaryBuilder.build());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    Genrule genrule = genruleBuilder.build(resolver, filesystem, targetGraph);
    libBuilder.build(resolver, filesystem, targetGraph);
    PythonBinary binary = binaryBuilder.build(resolver, filesystem, targetGraph);
    assertThat(binary.getDeps(), Matchers.hasItem(genrule));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Genrule(com.facebook.buck.shell.Genrule) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 12 with Genrule

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

the class PythonBinaryDescriptionTest method packagedBinaryAttachedPexToolDeps.

@Test
public void packagedBinaryAttachedPexToolDeps() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bin");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    final Genrule pexTool = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:pex_tool")).setOut("pex-tool").build(resolver);
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

        @Override
        public PackageStyle getPackageStyle() {
            return PackageStyle.STANDALONE;
        }

        @Override
        public Tool getPexTool(BuildRuleResolver resolver) {
            return new CommandTool.Builder().addArg(SourcePathArg.of(pexTool.getSourcePathToOutput())).build();
        }
    };
    PythonBinaryBuilder builder = new PythonBinaryBuilder(target, config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    PythonPackagedBinary binary = (PythonPackagedBinary) builder.setMainModule("main").build(resolver);
    assertThat(binary.getDeps(), Matchers.hasItem(pexTool));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) ShBinaryBuilder(com.facebook.buck.shell.ShBinaryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) CxxBinaryBuilder(com.facebook.buck.cxx.CxxBinaryBuilder) Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 13 with Genrule

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

the class PythonBinaryDescriptionTest method thatMainSourcePathPropagatesToDeps.

@Test
public void thatMainSourcePathPropagatesToDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen")).setOut("blah.py").build(resolver);
    PythonBinary binary = PythonBinaryBuilder.create(BuildTargetFactory.newInstance("//:bin")).setMain(genrule.getSourcePathToOutput()).build(resolver);
    assertThat(binary.getDeps(), Matchers.hasItem(genrule));
}
Also used : Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 14 with Genrule

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

the class SourcePathResolverTest method getSourcePathNameOnExplicitBuildTargetSourcePath.

@Test
public void getSourcePathNameOnExplicitBuildTargetSourcePath() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    // Verify that wrapping a genrule in a ExplicitBuildTargetSourcePath resolves to the output name
    // of that genrule.
    String out = "test/blah.txt";
    Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut(out).build(resolver);
    ExplicitBuildTargetSourcePath buildTargetSourcePath1 = new ExplicitBuildTargetSourcePath(genrule.getBuildTarget(), Paths.get("foo"));
    String actual1 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath1);
    assertEquals(out, actual1);
    BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//package:fake");
    FakeBuildRule fakeBuildRule = new FakeBuildRule(new FakeBuildRuleParamsBuilder(fakeBuildTarget).build(), pathResolver);
    resolver.addToIndex(fakeBuildRule);
    ExplicitBuildTargetSourcePath buildTargetSourcePath2 = new ExplicitBuildTargetSourcePath(fakeBuildRule.getBuildTarget(), fakeBuildRule.getBuildTarget().getBasePath().resolve("foo/bar"));
    String actual2 = pathResolver.getSourcePathName(BuildTargetFactory.newInstance("//:test"), buildTargetSourcePath2);
    assertEquals(Paths.get("foo", "bar").toString(), actual2);
    BuildTarget otherFakeBuildTarget = BuildTargetFactory.newInstance("//package:fake2");
    FakeBuildRule otherFakeBuildRule = new FakeBuildRule(new FakeBuildRuleParamsBuilder(otherFakeBuildTarget).build(), pathResolver);
    resolver.addToIndex(otherFakeBuildRule);
    ExplicitBuildTargetSourcePath buildTargetSourcePath3 = new ExplicitBuildTargetSourcePath(otherFakeBuildRule.getBuildTarget(), Paths.get("buck-out/gen/package/foo/bar"));
    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 15 with Genrule

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

the class SourcePathResolverTest method getSourcePathNameOnArchiveMemberSourcePath.

@Test(expected = IllegalArgumentException.class)
public void getSourcePathNameOnArchiveMemberSourcePath() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    String out = "test/blah.jar";
    Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut(out).build(resolver);
    SourcePath archiveSourcePath = genrule.getSourcePathToOutput();
    ArchiveMemberSourcePath archiveMemberSourcePath = new ArchiveMemberSourcePath(archiveSourcePath, Paths.get("member"));
    pathResolver.getSourcePathName(null, archiveMemberSourcePath);
}
Also used : Genrule(com.facebook.buck.shell.Genrule) 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