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))));
}
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));
}
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));
}
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));
}
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));
}
Aggregations