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