use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PythonTestDescriptionTest method versionedSrcs.
@Test
public void versionedSrcs() 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).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()).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().getModules().values(), Matchers.allOf(Matchers.hasItem(matchedSource), Matchers.not(Matchers.hasItem(unmatchedSource))));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PythonTestDescriptionTest method platformResources.
@Test
public void platformResources() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//foo:test");
SourcePath matchedSource = new FakeSourcePath("foo/a.dat");
SourcePath unmatchedSource = new FakeSourcePath("foo/b.dat");
PythonTestBuilder builder = PythonTestBuilder.create(target).setPlatformResources(PatternMatchedCollection.<SourceList>builder().add(Pattern.compile(PythonTestUtils.PYTHON_PLATFORM.getFlavor().toString()), SourceList.ofUnnamedSources(ImmutableSortedSet.of(matchedSource))).add(Pattern.compile("won't match anything"), SourceList.ofUnnamedSources(ImmutableSortedSet.of(unmatchedSource))).build());
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
PythonTest test = builder.build(new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer()), filesystem, targetGraph);
assertThat(test.getBinary().getComponents().getResources().values(), Matchers.allOf(Matchers.hasItem(matchedSource), Matchers.not(Matchers.hasItem(unmatchedSource))));
}
use of com.facebook.buck.rules.TargetGraph in project buck by facebook.
the class PythonTestDescriptionTest method packageStyleParam.
@Test
public void packageStyleParam() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
PythonTestBuilder builder = PythonTestBuilder.create(BuildTargetFactory.newInstance("//:bin")).setPackageStyle(PythonBuckConfig.PackageStyle.INPLACE);
TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PythonTest pythonTest = builder.build(resolver, filesystem, targetGraph);
assertThat(pythonTest.getBinary(), Matchers.instanceOf(PythonInPlaceBinary.class));
builder = PythonTestBuilder.create(BuildTargetFactory.newInstance("//:bin")).setPackageStyle(PythonBuckConfig.PackageStyle.STANDALONE);
targetGraph = TargetGraphFactory.newInstance(builder.build());
resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
pythonTest = builder.build(resolver, filesystem, targetGraph);
assertThat(pythonTest.getBinary(), Matchers.instanceOf(PythonPackagedBinary.class));
}
use of com.facebook.buck.rules.TargetGraph 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.rules.TargetGraph in project buck by facebook.
the class PythonBinaryDescriptionTest method explicitDepOnlinkWholeLibPullsInSharedLibrary.
@Test
public void explicitDepOnlinkWholeLibPullsInSharedLibrary() throws Exception {
for (final NativeLinkStrategy strategy : NativeLinkStrategy.values()) {
ProjectFilesystem filesystem = new AllExistingProjectFilesystem();
CxxLibraryBuilder cxxLibraryBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep1")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test.c")))).setForceStatic(true);
PrebuiltCxxLibraryBuilder prebuiltCxxLibraryBuilder = new PrebuiltCxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep2")).setForceStatic(true);
PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {
@Override
public NativeLinkStrategy getNativeLinkStrategy() {
return strategy;
}
};
PythonBinaryBuilder binaryBuilder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
binaryBuilder.setMainModule("main");
binaryBuilder.setDeps(ImmutableSortedSet.of(cxxLibraryBuilder.getTarget(), prebuiltCxxLibraryBuilder.getTarget()));
TargetGraph targetGraph = TargetGraphFactory.newInstance(cxxLibraryBuilder.build(), prebuiltCxxLibraryBuilder.build(), binaryBuilder.build());
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
cxxLibraryBuilder.build(resolver, filesystem, targetGraph);
prebuiltCxxLibraryBuilder.build(resolver, filesystem, targetGraph);
PythonBinary binary = binaryBuilder.build(resolver, filesystem, targetGraph);
assertThat("Using " + strategy, binary.getComponents().getNativeLibraries().keySet(), Matchers.hasItems(Paths.get("libdep1.so"), Paths.get("libdep2.so")));
}
}
Aggregations