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