Search in sources :

Example 1 with DotdFile

use of com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile in project bazel by bazelbuild.

the class CppCompileActionBuilder method setOutputs.

public CppCompileActionBuilder setOutputs(RuleContext ruleContext, ArtifactCategory outputCategory, String outputName, boolean generateDotd) {
    this.outputFile = CppHelper.getCompileOutputArtifact(ruleContext, CppHelper.getArtifactNameForCategory(ruleContext, ccToolchain, outputCategory, outputName), configuration);
    if (generateDotd) {
        String dotdFileName = CppHelper.getDotdFileName(ruleContext, ccToolchain, outputCategory, outputName);
        if (cppConfiguration.getInmemoryDotdFiles()) {
            // Just set the path, no artifact is constructed
            BuildConfiguration configuration = ruleContext.getConfiguration();
            dotdFile = new DotdFile(configuration.getBinDirectory(ruleContext.getRule().getRepository()).getExecPath().getRelative(CppHelper.getObjDirectory(ruleContext.getLabel())).getRelative(dotdFileName));
        } else {
            dotdFile = new DotdFile(CppHelper.getCompileOutputArtifact(ruleContext, dotdFileName, configuration));
        }
    } else {
        dotdFile = null;
    }
    return this;
}
Also used : BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) DotdFile(com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile)

Example 2 with DotdFile

use of com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile 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);
}
Also used : StringSequenceBuilder(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.StringSequenceBuilder) VariablesExtension(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariablesExtension) Builder(com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs.Builder) StringSequenceBuilder(com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.StringSequenceBuilder) Artifact(com.google.devtools.build.lib.actions.Artifact) DotdFile(com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile)

Example 3 with DotdFile

use of com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile in project bazel by bazelbuild.

the class LegacyCompilationSupport method registerCompileAction.

@Nullable
private ObjcHeaderThinningInfo registerCompileAction(Artifact sourceFile, Artifact objFile, ObjcProvider objcProvider, Iterable<PathFragment> priorityHeaders, Optional<CppModuleMap> moduleMap, CompilationArtifacts compilationArtifacts, Iterable<String> otherFlags) {
    boolean isCPlusPlusSource = ObjcRuleClasses.CPP_SOURCES.matches(sourceFile.getExecPath());
    boolean runCodeCoverage = buildConfiguration.isCodeCoverageEnabled() && ObjcRuleClasses.isInstrumentable(sourceFile);
    DotdFile dotdFile = intermediateArtifacts.dotdFile(sourceFile);
    CustomCommandLine commandLine = compileActionCommandLine(sourceFile, objFile, objcProvider, priorityHeaders, moduleMap, compilationArtifacts.getPchFile(), Optional.of(dotdFile.artifact()), otherFlags, runCodeCoverage, isCPlusPlusSource);
    Optional<Artifact> gcnoFile = Optional.absent();
    if (runCodeCoverage && !buildConfiguration.isLLVMCoverageMapFormatEnabled()) {
        gcnoFile = Optional.of(intermediateArtifacts.gcnoFile(sourceFile));
    }
    NestedSet<Artifact> moduleMapInputs = NestedSetBuilder.emptySet(Order.STABLE_ORDER);
    if (objcConfiguration.moduleMapsEnabled()) {
        moduleMapInputs = objcProvider.get(MODULE_MAP);
    }
    // TODO(bazel-team): Remove private headers from inputs once they're added to the provider.
    ObjcCompileAction.Builder compileBuilder = ObjcCompileAction.Builder.createObjcCompileActionBuilderWithAppleEnv(appleConfiguration, appleConfiguration.getSingleArchPlatform()).setDotdPruningPlan(objcConfiguration.getDotdPruningPlan()).setSourceFile(sourceFile).addTransitiveHeaders(objcProvider.get(HEADER)).addHeaders(compilationArtifacts.getPrivateHdrs()).addTransitiveMandatoryInputs(moduleMapInputs).addTransitiveMandatoryInputs(objcProvider.get(STATIC_FRAMEWORK_FILE)).addTransitiveMandatoryInputs(objcProvider.get(DYNAMIC_FRAMEWORK_FILE)).setDotdFile(dotdFile).addMandatoryInputs(compilationArtifacts.getPchFile().asSet());
    Artifact headersListFile = null;
    if (isHeaderThinningEnabled() && SOURCES_FOR_HEADER_THINNING.matches(sourceFile.getFilename())) {
        headersListFile = intermediateArtifacts.headersListFile(sourceFile);
        compileBuilder.setHeadersListFile(headersListFile);
    }
    ruleContext.registerAction(compileBuilder.setMnemonic("ObjcCompile").setExecutable(xcrunwrapper(ruleContext)).setCommandLine(commandLine).addOutput(objFile).addOutputs(gcnoFile.asSet()).addOutput(dotdFile.artifact()).build(ruleContext));
    return headersListFile == null ? null : new ObjcHeaderThinningInfo(sourceFile, headersListFile, ImmutableList.copyOf(commandLine.arguments()));
}
Also used : CustomCommandLine(com.google.devtools.build.lib.analysis.actions.CustomCommandLine) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) DotdFile(com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile) Nullable(javax.annotation.Nullable)

Aggregations

DotdFile (com.google.devtools.build.lib.rules.cpp.CppCompileAction.DotdFile)3 Artifact (com.google.devtools.build.lib.actions.Artifact)2 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)1 CustomCommandLine (com.google.devtools.build.lib.analysis.actions.CustomCommandLine)1 BuildConfiguration (com.google.devtools.build.lib.analysis.config.BuildConfiguration)1 Builder (com.google.devtools.build.lib.rules.cpp.CcCompilationOutputs.Builder)1 StringSequenceBuilder (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.StringSequenceBuilder)1 VariablesExtension (com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables.VariablesExtension)1 Nullable (javax.annotation.Nullable)1