Search in sources :

Example 6 with GenruleBuilder

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

the class PythonTestDescriptionTest method versionedResources.

@Test
public void versionedResources() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildTarget target = BuildTargetFactory.newInstance("//foo:lib");
    SourcePath matchedSource = new FakeSourcePath("foo/a.py");
    SourcePath unmatchedSource = new FakeSourcePath("foo/b.py");
    GenruleBuilder depBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out");
    AbstractNodeBuilder<?, ?, ?> builder = PythonTestBuilder.create(target).setVersionedResources(VersionMatchedCollection.<SourceList>builder().add(ImmutableMap.of(depBuilder.getTarget(), Version.of("1.0")), SourceList.ofUnnamedSources(ImmutableSortedSet.of(matchedSource))).add(ImmutableMap.of(depBuilder.getTarget(), Version.of("2.0")), SourceList.ofUnnamedSources(ImmutableSortedSet.of(unmatchedSource))).build()).setSelectedVersions(ImmutableMap.of(depBuilder.getTarget(), Version.of("1.0")));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(depBuilder.build(), builder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    depBuilder.build(resolver, filesystem, targetGraph);
    PythonTest test = (PythonTest) builder.build(resolver, filesystem, targetGraph);
    assertThat(test.getBinary().getComponents().getResources().values(), Matchers.allOf(Matchers.hasItem(matchedSource), Matchers.not(Matchers.hasItem(unmatchedSource))));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 7 with GenruleBuilder

use of com.facebook.buck.shell.GenruleBuilder 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 8 with GenruleBuilder

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

the class PythonLibraryDescriptionTest method versionedSrcs.

@Test
public void versionedSrcs() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:lib");
    SourcePath matchedSource = new FakeSourcePath("foo/a.py");
    SourcePath unmatchedSource = new FakeSourcePath("foo/b.py");
    GenruleBuilder transitiveDepBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:tdep")).setOut("out");
    VersionedAliasBuilder depBuilder = new VersionedAliasBuilder(BuildTargetFactory.newInstance("//:dep")).setVersions(ImmutableMap.of(Version.of("1.0"), transitiveDepBuilder.getTarget(), Version.of("2.0"), transitiveDepBuilder.getTarget()));
    AbstractNodeBuilder<?, ?, ?> builder = new PythonLibraryBuilder(target).setVersionedSrcs(VersionMatchedCollection.<SourceList>builder().add(ImmutableMap.of(depBuilder.getTarget(), Version.of("1.0")), SourceList.ofUnnamedSources(ImmutableSortedSet.of(matchedSource))).add(ImmutableMap.of(depBuilder.getTarget(), Version.of("2.0")), SourceList.ofUnnamedSources(ImmutableSortedSet.of(unmatchedSource))).build());
    TargetGraph targetGraph = VersionedTargetGraphBuilder.transform(new FixedVersionSelector(ImmutableMap.of(builder.getTarget(), ImmutableMap.of(depBuilder.getTarget(), Version.of("1.0")))), TargetGraphAndBuildTargets.of(TargetGraphFactory.newInstance(transitiveDepBuilder.build(), depBuilder.build(), builder.build()), ImmutableSet.of(builder.getTarget())), new ForkJoinPool()).getTargetGraph();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PythonLibrary library = (PythonLibrary) resolver.requireRule(builder.getTarget());
    assertThat(library.getPythonPackageComponents(PythonTestUtils.PYTHON_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORM).getModules().values(), Matchers.contains(matchedSource));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) CxxGenruleBuilder(com.facebook.buck.cxx.CxxGenruleBuilder) FixedVersionSelector(com.facebook.buck.versions.FixedVersionSelector) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VersionedAliasBuilder(com.facebook.buck.versions.VersionedAliasBuilder) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) SourceList(com.facebook.buck.rules.coercer.SourceList) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test)

Example 9 with GenruleBuilder

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

the class PrebuiltCxxLibraryDescriptionTest method locationMacro.

@Test
public void locationMacro() throws NoSuchBuildTargetException {
    ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
    CellPathResolver cellRoots = TestCellBuilder.createCellRoots(filesystem);
    Optional<String> libName = Optional.of("test");
    Optional<String> libDir = Optional.of("$(location //other:gen_lib)/");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    BuildTarget genTarget = BuildTargetFactory.newInstance("//other:gen_lib");
    GenruleBuilder genruleBuilder = GenruleBuilder.newGenruleBuilder(genTarget).setOut("lib_dir");
    BuildRule genRule = genruleBuilder.build(resolver);
    CxxPlatform platform = CxxPlatformUtils.DEFAULT_PLATFORM.withFlavor(InternalFlavor.of("PLATFORM1"));
    Path path = pathResolver.getAbsolutePath(Preconditions.checkNotNull(genRule.getSourcePathToOutput()));
    final SourcePath staticLibraryPath = PrebuiltCxxLibraryDescription.getStaticLibraryPath(TARGET, cellRoots, filesystem, resolver, platform, Optional.empty(), libDir, libName);
    assertEquals(TARGET.getBasePath().resolve(String.format("%s/libtest.a", path)), pathResolver.getAbsolutePath(staticLibraryPath));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) CellPathResolver(com.facebook.buck.rules.CellPathResolver) 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) Test(org.junit.Test)

Example 10 with GenruleBuilder

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

the class PrebuiltCxxLibraryDescriptionTest method testBuildSharedWithDep.

@Test
public void testBuildSharedWithDep() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    CxxPlatform platform = CxxLibraryBuilder.createDefaultPlatform();
    BuildTarget target = BuildTargetFactory.newInstance("//:x").withFlavors(platform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR);
    GenruleBuilder genruleBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_libx")).setOut("gen_libx").setCmd("something");
    PrebuiltCxxLibraryBuilder builder = new PrebuiltCxxLibraryBuilder(target).setLibName("x").setLibDir("$(location //:gen_libx)");
    TargetGraph targetGraph = TargetGraphFactory.newInstance(genruleBuilder.build(), builder.build());
    BuildRule genSrc = genruleBuilder.build(resolver, filesystem, targetGraph);
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    filesystem.writeContentsToPath("class Test {}", pathResolver.getAbsolutePath(Preconditions.checkNotNull(genSrc.getSourcePathToOutput())).resolve("libx.so"));
    CxxLink lib = (CxxLink) builder.build(resolver, filesystem, targetGraph);
    assertNotNull(lib);
    assertThat(lib.getDeps(), Matchers.contains(genSrc));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) 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) Test(org.junit.Test)

Aggregations

BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)14 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)14 GenruleBuilder (com.facebook.buck.shell.GenruleBuilder)14 Test (org.junit.Test)14 TargetGraph (com.facebook.buck.rules.TargetGraph)13 BuildTarget (com.facebook.buck.model.BuildTarget)12 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)11 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)10 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)10 BuildRule (com.facebook.buck.rules.BuildRule)9 SourcePath (com.facebook.buck.rules.SourcePath)7 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)6 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)6 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)6 PathSourcePath (com.facebook.buck.rules.PathSourcePath)3 Genrule (com.facebook.buck.shell.Genrule)3 Path (java.nio.file.Path)3 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)2 CxxGenruleBuilder (com.facebook.buck.cxx.CxxGenruleBuilder)2