Search in sources :

Example 11 with CxxPreprocessorInput

use of com.facebook.buck.cxx.CxxPreprocessorInput in project buck by facebook.

the class OcamlBuildRulesGenerator method generateCCompilation.

private ImmutableList<SourcePath> generateCCompilation(ImmutableList<SourcePath> cInput) {
    ImmutableList.Builder<SourcePath> objects = ImmutableList.builder();
    ImmutableList.Builder<String> cCompileFlags = ImmutableList.builder();
    cCompileFlags.addAll(ocamlContext.getCCompileFlags());
    cCompileFlags.addAll(ocamlContext.getCommonCFlags());
    CxxPreprocessorInput cxxPreprocessorInput = ocamlContext.getCxxPreprocessorInput();
    for (SourcePath cSrc : cInput) {
        String name = pathResolver.getAbsolutePath(cSrc).toFile().getName();
        BuildTarget target = createCCompileBuildTarget(params.getBuildTarget(), name);
        BuildRuleParams cCompileParams = params.withBuildTarget(target).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(cSrc)).addAll(cxxPreprocessorInput.getDeps(resolver, ruleFinder)).add(this.cleanRule).addAll(cCompiler.getDeps(ruleFinder)).addAll(params.getDeclaredDeps().get()).build()), params.getExtraDeps());
        Path outputPath = ocamlContext.getCOutput(pathResolver.getRelativePath(cSrc));
        OcamlCCompile compileRule = new OcamlCCompile(cCompileParams, new OcamlCCompileStep.Args(cCompiler.getEnvironment(pathResolver), cCompiler.getCommandPrefix(pathResolver), ocamlContext.getOcamlCompiler().get(), ocamlContext.getOcamlInteropIncludesDir(), outputPath, cSrc, cCompileFlags.build(), cxxPreprocessorInput.getIncludes()));
        resolver.addToIndex(compileRule);
        objects.add(compileRule.getSourcePathToOutput());
    }
    return objects.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) SourcePath(com.facebook.buck.rules.SourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) BuildRule(com.facebook.buck.rules.BuildRule)

Example 12 with CxxPreprocessorInput

use of com.facebook.buck.cxx.CxxPreprocessorInput 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

CxxPreprocessorInput (com.facebook.buck.cxx.CxxPreprocessorInput)12 ImmutableList (com.google.common.collect.ImmutableList)11 SourcePath (com.facebook.buck.rules.SourcePath)9 Path (java.nio.file.Path)7 BuildTarget (com.facebook.buck.model.BuildTarget)5 BuildRule (com.facebook.buck.rules.BuildRule)5 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)4 NativeLinkableInput (com.facebook.buck.cxx.NativeLinkableInput)4 CxxPreprocessables (com.facebook.buck.cxx.CxxPreprocessables)3 CxxPreprocessorDep (com.facebook.buck.cxx.CxxPreprocessorDep)3 HeaderSymlinkTree (com.facebook.buck.cxx.HeaderSymlinkTree)3 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)3 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)3 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)3 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)3