Search in sources :

Example 1 with CxxHeaders

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();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) ImmutableList(com.google.common.collect.ImmutableList) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) CxxHeaders(com.facebook.buck.cxx.CxxHeaders) HeaderVisibility(com.facebook.buck.cxx.HeaderVisibility) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

CxxHeaders (com.facebook.buck.cxx.CxxHeaders)1 CxxPreprocessorInput (com.facebook.buck.cxx.CxxPreprocessorInput)1 HeaderVisibility (com.facebook.buck.cxx.HeaderVisibility)1 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 Path (java.nio.file.Path)1 LinkedHashSet (java.util.LinkedHashSet)1