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));
}
};
}
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();
}
Aggregations