use of com.facebook.buck.rules.SourceWithFlags in project buck by facebook.
the class NewNativeTargetProjectMutator method traverseGroupsTreeAndHandleSources.
private void traverseGroupsTreeAndHandleSources(final PBXGroup sourcesGroup, final PBXSourcesBuildPhase sourcesBuildPhase, Iterable<GroupedSource> groupedSources) {
GroupedSource.Visitor visitor = new GroupedSource.Visitor() {
@Override
public void visitSourceWithFlags(SourceWithFlags sourceWithFlags) {
addSourcePathToSourcesBuildPhase(sourceWithFlags, sourcesGroup, sourcesBuildPhase);
}
@Override
public void visitPublicHeader(SourcePath publicHeader) {
addSourcePathToHeadersBuildPhase(publicHeader, sourcesGroup, HeaderVisibility.PUBLIC);
}
@Override
public void visitPrivateHeader(SourcePath privateHeader) {
addSourcePathToHeadersBuildPhase(privateHeader, sourcesGroup, HeaderVisibility.PRIVATE);
}
@Override
public void visitSourceGroup(String sourceGroupName, Path sourceGroupPathRelativeToTarget, List<GroupedSource> sourceGroup) {
PBXGroup newSourceGroup = sourcesGroup.getOrCreateChildGroupByName(sourceGroupName);
newSourceGroup.setSourceTree(PBXReference.SourceTree.SOURCE_ROOT);
newSourceGroup.setPath(sourceGroupPathRelativeToTarget.toString());
// Sources groups stay in the order in which they're in the GroupedSource.
newSourceGroup.setSortPolicy(PBXGroup.SortPolicy.UNSORTED);
traverseGroupsTreeAndHandleSources(newSourceGroup, sourcesBuildPhase, sourceGroup);
}
};
for (GroupedSource groupedSource : groupedSources) {
groupedSource.visit(visitor);
}
}
use of com.facebook.buck.rules.SourceWithFlags in project buck by facebook.
the class RuleKeyBuilder method setReflectively.
/** Recursively serializes the value. Serialization of the key is handled outside. */
protected RuleKeyBuilder<RULE_KEY> setReflectively(@Nullable Object val) {
if (val instanceof RuleKeyAppendable) {
return setAppendableRuleKey((RuleKeyAppendable) val);
}
if (val instanceof BuildRule) {
return setBuildRule((BuildRule) val);
}
if (val instanceof Supplier) {
try (Scope containerScope = scopedHasher.wrapperScope(Wrapper.SUPPLIER)) {
Object newVal = ((Supplier<?>) val).get();
return setReflectively(newVal);
}
}
if (val instanceof Optional) {
Object o = ((Optional<?>) val).orElse(null);
try (Scope wraperScope = scopedHasher.wrapperScope(Wrapper.OPTIONAL)) {
return setReflectively(o);
}
}
if (val instanceof Either) {
Either<?, ?> either = (Either<?, ?>) val;
if (either.isLeft()) {
try (Scope wraperScope = scopedHasher.wrapperScope(Wrapper.EITHER_LEFT)) {
return setReflectively(either.getLeft());
}
} else {
try (Scope wraperScope = scopedHasher.wrapperScope(Wrapper.EITHER_RIGHT)) {
return setReflectively(either.getRight());
}
}
}
// Note {@link java.nio.file.Path} implements "Iterable", so we explicitly exclude it here.
if (val instanceof Iterable && !(val instanceof Path)) {
try (ContainerScope containerScope = scopedHasher.containerScope(Container.LIST)) {
for (Object element : (Iterable<?>) val) {
try (Scope elementScope = containerScope.elementScope()) {
setReflectively(element);
}
}
return this;
}
}
if (val instanceof Iterator) {
Iterator<?> iterator = (Iterator<?>) val;
try (ContainerScope containerScope = scopedHasher.containerScope(Container.LIST)) {
while (iterator.hasNext()) {
try (Scope elementScope = containerScope.elementScope()) {
setReflectively(iterator.next());
}
}
}
return this;
}
if (val instanceof Map) {
if (!(val instanceof SortedMap || val instanceof ImmutableMap)) {
logger.warn("Adding an unsorted map to the rule key. " + "Expect unstable ordering and caches misses: %s", val);
}
try (ContainerScope containerScope = scopedHasher.containerScope(Container.MAP)) {
for (Map.Entry<?, ?> entry : ((Map<?, ?>) val).entrySet()) {
try (Scope elementScope = containerScope.elementScope()) {
setReflectively(entry.getKey());
}
try (Scope elementScope = containerScope.elementScope()) {
setReflectively(entry.getValue());
}
}
}
return this;
}
if (val instanceof Path) {
throw new HumanReadableException("It's not possible to reliably disambiguate Paths. They are disallowed from rule keys");
}
if (val instanceof SourcePath) {
try {
return setSourcePath((SourcePath) val);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
if (val instanceof NonHashableSourcePathContainer) {
SourcePath sourcePath = ((NonHashableSourcePathContainer) val).getSourcePath();
return setNonHashingSourcePath(sourcePath);
}
if (val instanceof SourceWithFlags) {
SourceWithFlags source = (SourceWithFlags) val;
try {
setSourcePath(source.getSourcePath());
} catch (IOException e) {
throw new RuntimeException(e);
}
setReflectively(source.getFlags());
return this;
}
return setSingleValue(val);
}
use of com.facebook.buck.rules.SourceWithFlags in project buck by facebook.
the class TypeCoercerTest method coercingHeterogeneousAppleSourceGroups.
@Test
public void coercingHeterogeneousAppleSourceGroups() throws NoSuchFieldException, CoerceFailedException {
Type type = TestFields.class.getField("listOfSourcesWithFlags").getGenericType();
TypeCoercer<?> coercer = typeCoercerFactory.typeCoercerForType(type);
ImmutableList<?> input = ImmutableList.of("Group1/foo.m", ImmutableList.of("Group1/bar.m", ImmutableList.of("-Wall", "-Werror")), "Group2/baz.m", ImmutableList.of("Group2/blech.m", ImmutableList.of("-fobjc-arc")));
Object result = coercer.coerce(cellRoots, filesystem, Paths.get(""), input);
ImmutableList<SourceWithFlags> expectedResult = ImmutableList.of(SourceWithFlags.of(new FakeSourcePath("Group1/foo.m")), SourceWithFlags.of(new FakeSourcePath("Group1/bar.m"), ImmutableList.of("-Wall", "-Werror")), SourceWithFlags.of(new FakeSourcePath("Group2/baz.m")), SourceWithFlags.of(new FakeSourcePath("Group2/blech.m"), ImmutableList.of("-fobjc-arc")));
assertEquals(expectedResult, result);
}
use of com.facebook.buck.rules.SourceWithFlags in project buck by facebook.
the class AppleDescriptions method populateCxxConstructorArg.
public static void populateCxxConstructorArg(SourcePathResolver resolver, CxxConstructorArg output, AppleNativeTargetDescriptionArg arg, BuildTarget buildTarget) {
Path headerPathPrefix = AppleDescriptions.getHeaderPathPrefix(arg, buildTarget);
// The resulting cxx constructor arg will have no exported headers and both headers and exported
// headers specified in the apple arg will be available with both public and private include
// styles.
ImmutableSortedMap<String, SourcePath> headerMap = ImmutableSortedMap.<String, SourcePath>naturalOrder().putAll(convertAppleHeadersToPublicCxxHeaders(resolver::getRelativePath, headerPathPrefix, arg)).putAll(convertAppleHeadersToPrivateCxxHeaders(resolver::getRelativePath, headerPathPrefix, arg)).build();
ImmutableSortedSet.Builder<SourceWithFlags> nonSwiftSrcs = ImmutableSortedSet.naturalOrder();
for (SourceWithFlags src : arg.srcs) {
if (!MorePaths.getFileExtension(resolver.getAbsolutePath(src.getSourcePath())).equalsIgnoreCase(SWIFT_EXTENSION)) {
nonSwiftSrcs.add(src);
}
}
output.srcs = nonSwiftSrcs.build();
output.platformSrcs = arg.platformSrcs;
output.headers = SourceList.ofNamedSources(headerMap);
output.platformHeaders = arg.platformHeaders;
output.prefixHeader = arg.prefixHeader;
output.compilerFlags = arg.compilerFlags;
output.platformCompilerFlags = arg.platformCompilerFlags;
output.langCompilerFlags = arg.langCompilerFlags;
output.preprocessorFlags = arg.preprocessorFlags;
output.platformPreprocessorFlags = arg.platformPreprocessorFlags;
output.langPreprocessorFlags = arg.langPreprocessorFlags;
output.linkerFlags = arg.linkerFlags;
output.platformLinkerFlags = arg.platformLinkerFlags;
output.frameworks = arg.frameworks;
output.libraries = arg.libraries;
output.deps = arg.deps;
// This is intentionally an empty string; we put all prefixes into
// the header map itself.
output.headerNamespace = Optional.of("");
output.cxxRuntimeType = arg.cxxRuntimeType;
output.tests = arg.tests;
output.precompiledHeader = arg.precompiledHeader;
}
use of com.facebook.buck.rules.SourceWithFlags in project buck by facebook.
the class RuleUtilsTest method extractGroupedSources.
@Test
public void extractGroupedSources() {
ImmutableList<SourceWithFlags> input = ImmutableList.of(SourceWithFlags.of(new FakeSourcePath("Group1/foo.m")), SourceWithFlags.of(new FakeSourcePath("Group1/bar.m"), ImmutableList.of("-Wall")), SourceWithFlags.of(new FakeSourcePath("Group2/baz.m")), SourceWithFlags.of(new FakeSourcePath("Group2/blech.m"), ImmutableList.of("-fobjc-arc")));
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ImmutableList<GroupedSource> sources = RuleUtils.createGroupsFromSourcePaths(resolver::getRelativePath, input, /* extraXcodeSources */
ImmutableSortedSet.of(), /* publicHeaders */
ImmutableSortedSet.of(), /* privateHeaders */
ImmutableSortedSet.of());
assertEquals(ImmutableList.of(GroupedSource.ofSourceGroup("Group1", Paths.get("Group1"), ImmutableList.of(GroupedSource.ofSourceWithFlags(SourceWithFlags.of(new FakeSourcePath("Group1/bar.m"), ImmutableList.of("-Wall"))), GroupedSource.ofSourceWithFlags(SourceWithFlags.of(new FakeSourcePath("Group1/foo.m"))))), GroupedSource.ofSourceGroup("Group2", Paths.get("Group2"), ImmutableList.of(GroupedSource.ofSourceWithFlags(SourceWithFlags.of(new FakeSourcePath("Group2/baz.m"))), GroupedSource.ofSourceWithFlags(SourceWithFlags.of(new FakeSourcePath("Group2/blech.m"), ImmutableList.of("-fobjc-arc")))))), sources);
}
Aggregations