use of com.facebook.buck.rules.coercer.SourceList in project buck by facebook.
the class LuaUtil method toModuleMap.
public static ImmutableMap<String, SourcePath> toModuleMap(BuildTarget target, SourcePathResolver resolver, String parameter, String baseModule, Iterable<SourceList> inputs) {
ImmutableMap.Builder<String, SourcePath> moduleNamesAndSourcePaths = ImmutableMap.builder();
for (SourceList input : inputs) {
ImmutableMap<String, SourcePath> namesAndSourcePaths;
if (input.getUnnamedSources().isPresent()) {
namesAndSourcePaths = resolver.getSourcePathNames(target, parameter, input.getUnnamedSources().get());
} else {
namesAndSourcePaths = input.getNamedSources().get();
}
for (ImmutableMap.Entry<String, SourcePath> entry : namesAndSourcePaths.entrySet()) {
String name = entry.getKey();
if (!baseModule.isEmpty()) {
name = baseModule + '/' + name;
}
moduleNamesAndSourcePaths.put(name, entry.getValue());
}
}
return moduleNamesAndSourcePaths.build();
}
use of com.facebook.buck.rules.coercer.SourceList in project buck by facebook.
the class PythonLibraryDescriptionTest method versionedResources.
@Test
public void versionedResources() 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).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());
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).getResources().values(), Matchers.contains(matchedSource));
}
use of com.facebook.buck.rules.coercer.SourceList in project buck by facebook.
the class PythonLibraryDescriptionTest method platformSrcs.
@Test
public void platformSrcs() 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");
PythonLibraryBuilder builder = new PythonLibraryBuilder(target).setPlatformSrcs(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());
PythonLibrary library = builder.build(new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer()), filesystem, targetGraph);
assertThat(library.getPythonPackageComponents(PythonTestUtils.PYTHON_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORM).getModules().values(), Matchers.contains(matchedSource));
}
use of com.facebook.buck.rules.coercer.SourceList in project buck by facebook.
the class PythonLibraryDescriptionTest method platformResources.
@Test
public void platformResources() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//foo:lib");
SourcePath matchedSource = new FakeSourcePath("foo/a.dat");
SourcePath unmatchedSource = new FakeSourcePath("foo/b.dat");
PythonLibraryBuilder builder = new PythonLibraryBuilder(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());
PythonLibrary library = builder.build(new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer()), filesystem, targetGraph);
assertThat(library.getPythonPackageComponents(PythonTestUtils.PYTHON_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORM).getResources().values(), Matchers.contains(matchedSource));
}
use of com.facebook.buck.rules.coercer.SourceList in project buck by facebook.
the class PythonTestDescriptionTest method platformSrcs.
@Test
public void platformSrcs() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildTarget target = BuildTargetFactory.newInstance("//foo:test");
SourcePath matchedSource = new FakeSourcePath("foo/a.py");
SourcePath unmatchedSource = new FakeSourcePath("foo/b.py");
PythonTestBuilder builder = PythonTestBuilder.create(target).setPlatformSrcs(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().getModules().values(), Matchers.allOf(Matchers.hasItem(matchedSource), Matchers.not(Matchers.hasItem(unmatchedSource))));
}
Aggregations