Search in sources :

Example 6 with SourceList

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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) SourceList(com.facebook.buck.rules.coercer.SourceList) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with SourceList

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));
}
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 8 with SourceList

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));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) SourceList(com.facebook.buck.rules.coercer.SourceList) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 9 with SourceList

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));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) SourceList(com.facebook.buck.rules.coercer.SourceList) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 10 with SourceList

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))));
}
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) SourceList(com.facebook.buck.rules.coercer.SourceList) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

SourceList (com.facebook.buck.rules.coercer.SourceList)10 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)9 SourcePath (com.facebook.buck.rules.SourcePath)9 TargetGraph (com.facebook.buck.rules.TargetGraph)9 BuildTarget (com.facebook.buck.model.BuildTarget)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)7 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)7 Test (org.junit.Test)7 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)4 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 CxxGenruleBuilder (com.facebook.buck.cxx.CxxGenruleBuilder)2 BuildTargets (com.facebook.buck.model.BuildTargets)2 Flavor (com.facebook.buck.model.Flavor)2 FlavorDomain (com.facebook.buck.model.FlavorDomain)2 InternalFlavor (com.facebook.buck.model.InternalFlavor)2 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)2 BuildRule (com.facebook.buck.rules.BuildRule)2 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)2