Search in sources :

Example 1 with HeaderVisibility

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

the class HaskellPrebuiltLibraryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException {
    return new PrebuiltHaskellLibrary(params) {

        private final LoadingCache<CxxPreprocessables.CxxPreprocessorInputCacheKey, ImmutableMap<BuildTarget, CxxPreprocessorInput>> transitiveCxxPreprocessorInputCache = CxxPreprocessables.getTransitiveCxxPreprocessorInputCache(this);

        @Override
        public HaskellCompileInput getCompileInput(CxxPlatform cxxPlatform, Linker.LinkableDepType depType) throws NoSuchBuildTargetException {
            return HaskellCompileInput.builder().addAllFlags(args.exportedCompilerFlags).addPackages(HaskellPackage.builder().setInfo(HaskellPackageInfo.of(getBuildTarget().getShortName(), args.version, args.id.orElse(String.format("%s-%s", getBuildTarget().getShortName(), args.version)))).setPackageDb(args.db).addAllInterfaces(args.importDirs).addAllLibraries(depType == Linker.LinkableDepType.SHARED ? args.sharedLibs.values() : args.staticLibs).build()).build();
        }

        @Override
        public Iterable<? extends NativeLinkable> getNativeLinkableDeps() {
            return ImmutableList.of();
        }

        @Override
        public Iterable<? extends NativeLinkable> getNativeLinkableExportedDeps() {
            return FluentIterable.from(getDeclaredDeps()).filter(NativeLinkable.class);
        }

        @Override
        public NativeLinkableInput getNativeLinkableInput(CxxPlatform cxxPlatform, Linker.LinkableDepType type) {
            NativeLinkableInput.Builder builder = NativeLinkableInput.builder();
            builder.addAllArgs(StringArg.from(args.exportedLinkerFlags));
            if (type == Linker.LinkableDepType.SHARED) {
                builder.addAllArgs(SourcePathArg.from(args.sharedLibs.values()));
            } else {
                builder.addAllArgs(SourcePathArg.from(args.staticLibs));
            }
            return builder.build();
        }

        @Override
        public Linkage getPreferredLinkage(CxxPlatform cxxPlatform) {
            return Linkage.ANY;
        }

        @Override
        public ImmutableMap<String, SourcePath> getSharedLibraries(CxxPlatform cxxPlatform) {
            return args.sharedLibs;
        }

        @Override
        public Iterable<? extends CxxPreprocessorDep> getCxxPreprocessorDeps(CxxPlatform cxxPlatform) {
            return FluentIterable.from(getDeps()).filter(CxxPreprocessorDep.class);
        }

        @Override
        public Optional<HeaderSymlinkTree> getExportedHeaderSymlinkTree(CxxPlatform cxxPlatform) {
            return Optional.empty();
        }

        @Override
        public CxxPreprocessorInput getCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
            CxxPreprocessorInput.Builder builder = CxxPreprocessorInput.builder();
            for (SourcePath headerDir : args.cxxHeaderDirs) {
                builder.addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, headerDir));
            }
            return builder.build();
        }

        @Override
        public ImmutableMap<BuildTarget, CxxPreprocessorInput> getTransitiveCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
            return transitiveCxxPreprocessorInputCache.getUnchecked(ImmutableCxxPreprocessorInputCacheKey.of(cxxPlatform, headerVisibility));
        }
    };
}
Also used : HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) SourcePath(com.facebook.buck.rules.SourcePath) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) CxxPreprocessables(com.facebook.buck.cxx.CxxPreprocessables) BuildTarget(com.facebook.buck.model.BuildTarget) LoadingCache(com.google.common.cache.LoadingCache) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput) HeaderVisibility(com.facebook.buck.cxx.HeaderVisibility)

Example 2 with HeaderVisibility

use of com.facebook.buck.cxx.HeaderVisibility 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)2 HeaderVisibility (com.facebook.buck.cxx.HeaderVisibility)2 SourcePath (com.facebook.buck.rules.SourcePath)2 CxxHeaders (com.facebook.buck.cxx.CxxHeaders)1 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)1 CxxPreprocessables (com.facebook.buck.cxx.CxxPreprocessables)1 HeaderSymlinkTree (com.facebook.buck.cxx.HeaderSymlinkTree)1 NativeLinkableInput (com.facebook.buck.cxx.NativeLinkableInput)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)1 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableList (com.google.common.collect.ImmutableList)1 Path (java.nio.file.Path)1 LinkedHashSet (java.util.LinkedHashSet)1