use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.StringSequenceBuilder in project bazel by bazelbuild.
the class CcToolchainFeaturesTest method createNestedSequence.
private VariableValueBuilder createNestedSequence(int depth, int count, String prefix) {
if (depth == 0) {
StringSequenceBuilder builder = new StringSequenceBuilder();
for (int i = 0; i < count; ++i) {
String value = prefix + i;
builder.addValue(value);
}
return builder;
} else {
SequenceBuilder builder = new SequenceBuilder();
for (int i = 0; i < count; ++i) {
String value = prefix + i;
builder.addValue(createNestedSequence(depth - 1, count, value));
}
return builder;
}
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.StringSequenceBuilder in project bazel by bazelbuild.
the class CppModel method setupCompileBuildVariables.
private void setupCompileBuildVariables(CppCompileActionBuilder builder, boolean usePic, PathFragment ccRelativeName, PathFragment autoFdoImportPath, Artifact gcnoFile, Artifact dwoFile, CppModuleMap cppModuleMap, Map<String, String> sourceSpecificBuildVariables) {
CcToolchainFeatures.Variables.Builder buildVariables = new CcToolchainFeatures.Variables.Builder();
// TODO(bazel-team): Pull out string constants for all build variables.
CppCompilationContext builderContext = builder.getContext();
Artifact sourceFile = builder.getSourceFile();
Artifact outputFile = builder.getOutputFile();
String realOutputFilePath;
buildVariables.addStringVariable("source_file", sourceFile.getExecPathString());
buildVariables.addStringVariable("output_file", outputFile.getExecPathString());
if (builder.getTempOutputFile() != null) {
realOutputFilePath = builder.getTempOutputFile().getPathString();
} else {
realOutputFilePath = builder.getOutputFile().getExecPathString();
}
if (FileType.contains(outputFile, CppFileTypes.ASSEMBLER, CppFileTypes.PIC_ASSEMBLER)) {
buildVariables.addStringVariable("output_assembly_file", realOutputFilePath);
} else if (FileType.contains(outputFile, CppFileTypes.PREPROCESSED_C, CppFileTypes.PREPROCESSED_CPP, CppFileTypes.PIC_PREPROCESSED_C, CppFileTypes.PIC_PREPROCESSED_CPP)) {
buildVariables.addStringVariable("output_preprocess_file", realOutputFilePath);
} else {
buildVariables.addStringVariable("output_object_file", realOutputFilePath);
}
DotdFile dotdFile = CppFileTypes.mustProduceDotdFile(sourceFile) ? Preconditions.checkNotNull(builder.getDotdFile()) : null;
// Set dependency_file to enable <object>.d file generation.
if (dotdFile != null) {
buildVariables.addStringVariable("dependency_file", dotdFile.getSafeExecPath().getPathString());
}
if (featureConfiguration.isEnabled(CppRuleClasses.MODULE_MAPS) && cppModuleMap != null) {
// If the feature is enabled and cppModuleMap is null, we are about to fail during analysis
// in any case, but don't crash.
buildVariables.addStringVariable("module_name", cppModuleMap.getName());
buildVariables.addStringVariable("module_map_file", cppModuleMap.getArtifact().getExecPathString());
StringSequenceBuilder sequence = new StringSequenceBuilder();
for (Artifact artifact : builderContext.getDirectModuleMaps()) {
sequence.addValue(artifact.getExecPathString());
}
buildVariables.addCustomBuiltVariable("dependent_module_map_files", sequence);
}
if (featureConfiguration.isEnabled(CppRuleClasses.USE_HEADER_MODULES)) {
// Module inputs will be set later when the action is executed.
buildVariables.addStringSequenceVariable("module_files", ImmutableSet.<String>of());
}
if (featureConfiguration.isEnabled(CppRuleClasses.INCLUDE_PATHS)) {
buildVariables.addStringSequenceVariable("include_paths", getSafePathStrings(builderContext.getIncludeDirs()));
buildVariables.addStringSequenceVariable("quote_include_paths", getSafePathStrings(builderContext.getQuoteIncludeDirs()));
buildVariables.addStringSequenceVariable("system_include_paths", getSafePathStrings(builderContext.getSystemIncludeDirs()));
}
if (featureConfiguration.isEnabled(CppRuleClasses.PREPROCESSOR_DEFINES)) {
String fdoBuildStamp = CppHelper.getFdoBuildStamp(ruleContext, fdoSupport.getFdoSupport());
ImmutableList<String> defines;
if (fdoBuildStamp != null) {
// Stamp FDO builds with FDO subtype string
defines = ImmutableList.<String>builder().addAll(builderContext.getDefines()).add(CppConfiguration.FDO_STAMP_MACRO + "=\"" + CppHelper.getFdoBuildStamp(ruleContext, fdoSupport.getFdoSupport()) + "\"").build();
} else {
defines = builderContext.getDefines();
}
buildVariables.addStringSequenceVariable("preprocessor_defines", defines);
}
if (usePic) {
if (!featureConfiguration.isEnabled(CppRuleClasses.PIC)) {
ruleContext.ruleError("PIC compilation is requested but the toolchain does not support it");
}
buildVariables.addStringVariable("pic", "");
}
if (ccRelativeName != null) {
fdoSupport.getFdoSupport().configureCompilation(builder, buildVariables, ruleContext, ccRelativeName, autoFdoImportPath, usePic, featureConfiguration, fdoSupport);
}
if (gcnoFile != null) {
buildVariables.addStringVariable("gcov_gcno_file", gcnoFile.getExecPathString());
}
if (dwoFile != null) {
buildVariables.addStringVariable("per_object_debug_info_file", dwoFile.getExecPathString());
}
buildVariables.addAllStringVariables(ccToolchain.getBuildVariables());
buildVariables.addAllStringVariables(sourceSpecificBuildVariables);
for (VariablesExtension extension : variablesExtensions) {
extension.addVariables(buildVariables);
}
CcToolchainFeatures.Variables variables = buildVariables.build();
builder.setVariables(variables);
}
use of com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.StringSequenceBuilder in project bazel by bazelbuild.
the class ObjcVariablesExtension method addFrameworkVariables.
private void addFrameworkVariables(CcToolchainFeatures.Variables.Builder builder) {
StringSequenceBuilder frameworkSequence = new StringSequenceBuilder();
for (String framework : CompilationSupport.commonFrameworkNames(objcProvider, appleConfiguration)) {
frameworkSequence.addValue(framework);
}
builder.addCustomBuiltVariable(FRAMEWORKS_VARIABLE_NAME, frameworkSequence);
}
Aggregations