diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index e169c4fbb22da4..04dab1586bbeb2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -110,17 +110,17 @@ public void collectMetadataArtifacts(Iterable objectFiles, public static final ImmutableSet ALL_COMPILE_ACTIONS = ImmutableSet.of( - CppCompileAction.C_COMPILE, - CppCompileAction.CPP_COMPILE, - CppCompileAction.CPP_HEADER_PARSING, - CppCompileAction.CPP_HEADER_PREPROCESSING, - CppCompileAction.CPP_MODULE_COMPILE, - CppCompileAction.CPP_MODULE_CODEGEN, - CppCompileAction.ASSEMBLE, - CppCompileAction.PREPROCESS_ASSEMBLE, - CppCompileAction.CLIF_MATCH, - CppCompileAction.LINKSTAMP_COMPILE, - CppCompileAction.CC_FLAGS_MAKE_VARIABLE_ACTION_NAME); + CppActionNames.C_COMPILE, + CppActionNames.CPP_COMPILE, + CppActionNames.CPP_HEADER_PARSING, + CppActionNames.CPP_HEADER_PREPROCESSING, + CppActionNames.CPP_MODULE_COMPILE, + CppActionNames.CPP_MODULE_CODEGEN, + CppActionNames.ASSEMBLE, + CppActionNames.PREPROCESS_ASSEMBLE, + CppActionNames.CLIF_MATCH, + CppActionNames.LINKSTAMP_COMPILE, + CppActionNames.CC_FLAGS_MAKE_VARIABLE); public static final ImmutableSet ALL_LINK_ACTIONS = ImmutableSet.of( @@ -132,7 +132,7 @@ public void collectMetadataArtifacts(Iterable objectFiles, ImmutableSet.of(Link.LinkTargetType.STATIC_LIBRARY.getActionName()); public static final ImmutableSet ALL_OTHER_ACTIONS = - ImmutableSet.of(CppCompileAction.STRIP_ACTION_NAME); + ImmutableSet.of(CppActionNames.STRIP); /** Action configs we request to enable. */ public static final ImmutableSet DEFAULT_ACTION_CONFIGS = @@ -971,8 +971,7 @@ public static String computeCcFlags(RuleContext ruleContext, TransitiveInfoColle (CcToolchainProvider) toolchain.get(ToolchainInfo.PROVIDER); FeatureConfiguration featureConfiguration = CcCommon.configureFeaturesOrReportRuleError(ruleContext, toolchainProvider); - if (!featureConfiguration.actionIsConfigured( - CppCompileAction.CC_FLAGS_MAKE_VARIABLE_ACTION_NAME)) { + if (!featureConfiguration.actionIsConfigured(CppActionNames.CC_FLAGS_MAKE_VARIABLE)) { return null; } @@ -981,7 +980,7 @@ public static String computeCcFlags(RuleContext ruleContext, TransitiveInfoColle Joiner.on(" ") .join( featureConfiguration.getCommandLine( - CppCompileAction.CC_FLAGS_MAKE_VARIABLE_ACTION_NAME, buildVariables)); + CppActionNames.CC_FLAGS_MAKE_VARIABLE, buildVariables)); String oldCcFlags = ""; TemplateVariableInfo templateVariableInfo = toolchain.get(TemplateVariableInfo.PROVIDER); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionNames.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionNames.java new file mode 100644 index 00000000000000..1f2c749a5af08c --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppActionNames.java @@ -0,0 +1,75 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.rules.cpp; + +/** Class holding constants for all C++ action names */ +public class CppActionNames { + + /** A string constant used to compute CC_FLAGS make variable value */ + public static final String CC_FLAGS_MAKE_VARIABLE = "cc-flags-make-variable"; + /** A string constant for the strip action name. */ + public static final String STRIP = "strip"; + /** A string constant for the linkstamp-compile action. */ + public static final String LINKSTAMP_COMPILE = "linkstamp-compile"; + /** A string constant for the c compilation action. */ + public static final String C_COMPILE = "c-compile"; + /** A string constant for the c++ compilation action. */ + public static final String CPP_COMPILE = "c++-compile"; + /** A string constant for the c++ module compile action. */ + public static final String CPP_MODULE_CODEGEN = "c++-module-codegen"; + /** A string constant for the objc compilation action. */ + public static final String OBJC_COMPILE = "objc-compile"; + /** A string constant for the objc++ compile action. */ + public static final String OBJCPP_COMPILE = "objc++-compile"; + /** A string constant for the c++ header parsing. */ + public static final String CPP_HEADER_PARSING = "c++-header-parsing"; + /** A string constant for the c++ header preprocessing. */ + public static final String CPP_HEADER_PREPROCESSING = "c++-header-preprocessing"; + /** + * A string constant for the c++ module compilation action. Note: currently we don't support C + * module compilation. + */ + public static final String CPP_MODULE_COMPILE = "c++-module-compile"; + /** A string constant for the assembler actions. */ + public static final String ASSEMBLE = "assemble"; + + public static final String PREPROCESS_ASSEMBLE = "preprocess-assemble"; + /** + * A string constant for the clif actions. Bazel enables different features of the toolchain based + * on the name of the action. This name enables the clif_matcher feature, which switches the + * "compiler" to the clif_matcher and adds some additional arguments as described in the CROSSTOOL + * file. + */ + public static final String CLIF_MATCH = "clif-match"; + + /** Name of the action producing static library. */ + public static final String CPP_LINK_STATIC_LIBRARY = "c++-link-static-library"; + /** Name of the action producing dynamic library from cc_library. */ + public static final String CPP_LINK_NODEPS_DYNAMIC_LIBRARY = "c++-link-nodeps-dynamic-library"; + /** Name of the action producing dynamic library from cc_binary. */ + public static final String CPP_LINK_DYNAMIC_LIBRARY = "c++-link-dynamic-library"; + /** Name of the action producing executable binary. */ + public static final String CPP_LINK_EXECUTABLE = "c++-link-executable"; + /** Name of the objc action producing static library */ + public static final String OBJC_ARCHIVE = "objc-archive"; + /** Name of the objc action producing dynamic library */ + public static final String OBJC_FULLY_LINK = "objc-fully-link"; + /** Name of the objc action producing objc executable binary */ + public static final String OBJC_EXECUTABLE = "objc-executable"; + /** Name of the objc action producing objc++ executable binary */ + public static final String OBJCPP_EXECUTABLE = "objc++-executable"; + + public static final String LTO_INDEXING = "lto-indexing"; + public static final String LTO_BACKEND = "lto-backend"; +} diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java index f19dc727e6cda1..9c7e837e4c0857 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java @@ -93,69 +93,6 @@ public class CppCompileAction extends AbstractAction private static final int VALIDATION_DEBUG = 0; // 0==none, 1==warns/errors, 2==all private static final boolean VALIDATION_DEBUG_WARN = VALIDATION_DEBUG >= 1; - /** A string constant used to compute CC_FLAGS make variable value */ - public static final java.lang.String CC_FLAGS_MAKE_VARIABLE_ACTION_NAME = - "cc-flags-make-variable"; - - /** A string constant for the strip action name. */ - public static final String STRIP_ACTION_NAME = "strip"; - - /** A string constant for the linkstamp-compile action. */ - public static final String LINKSTAMP_COMPILE = "linkstamp-compile"; - - /** - * A string constant for the c compilation action. - */ - public static final String C_COMPILE = "c-compile"; - - /** - * A string constant for the c++ compilation action. - */ - public static final String CPP_COMPILE = "c++-compile"; - - /** A string constant for the c++ module compile action. */ - public static final String CPP_MODULE_CODEGEN = "c++-module-codegen"; - - /** - * A string constant for the objc compilation action. - */ - public static final String OBJC_COMPILE = "objc-compile"; - - /** - * A string constant for the objc++ compile action. - */ - public static final String OBJCPP_COMPILE = "objc++-compile"; - - /** - * A string constant for the c++ header parsing. - */ - public static final String CPP_HEADER_PARSING = "c++-header-parsing"; - - /** - * A string constant for the c++ header preprocessing. - */ - public static final String CPP_HEADER_PREPROCESSING = "c++-header-preprocessing"; - - /** - * A string constant for the c++ module compilation action. - * Note: currently we don't support C module compilation. - */ - public static final String CPP_MODULE_COMPILE = "c++-module-compile"; - - /** - * A string constant for the assembler actions. - */ - public static final String ASSEMBLE = "assemble"; - public static final String PREPROCESS_ASSEMBLE = "preprocess-assemble"; - - /** - * A string constant for the clif actions. Bazel enables different features of the toolchain based - * on the name of the action. This name enables the clif_matcher feature, which switches the - * "compiler" to the clif_matcher and adds some additional arguments as described in the CROSSTOOL - * file. - */ - public static final String CLIF_MATCH = "clif-match"; - protected final Artifact outputFile; private final Artifact sourceFile; private final NestedSet mandatoryInputs; @@ -1327,11 +1264,11 @@ public Iterable getInputFilesForExtraAction( @Override public String getMnemonic() { switch (actionName) { - case OBJC_COMPILE: - case OBJCPP_COMPILE: + case CppActionNames.OBJC_COMPILE: + case CppActionNames.OBJCPP_COMPILE: return "ObjcCompile"; - case LINKSTAMP_COMPILE: + case CppActionNames.LINKSTAMP_COMPILE: // When compiling shared native deps, e.g. when two java_binary rules have the same set of // native dependencies, the CppCompileAction for link stamp data is shared also. This means // that out of two CppCompileAction instances, only one is actually executed, which means diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java index 13d8f3eea6a9e7..9e8b583d7e0c60 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java @@ -232,15 +232,15 @@ private String getActionName() { } PathFragment sourcePath = sourceFile.getExecPath(); if (CppFileTypes.CPP_MODULE_MAP.matches(sourcePath)) { - return CppCompileAction.CPP_MODULE_COMPILE; + return CppActionNames.CPP_MODULE_COMPILE; } else if (CppFileTypes.CPP_HEADER.matches(sourcePath)) { // TODO(bazel-team): Handle C headers that probably don't work in C++ mode. if (!cppConfiguration.getParseHeadersVerifiesModules() && featureConfiguration.isEnabled(CppRuleClasses.PARSE_HEADERS)) { - return CppCompileAction.CPP_HEADER_PARSING; + return CppActionNames.CPP_HEADER_PARSING; } else if (!cppConfiguration.getParseHeadersVerifiesModules() && featureConfiguration.isEnabled(CppRuleClasses.PREPROCESS_HEADERS)) { - return CppCompileAction.CPP_HEADER_PREPROCESSING; + return CppActionNames.CPP_HEADER_PREPROCESSING; } else { // CcCommon.collectCAndCppSources() ensures we do not add headers to // the compilation artifacts unless either 'parse_headers' or @@ -248,21 +248,21 @@ private String getActionName() { throw new IllegalStateException(); } } else if (CppFileTypes.C_SOURCE.matches(sourcePath)) { - return CppCompileAction.C_COMPILE; + return CppActionNames.C_COMPILE; } else if (CppFileTypes.CPP_SOURCE.matches(sourcePath)) { - return CppCompileAction.CPP_COMPILE; + return CppActionNames.CPP_COMPILE; } else if (CppFileTypes.OBJC_SOURCE.matches(sourcePath)) { - return CppCompileAction.OBJC_COMPILE; + return CppActionNames.OBJC_COMPILE; } else if (CppFileTypes.OBJCPP_SOURCE.matches(sourcePath)) { - return CppCompileAction.OBJCPP_COMPILE; + return CppActionNames.OBJCPP_COMPILE; } else if (CppFileTypes.ASSEMBLER.matches(sourcePath)) { - return CppCompileAction.ASSEMBLE; + return CppActionNames.ASSEMBLE; } else if (CppFileTypes.ASSEMBLER_WITH_C_PREPROCESSOR.matches(sourcePath)) { - return CppCompileAction.PREPROCESS_ASSEMBLE; + return CppActionNames.PREPROCESS_ASSEMBLE; } else if (CppFileTypes.CLIF_INPUT_PROTO.matches(sourcePath)) { - return CppCompileAction.CLIF_MATCH; + return CppActionNames.CLIF_MATCH; } else if (CppFileTypes.CPP_MODULE.matches(sourcePath)) { - return CppCompileAction.CPP_MODULE_CODEGEN; + return CppActionNames.CPP_MODULE_CODEGEN; } // CcCompilationHelper ensures CppCompileAction only gets instantiated for supported file types. throw new IllegalStateException(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index d5617e6f5b353d..646ad4c9e63ae4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -902,14 +902,13 @@ public static void createStripAction( return; } - if (!featureConfiguration.actionIsConfigured(CppCompileAction.STRIP_ACTION_NAME)) { + if (!featureConfiguration.actionIsConfigured(CppActionNames.STRIP)) { context.ruleError("Expected action_config for 'strip' to be configured."); return; } Tool stripTool = - Preconditions.checkNotNull( - featureConfiguration.getToolForAction(CppCompileAction.STRIP_ACTION_NAME)); + Preconditions.checkNotNull(featureConfiguration.getToolForAction(CppActionNames.STRIP)); CcToolchainVariables variables = new CcToolchainVariables.Builder(toolchain.getBuildVariables()) .addStringVariable( @@ -919,8 +918,7 @@ public static void createStripAction( .addStringVariable(CcCommon.INPUT_FILE_VARIABLE_NAME, input.getExecPathString()) .build(); ImmutableList commandLine = - ImmutableList.copyOf( - featureConfiguration.getCommandLine(CppCompileAction.STRIP_ACTION_NAME, variables)); + ImmutableList.copyOf(featureConfiguration.getCommandLine(CppActionNames.STRIP, variables)); ImmutableMap.Builder executionInfoBuilder = ImmutableMap.builder(); for (String executionRequirement : stripTool.getExecutionRequirements()) { executionInfoBuilder.put(executionRequirement, ""); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java index 67d020f8ef5e93..ce8d5bc89c5a03 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java @@ -75,7 +75,7 @@ public static CppCompileAction createLinkstampCompileAction( .setBuiltinIncludeFiles(buildInfoHeaderArtifacts) .addMandatoryInputs(nonCodeInputs) .setCppConfiguration(cppConfiguration) - .setActionName(CppCompileAction.LINKSTAMP_COMPILE); + .setActionName(CppActionNames.LINKSTAMP_COMPILE); semantics.finalizeCompileActionBuilder(ruleContext, builder); return builder.buildOrThrowIllegalStateException(); } @@ -140,7 +140,7 @@ private static CcToolchainVariables getVariables( boolean codeCoverageEnabled) { // TODO(b/34761650): Remove all this hardcoding by separating a full blown compile action. Preconditions.checkArgument( - featureConfiguration.actionIsConfigured(CppCompileAction.LINKSTAMP_COMPILE)); + featureConfiguration.actionIsConfigured(CppActionNames.LINKSTAMP_COMPILE)); return CompileBuildVariables.setupVariablesOrReportRuleError( ruleContext, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java index 7e6d2783bbd7af..fece268cd2021e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java @@ -118,7 +118,7 @@ public class FakeCppCompileAction extends CppCompileAction { /* additionalIncludeScanningRoots=*/ ImmutableList.of(), GUID, executionInfo, - CppCompileAction.CPP_COMPILE, + CppActionNames.CPP_COMPILE, cppSemantics, cppProvider, grepIncludes); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java index c32a701207dac0..54c0aca96d26e7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/Link.java @@ -28,24 +28,6 @@ */ public abstract class Link { - /** Name of the action producing static library. */ - public static final String CPP_LINK_STATIC_LIBRARY_ACTION_NAME = "c++-link-static-library"; - /** Name of the action producing dynamic library from cc_library. */ - public static final String CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME = - "c++-link-nodeps-dynamic-library"; - /** Name of the action producing dynamic library from cc_binary. */ - public static final String CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME = "c++-link-dynamic-library"; - /** Name of the action producing executable binary. */ - public static final String CPP_LINK_EXECUTABLE_ACTION_NAME = "c++-link-executable"; - /** Name of the objc action producing static library */ - public static final String OBJC_ARCHIVE_ACTION_NAME = "objc-archive"; - /** Name of the objc action producing dynamic library */ - public static final String OBJC_FULLY_LINK_ACTION_NAME = "objc-fully-link"; - /** Name of the objc action producing objc executable binary */ - public static final String OBJC_EXECUTABLE_ACTION_NAME = "objc-executable"; - /** Name of the objc action producing objc++ executable binary */ - public static final String OBJCPP_EXECUTABLE_ACTION_NAME = "objc++-executable"; - private Link() {} // uninstantiable /** @@ -115,7 +97,7 @@ public enum LinkTargetType { /** A normal static archive. */ STATIC_LIBRARY( LinkerOrArchiver.ARCHIVER, - CPP_LINK_STATIC_LIBRARY_ACTION_NAME, + CppActionNames.CPP_LINK_STATIC_LIBRARY, Picness.NOPIC, ArtifactCategory.STATIC_LIBRARY, Executable.NOT_EXECUTABLE), @@ -123,7 +105,7 @@ public enum LinkTargetType { /** An objc static archive. */ OBJC_ARCHIVE( LinkerOrArchiver.ARCHIVER, - OBJC_ARCHIVE_ACTION_NAME, + CppActionNames.OBJC_ARCHIVE, Picness.NOPIC, ArtifactCategory.STATIC_LIBRARY, Executable.NOT_EXECUTABLE), @@ -131,7 +113,7 @@ public enum LinkTargetType { /** An objc fully linked static archive. */ OBJC_FULLY_LINKED_ARCHIVE( LinkerOrArchiver.ARCHIVER, - OBJC_FULLY_LINK_ACTION_NAME, + CppActionNames.OBJC_FULLY_LINK, Picness.NOPIC, ArtifactCategory.STATIC_LIBRARY, Executable.NOT_EXECUTABLE), @@ -139,7 +121,7 @@ public enum LinkTargetType { /** An objc executable. */ OBJC_EXECUTABLE( LinkerOrArchiver.LINKER, - OBJC_EXECUTABLE_ACTION_NAME, + CppActionNames.OBJC_EXECUTABLE, Picness.NOPIC, ArtifactCategory.EXECUTABLE, Executable.EXECUTABLE), @@ -147,7 +129,7 @@ public enum LinkTargetType { /** An objc executable that includes objc++/c++ source. */ OBJCPP_EXECUTABLE( LinkerOrArchiver.LINKER, - OBJCPP_EXECUTABLE_ACTION_NAME, + CppActionNames.OBJCPP_EXECUTABLE, Picness.NOPIC, ArtifactCategory.EXECUTABLE, Executable.EXECUTABLE), @@ -155,7 +137,7 @@ public enum LinkTargetType { /** A static archive with .pic.o object files (compiled with -fPIC). */ PIC_STATIC_LIBRARY( LinkerOrArchiver.ARCHIVER, - CPP_LINK_STATIC_LIBRARY_ACTION_NAME, + CppActionNames.CPP_LINK_STATIC_LIBRARY, Picness.PIC, ArtifactCategory.STATIC_LIBRARY, Executable.NOT_EXECUTABLE), @@ -163,7 +145,7 @@ public enum LinkTargetType { /** An interface dynamic library. */ INTERFACE_DYNAMIC_LIBRARY( LinkerOrArchiver.LINKER, - CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME, + CppActionNames.CPP_LINK_DYNAMIC_LIBRARY, Picness.NOPIC, // Actually PIC but it's not indicated in the file name ArtifactCategory.INTERFACE_LIBRARY, Executable.NOT_EXECUTABLE), @@ -171,14 +153,14 @@ public enum LinkTargetType { /** A dynamic library built from cc_library srcs. */ NODEPS_DYNAMIC_LIBRARY( LinkerOrArchiver.LINKER, - CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME, + CppActionNames.CPP_LINK_NODEPS_DYNAMIC_LIBRARY, Picness.NOPIC, // Actually PIC but it's not indicated in the file name ArtifactCategory.DYNAMIC_LIBRARY, Executable.NOT_EXECUTABLE), /** A transitive dynamic library used for distribution. */ DYNAMIC_LIBRARY( LinkerOrArchiver.LINKER, - CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME, + CppActionNames.CPP_LINK_DYNAMIC_LIBRARY, Picness.NOPIC, // Actually PIC but it's not indicated in the file name ArtifactCategory.DYNAMIC_LIBRARY, Executable.NOT_EXECUTABLE), @@ -186,7 +168,7 @@ public enum LinkTargetType { /** A static archive without removal of unused object files. */ ALWAYS_LINK_STATIC_LIBRARY( LinkerOrArchiver.ARCHIVER, - CPP_LINK_STATIC_LIBRARY_ACTION_NAME, + CppActionNames.CPP_LINK_STATIC_LIBRARY, Picness.NOPIC, ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY, Executable.NOT_EXECUTABLE), @@ -194,7 +176,7 @@ public enum LinkTargetType { /** A PIC static archive without removal of unused object files. */ ALWAYS_LINK_PIC_STATIC_LIBRARY( LinkerOrArchiver.ARCHIVER, - CPP_LINK_STATIC_LIBRARY_ACTION_NAME, + CppActionNames.CPP_LINK_STATIC_LIBRARY, Picness.PIC, ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY, Executable.NOT_EXECUTABLE), @@ -202,7 +184,7 @@ public enum LinkTargetType { /** An executable binary. */ EXECUTABLE( LinkerOrArchiver.LINKER, - CPP_LINK_EXECUTABLE_ACTION_NAME, + CppActionNames.CPP_LINK_EXECUTABLE, Picness.NOPIC, // Picness is not indicate in the file name ArtifactCategory.EXECUTABLE, Executable.EXECUTABLE); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java index f0e56358aacfd7..9104db77e0d5be 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariables.java @@ -252,7 +252,7 @@ public static CcToolchainVariables setupVariables( List opts = new ArrayList<>(userLinkFlags); opts.addAll( featureConfiguration.getCommandLine( - "lto-indexing", buildVariables.build(), /* expander= */ null)); + CppActionNames.LTO_INDEXING, buildVariables.build(), /* expander= */ null)); opts.addAll(ccToolchainProvider.getCppConfiguration().getLtoIndexOptions()); userLinkFlagsWithLtoIndexingIfNeeded = ImmutableList.copyOf(opts); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendArtifacts.java index f3e6d688a9fd04..643fb26eb05937 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendArtifacts.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LtoBackendArtifacts.java @@ -52,6 +52,7 @@ */ @AutoCodec public final class LtoBackendArtifacts { + // A file containing mapping of symbol => bitcode file containing the symbol. // It will be null when this is a shared non-lto backend. private final Artifact index; @@ -259,7 +260,8 @@ private void scheduleLtoBackendAction( execArgs.addAll(commandLine); CcToolchainVariables buildVariables = buildVariablesBuilder.build(); // Feature options should go after --copt for consistency with compile actions. - execArgs.addAll(featureConfiguration.getCommandLine("lto-backend", buildVariables)); + execArgs.addAll( + featureConfiguration.getCommandLine(CppActionNames.LTO_BACKEND, buildVariables)); // If this is a PIC compile (set based on the CppConfiguration), the PIC // option should be added after the rest of the command line so that it // cannot be overridden. This is consistent with the ordering in the diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java index a072dd9c147304..2033dc66cee008 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java @@ -23,7 +23,7 @@ import com.google.devtools.build.lib.cmdline.LabelSyntaxException; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.cmdline.RepositoryName; -import com.google.devtools.build.lib.rules.cpp.CppCompileAction; +import com.google.devtools.build.lib.rules.cpp.CppActionNames; import com.google.devtools.build.lib.rules.cpp.CppRuleClasses; import com.google.devtools.build.lib.rules.cpp.Link.LinkTargetType; import com.google.devtools.build.lib.testutil.TestConstants; @@ -507,13 +507,13 @@ public boolean apply(Artifact artifact) { + "}"; public static final String EMPTY_COMPILE_ACTION_CONFIG = - emptyActionConfigFor(CppCompileAction.CPP_COMPILE); + emptyActionConfigFor(CppActionNames.CPP_COMPILE); public static final String EMPTY_MODULE_CODEGEN_ACTION_CONFIG = - emptyActionConfigFor(CppCompileAction.CPP_MODULE_CODEGEN); + emptyActionConfigFor(CppActionNames.CPP_MODULE_CODEGEN); public static final String EMPTY_MODULE_COMPILE_ACTION_CONFIG = - emptyActionConfigFor(CppCompileAction.CPP_MODULE_COMPILE); + emptyActionConfigFor(CppActionNames.CPP_MODULE_COMPILE); public static final String EMPTY_EXECUTABLE_ACTION_CONFIG = emptyActionConfigFor(LinkTargetType.EXECUTABLE.getActionName()); @@ -528,10 +528,9 @@ public boolean apply(Artifact artifact) { emptyActionConfigFor(LinkTargetType.STATIC_LIBRARY.getActionName()); public static final String EMPTY_CLIF_MATCH_ACTION_CONFIG = - emptyActionConfigFor(CppCompileAction.CLIF_MATCH); + emptyActionConfigFor(CppActionNames.CLIF_MATCH); - public static final String EMPTY_STRIP_ACTION_CONFIG = - emptyActionConfigFor(CppCompileAction.STRIP_ACTION_NAME); + public static final String EMPTY_STRIP_ACTION_CONFIG = emptyActionConfigFor(CppActionNames.STRIP); /** * Creates action_config for {@code actionName} action using DUMMY_TOOL that doesn't imply any @@ -727,10 +726,12 @@ protected static void createToolsCppPackage(MockToolsConfig config) throws IOExc config.linkTool("tools/cpp/link_dynamic_library.sh"); config.linkTool("tools/cpp/build_interface_so"); config.linkTool("tools/cpp/grep-includes"); + config.linkTool("tools/build_defs/cc/action_names.bzl"); } else { config.create("tools/cpp/link_dynamic_library.sh", ""); config.create("tools/cpp/build_interface_so", ""); config.create("tools/cpp/grep-includes", ""); + config.linkTool("tools/build_defs/cc/action_names.bzl", ""); } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java index f8c29e00e81e4a..a0671e386df4ca 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainFeaturesTest.java @@ -225,8 +225,8 @@ public void testFlagOrderEqualsSpecOrder() throws Exception { " }", "}") .getFeatureConfiguration(ImmutableSet.of("a", "b")); - List commandLine = configuration.getCommandLine( - CppCompileAction.CPP_COMPILE, createVariables()); + List commandLine = + configuration.getCommandLine(CppActionNames.CPP_COMPILE, createVariables()); assertThat(commandLine).containsExactly("-a-c++-compile", "-b-c++-compile").inOrder(); } @@ -285,8 +285,8 @@ public void testEnvVars() throws Exception { "feature { name: 'f' }", "feature { name: 'g' }") .getFeatureConfiguration(ImmutableSet.of("a", "b", "d", "f")); - Map env = configuration.getEnvironmentVariables( - CppCompileAction.CPP_COMPILE, createVariables()); + Map env = + configuration.getEnvironmentVariables(CppActionNames.CPP_COMPILE, createVariables()); assertThat(env) .containsExactly( "foo", "bar", "cat", "meow", "dog", "woof", @@ -317,7 +317,7 @@ private List getCommandLineForFlagGroups(String groups, CcToolchainVaria " }", "}") .getFeatureConfiguration(ImmutableSet.of("a")); - return configuration.getCommandLine(CppCompileAction.CPP_COMPILE, variables); + return configuration.getCommandLine(CppActionNames.CPP_COMPILE, variables); } private List getCommandLineForFlag(String value, CcToolchainVariables variables) @@ -1081,7 +1081,7 @@ public void testFlagSetWithMissingVariableIsNotExpanded() throws Exception { "}") .getFeatureConfiguration(ImmutableSet.of("a")); - assertThat(configuration.getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + assertThat(configuration.getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .containsExactly("unconditional"); } @@ -1109,8 +1109,7 @@ public void testOnlyFlagSetsWithAllVariablesPresentAreExpanded() throws Exceptio "}") .getFeatureConfiguration(ImmutableSet.of("a")); - assertThat( - configuration.getCommandLine(CppCompileAction.CPP_COMPILE, createVariables("v", "1"))) + assertThat(configuration.getCommandLine(CppActionNames.CPP_COMPILE, createVariables("v", "1"))) .containsExactly("1", "unconditional"); } @@ -1140,7 +1139,7 @@ public void testOnlyInnerFlagSetIsIteratedWithSequenceVariable() throws Exceptio assertThat( configuration.getCommandLine( - CppCompileAction.CPP_COMPILE, createVariables("v", "1", "v", "2"))) + CppActionNames.CPP_COMPILE, createVariables("v", "1", "v", "2"))) .containsExactly("1", "2", "unconditional") .inOrder(); } @@ -1171,7 +1170,7 @@ public void testFlagSetsAreIteratedIndividuallyForSequenceVariables() throws Exc assertThat( configuration.getCommandLine( - CppCompileAction.CPP_COMPILE, createVariables("v", "1", "v", "2", "w", "3"))) + CppActionNames.CPP_COMPILE, createVariables("v", "1", "v", "2", "w", "3"))) .containsExactly("1", "2", "13", "23", "unconditional") .inOrder(); } @@ -1194,7 +1193,7 @@ public void testConfiguration() throws Exception { assertThat( features .getFeatureConfiguration(ImmutableSet.of("b")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables("v", "1"))) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables("v", "1"))) .containsExactly("-f", "1"); byte[] serialized = TestUtils.serializeObject(features); CcToolchainFeatures deserialized = @@ -1203,7 +1202,7 @@ public void testConfiguration() throws Exception { assertThat( features .getFeatureConfiguration(ImmutableSet.of("b")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables("v", "1"))) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables("v", "1"))) .containsExactly("-f", "1"); } @@ -1240,12 +1239,12 @@ public void testWithFeature_OneSetOneFeature() throws Exception { assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "b")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .containsExactly("dummy_flag"); assertThat( features .getFeatureConfiguration(ImmutableSet.of("a")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .doesNotContain("dummy_flag"); } @@ -1268,17 +1267,17 @@ public void testWithFeature_OneSetMultipleFeatures() throws Exception { assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "b", "c")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .containsExactly("dummy_flag"); assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "b")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .doesNotContain("dummy_flag"); assertThat( features .getFeatureConfiguration(ImmutableSet.of("a")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .doesNotContain("dummy_flag"); } @@ -1304,17 +1303,17 @@ public void testWithFeature_MulipleSetsMultipleFeatures() throws Exception { assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "b1", "c1", "b2", "c2")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .containsExactly("dummy_flag"); assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "b1", "c1")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .containsExactly("dummy_flag"); assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "b1", "b2")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .doesNotContain("dummy_flag"); } @@ -1340,27 +1339,27 @@ public void testWithFeature_NotFeature() throws Exception { assertThat( features .getFeatureConfiguration(ImmutableSet.of("a")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .containsExactly("dummy_flag"); assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "q")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .doesNotContain("dummy_flag"); assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "q", "z")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .containsExactly("dummy_flag"); assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "q", "x", "z")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .doesNotContain("dummy_flag"); assertThat( features .getFeatureConfiguration(ImmutableSet.of("a", "q", "x", "y", "z")) - .getCommandLine(CppCompileAction.CPP_COMPILE, createVariables())) + .getCommandLine(CppActionNames.CPP_COMPILE, createVariables())) .doesNotContain("dummy_flag"); } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java index 9778050d01c683..1dffb0f87073e2 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLineTest.java @@ -55,14 +55,14 @@ private static FeatureConfiguration getMockFeatureConfiguration(String... crosst return CcToolchainFeaturesTest.buildFeatures(crosstool) .getFeatureConfiguration( ImmutableSet.of( - CppCompileAction.ASSEMBLE, - CppCompileAction.PREPROCESS_ASSEMBLE, - CppCompileAction.C_COMPILE, - CppCompileAction.CPP_COMPILE, - CppCompileAction.CPP_HEADER_PARSING, - CppCompileAction.CPP_HEADER_PREPROCESSING, - CppCompileAction.CPP_MODULE_CODEGEN, - CppCompileAction.CPP_MODULE_COMPILE)); + CppActionNames.ASSEMBLE, + CppActionNames.PREPROCESS_ASSEMBLE, + CppActionNames.C_COMPILE, + CppActionNames.CPP_COMPILE, + CppActionNames.CPP_HEADER_PARSING, + CppActionNames.CPP_HEADER_PREPROCESSING, + CppActionNames.CPP_MODULE_CODEGEN, + CppActionNames.CPP_MODULE_COMPILE)); } @Test diff --git a/tools/BUILD b/tools/BUILD index 04e77109fe23c3..0f28085e75a666 100644 --- a/tools/BUILD +++ b/tools/BUILD @@ -11,6 +11,7 @@ filegroup( "//tools/bash:srcs", "//tools/buildstamp:srcs", "//tools/build_defs/apple:srcs", + "//tools/build_defs/cc:srcs", "//tools/build_defs/apple/test:srcs", "//tools/build_defs/docker:srcs", "//tools/build_defs/hash:srcs", @@ -44,6 +45,7 @@ filegroup( "//tools/android:embedded_tools", "//tools/bash:embedded_tools", "//tools/build_defs/apple:srcs", + "//tools/build_defs/cc:srcs", "//tools/build_defs/hash:srcs", "//tools/build_defs/pkg:srcs", "//tools/build_defs/repo:srcs", diff --git a/tools/build_defs/cc/BUILD b/tools/build_defs/cc/BUILD new file mode 100644 index 00000000000000..9405d4a0d4e22a --- /dev/null +++ b/tools/build_defs/cc/BUILD @@ -0,0 +1,12 @@ +licenses(["notice"]) # Apache 2.0 + +exports_files(["action_names.bzl"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), + visibility = [ + "//:__pkg__", + "//tools:__pkg__", + ], +) diff --git a/tools/build_defs/cc/action_names.bzl b/tools/build_defs/cc/action_names.bzl new file mode 100644 index 00000000000000..53061c48d3627e --- /dev/null +++ b/tools/build_defs/cc/action_names.bzl @@ -0,0 +1,66 @@ +# Copyright 2018 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Constants for action names used for C++ rules.""" + +# Name for the C compilation action. +C_COMPILE_ACTION_NAME = "c-compile" + +# Name of the C++ compilation action. +CPP_COMPILE_ACTION_NAME = "c++-compile" + +# Name of the linkstamp-compile action. +LINKSTAMP_COMPILE_ACTION_NAME = "linkstamp-compile" + +# Name of the action used to compute CC_FLAGS make variable. +CC_FLAGS_MAKE_VARIABLE_ACTION_NAME_ACTION_NAME = "cc-flags-make-variable" + +# Name of the C++ module codegen action. +CPP_MODULE_CODEGEN_ACTION_NAME = "c++-module-codegen" + +# Name of the C++ header parsing action. +CPP_HEADER_PARSING_ACTION_NAME = "c++-header-parsing" + +# Name of the C++ header preprocessing action. +CPP_HEADER_PREPROCESSING_ACTION_NAME = "c++-header-preprocessing" + +# Name of the C++ module compile action. +CPP_MODULE_COMPILE_ACTION_NAME = "c++-module-compile" + +# Name of the assembler action. +ASSEMBLE_ACTION_NAME = "assemble" + +# Name of the assembly preprocessing action. +PREPROCESS_ASSEMBLE_ACTION_NAME = "preprocess-assemble" + +# Name of the action producing ThinLto index. +LTO_INDEXING_ACTION_NAME = "lto-indexing" + +# Name of the action compiling lto bitcodes into native objects. +LTO_BACKEND_ACTION_NAME = "lto-backend" + +# Name of the link action producing executable binary. +CPP_LINK_EXECUTABLE_ACTION_NAME = "c++-link-executable" + +# Name of the link action producing dynamic library. +CPP_LINK_DYNAMIC_LIBRARY_ACTION_NAME = "c++-link-dynamic-library" + +# Name of the link action producing dynamic library that doesn't include it's +# transitive dependencies. +CPP_LINK_NODEPS_DYNAMIC_LIBRARY_ACTION_NAME = "c++-link-nodeps-dynamic-library" + +# Name of the archiving action producing static library. +CPP_LINK_STATIC_LIBRARY_ACTION_NAME = "c++-link-static-library" + +# Name of the action stripping the binary. +STRIP_ACTION_NAME = "strip"