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