Search in sources :

Example 6 with SourceWithFlags

use of com.facebook.buck.rules.SourceWithFlags in project buck by facebook.

the class TypeCoercerTest method coercingAppleSourcePathsWithFlags.

@Test
public void coercingAppleSourcePathsWithFlags() throws NoSuchFieldException, CoerceFailedException {
    Type type = TestFields.class.getField("listOfSourcesWithFlags").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    ImmutableList<?> input = ImmutableList.of(ImmutableList.of("foo.m", ImmutableList.of("-Wall", "-Werror")), ImmutableList.of("bar.m", ImmutableList.of("-fobjc-arc")));
    Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    ImmutableList<SourceWithFlags> expectedResult = ImmutableList.of(SourceWithFlags.of(new FakeSourcePath("foo.m"), ImmutableList.of("-Wall", "-Werror")), SourceWithFlags.of(new FakeSourcePath("bar.m"), ImmutableList.of("-fobjc-arc")));
    assertEquals(expectedResult, result);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Type(java.lang.reflect.Type) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Test(org.junit.Test)

Example 7 with SourceWithFlags

use of com.facebook.buck.rules.SourceWithFlags in project buck by facebook.

the class TypeCoercerTest method coercingAppleSourcePaths.

@Test
public void coercingAppleSourcePaths() throws NoSuchFieldException, CoerceFailedException {
    Type type = TestFields.class.getField("listOfSourcesWithFlags").getGenericType();
    TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
    ImmutableList<String> input = ImmutableList.of("foo.m", "bar.m");
    Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
    ImmutableList<SourceWithFlags> expectedResult = ImmutableList.of(SourceWithFlags.of(new FakeSourcePath("foo.m")), SourceWithFlags.of(new FakeSourcePath("bar.m")));
    assertEquals(expectedResult, result);
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Type(java.lang.reflect.Type) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Test(org.junit.Test)

Example 8 with SourceWithFlags

use of com.facebook.buck.rules.SourceWithFlags in project buck by facebook.

the class RuleUtils method createGroupsFromSourcePaths.

public static ImmutableList<GroupedSource> createGroupsFromSourcePaths(Function<SourcePath, Path> resolver, Iterable<SourceWithFlags> sources, Iterable<SourcePath> extraXcodeSources, Iterable<SourcePath> publicHeaders, Iterable<SourcePath> privateHeaders) {
    Path rootPath = Paths.get("root");
    ImmutableMultimap.Builder<Path, GroupedSource> entriesBuilder = ImmutableMultimap.builder();
    for (SourceWithFlags sourceWithFlags : sources) {
        Path path = rootPath.resolve(resolver.apply(sourceWithFlags.getSourcePath()));
        GroupedSource groupedSource = GroupedSource.ofSourceWithFlags(sourceWithFlags);
        entriesBuilder.put(Preconditions.checkNotNull(path.getParent()), groupedSource);
    }
    for (SourcePath sourcePath : extraXcodeSources) {
        Path path = rootPath.resolve(resolver.apply(sourcePath));
        GroupedSource groupedSource = GroupedSource.ofSourceWithFlags(SourceWithFlags.of(sourcePath));
        entriesBuilder.put(Preconditions.checkNotNull(path.getParent()), groupedSource);
    }
    for (SourcePath publicHeader : publicHeaders) {
        Path path = rootPath.resolve(resolver.apply(publicHeader));
        GroupedSource groupedSource = GroupedSource.ofPublicHeader(publicHeader);
        entriesBuilder.put(Preconditions.checkNotNull(path.getParent()), groupedSource);
    }
    for (SourcePath privateHeader : privateHeaders) {
        Path path = rootPath.resolve(resolver.apply(privateHeader));
        GroupedSource groupedSource = GroupedSource.ofPrivateHeader(privateHeader);
        entriesBuilder.put(Preconditions.checkNotNull(path.getParent()), groupedSource);
    }
    ImmutableMultimap<Path, GroupedSource> entries = entriesBuilder.build();
    ImmutableMultimap.Builder<Path, String> subgroupsBuilder = ImmutableMultimap.builder();
    for (Path groupPath : entries.keys()) {
        Path parent = groupPath.getParent();
        while (parent != null) {
            subgroupsBuilder.put(parent, groupPath.getFileName().toString());
            groupPath = parent;
            parent = groupPath.getParent();
        }
    }
    ImmutableMultimap<Path, String> subgroups = subgroupsBuilder.build();
    GroupedSourceNameComparator groupedSourceNameComparator = new GroupedSourceNameComparator(resolver);
    ImmutableList<GroupedSource> groupedSources = createGroupsFromEntryMaps(subgroups, entries, groupedSourceNameComparator, rootPath, rootPath);
    // Remove the longest common prefix from all paths.
    while (groupedSources.size() == 1 && groupedSources.get(0).getType() == GroupedSource.Type.SOURCE_GROUP) {
        groupedSources = ImmutableList.copyOf(groupedSources.get(0).getSourceGroup().get());
    }
    return groupedSources;
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags)

Aggregations

SourceWithFlags (com.facebook.buck.rules.SourceWithFlags)8 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)4 SourcePath (com.facebook.buck.rules.SourcePath)4 Path (java.nio.file.Path)4 Test (org.junit.Test)4 Type (java.lang.reflect.Type)3 BuildTargetSourcePath (com.facebook.buck.rules.BuildTargetSourcePath)2 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 NSString (com.dd.plist.NSString)1 GroupedSource (com.facebook.buck.apple.GroupedSource)1 PBXGroup (com.facebook.buck.apple.xcode.xcodeproj.PBXGroup)1 SourceTreePath (com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath)1 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)1 Either (com.facebook.buck.model.Either)1 ArchiveMemberSourcePath (com.facebook.buck.rules.ArchiveMemberSourcePath)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 NonHashableSourcePathContainer (com.facebook.buck.rules.NonHashableSourcePathContainer)1 RuleKeyAppendable (com.facebook.buck.rules.RuleKeyAppendable)1