use of com.facebook.buck.cxx.CxxHeaders in project buck by facebook.
the class SwiftCompile method getSwiftIncludeArgs.
/**
* @return the arguments to add to the preprocessor command line to include the given header packs
* in preprocessor search path.
*
* We can't use CxxHeaders.getArgs() because
* 1. we don't need the system include roots.
* 2. swift doesn't like spaces after the "-I" flag.
*/
@VisibleForTesting
ImmutableList<String> getSwiftIncludeArgs(SourcePathResolver resolver) {
ImmutableList.Builder<String> args = ImmutableList.builder();
// Collect the header maps and roots into buckets organized by include type, so that we can:
// 1) Apply the header maps first (so that they work properly).
// 2) De-duplicate redundant include paths.
LinkedHashSet<String> headerMaps = new LinkedHashSet<String>();
LinkedHashSet<String> roots = new LinkedHashSet<String>();
for (CxxPreprocessorInput cxxPreprocessorInput : cxxPreprocessorInputs) {
Iterable<CxxHeaders> cxxHeaderses = cxxPreprocessorInput.getIncludes();
for (CxxHeaders cxxHeaders : cxxHeaderses) {
// Swift doesn't need to reference anything from system headers
if (cxxHeaders.getIncludeType() == CxxPreprocessables.IncludeType.SYSTEM) {
continue;
}
Optional<SourcePath> headerMap = cxxHeaders.getHeaderMap();
if (headerMap.isPresent()) {
headerMaps.add(resolver.getAbsolutePath(headerMap.get()).toString());
}
roots.add(resolver.getAbsolutePath(cxxHeaders.getIncludeRoot()).toString());
}
}
if (bridgingHeader.isPresent()) {
for (HeaderVisibility headerVisibility : HeaderVisibility.values()) {
Path headerPath = CxxDescriptionEnhancer.getHeaderSymlinkTreePath(getProjectFilesystem(), BuildTarget.builder(getBuildTarget().getUnflavoredBuildTarget()).build(), headerVisibility, cxxPlatform.getFlavor());
headerMaps.add(headerPath.toString());
}
}
// Apply the header maps first, so that headers that matching there avoid falling back to
// stat'ing files in the normal include roots.
args.addAll(Iterables.transform(headerMaps, INCLUDE_FLAG::concat));
// Apply the regular includes last.
args.addAll(Iterables.transform(roots, INCLUDE_FLAG::concat));
return args.build();
}
Aggregations