diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java | 3 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariables.java (renamed from src/main/java/com/google/devtools/build/lib/rules/cpp/CcBuildVariables.java) | 231 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java | 1 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java | 1 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkstampCompileHelper.java | 2 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java | 1 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/StripBuildVariables.java | 32 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java | 1 |
8 files changed, 130 insertions, 142 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java index 985d5fcee2..7ac3f194b5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCompilationHelper.java @@ -47,7 +47,6 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.packages.BuildType; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; -import com.google.devtools.build.lib.rules.cpp.CcBuildVariables.CompileBuildVariables; import com.google.devtools.build.lib.rules.cpp.CcCommon.CoptsFilter; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables; @@ -1468,7 +1467,7 @@ public final class CcCompilationHelper { featureConfiguration, fdoSupport)); } - return CcBuildVariables.setupCompileBuildVariables( + return CompileBuildVariables.setupVariables( ruleContext, featureConfiguration, ccToolchain, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBuildVariables.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariables.java index 857eb9913f..453d61f37a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBuildVariables.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariables.java @@ -27,112 +27,82 @@ import com.google.devtools.build.lib.util.FileType; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.Collection; -/** - * Utility class for collecting knowledge about what build variables we create and when we create - * them. Having this central location is useful so we can reason about what variables expose to - * Skylark, what variables are redundant etc. - */ -public class CcBuildVariables { - - /** Enum covering all build variables we create for 'strip' actions. */ - public enum StripBuildVariables { - /** Variable for the path to the compilation output file. */ - OUTPUT_FILE("output_file"), - /** Variable for stripopts. */ - STRIPOPTS("stripopts"); - - private final String variableName; - - StripBuildVariables(String variableName) { - this.variableName = variableName; - } - - public String getVariableName() { - return variableName; - } - } - - /** Enum covering all build variables we create for all various {@link CppCompileAction}. */ - public enum CompileBuildVariables { - /** Variable for the path to the source file being compiled. */ - SOURCE_FILE("source_file"), - /** - * Variable for all flags coming from copt rule attribute, and from --copt, --cxxopt, or - * --conlyopt options. - */ - USER_COMPILE_FLAGS("user_compile_flags"), - /** - * Variable for all flags coming from legacy crosstool fields, such as compiler_flag, - * optional_compiler_flag, cxx_flag. - */ - LEGACY_COMPILE_FLAGS("legacy_compile_flags"), - /** Variable for flags coming from unfiltered_cxx_flag CROSSTOOL fields. */ - UNFILTERED_COMPILE_FLAGS("unfiltered_compile_flags"), - /** Variable for the path to the output file when output is an object file. */ - OUTPUT_OBJECT_FILE("output_object_file"), - /** Variable for the path to the compilation output file. */ - OUTPUT_FILE("output_file"), - /** Variable for the dependency file path */ - DEPENDENCY_FILE("dependency_file"), - /** Variable for the module file name. */ - MODULE_NAME("module_name"), - /** - * Variable for the collection of include paths. - * - * @see CcCompilationInfo#getIncludeDirs(). - */ - INCLUDE_PATHS("include_paths"), - /** - * Variable for the collection of quote include paths. - * - * @see CcCompilationInfo#getIncludeDirs(). - */ - QUOTE_INCLUDE_PATHS("quote_include_paths"), - /** - * Variable for the collection of system include paths. - * - * @see CcCompilationInfo#getIncludeDirs(). - */ - SYSTEM_INCLUDE_PATHS("system_include_paths"), - /** Variable for the module map file name. */ - MODULE_MAP_FILE("module_map_file"), - /** Variable for the dependent module map file name. */ - DEPENDENT_MODULE_MAP_FILES("dependent_module_map_files"), - /** Variable for the collection of module files. */ - MODULE_FILES("module_files"), - /** Variable for the collection of macros defined for preprocessor. */ - PREPROCESSOR_DEFINES("preprocessor_defines"), - /** Variable for the gcov coverage file path. */ - GCOV_GCNO_FILE("gcov_gcno_file"), - /** Variable for the LTO indexing bitcode file. */ - LTO_INDEXING_BITCODE_FILE("lto_indexing_bitcode_file"), - /** Variable for the per object debug info file. */ - PER_OBJECT_DEBUG_INFO_FILE("per_object_debug_info_file"), - /** Variable present when the output is compiled as position independent. */ - PIC("pic"), - /** Variable marking that we are generating preprocessed sources (from --save_temps). */ - OUTPUT_PREPROCESS_FILE("output_preprocess_file"), - /** Variable marking that we are generating assembly source (from --save_temps). */ - OUTPUT_ASSEMBLY_FILE("output_assembly_file"), - /** Path to the fdo instrument artifact */ - FDO_INSTRUMENT_PATH("fdo_instrument_path"), - /** Path to the fdo profile artifact */ - FDO_PROFILE_PATH("fdo_profile_path"), - /** Variable for includes that compiler needs to include into sources. */ - INCLUDES("includes"); - - private final String variableName; +/** Enum covering all build variables we create for all various {@link CppCompileAction}. */ +public enum CompileBuildVariables { + /** Variable for the path to the source file being compiled. */ + SOURCE_FILE("source_file"), + /** + * Variable for all flags coming from copt rule attribute, and from --copt, --cxxopt, or + * --conlyopt options. + */ + USER_COMPILE_FLAGS("user_compile_flags"), + /** + * Variable for all flags coming from legacy crosstool fields, such as compiler_flag, + * optional_compiler_flag, cxx_flag. + */ + LEGACY_COMPILE_FLAGS("legacy_compile_flags"), + /** Variable for flags coming from unfiltered_cxx_flag CROSSTOOL fields. */ + UNFILTERED_COMPILE_FLAGS("unfiltered_compile_flags"), + /** Variable for the path to the output file when output is an object file. */ + OUTPUT_OBJECT_FILE("output_object_file"), + /** Variable for the path to the compilation output file. */ + OUTPUT_FILE("output_file"), + /** Variable for the dependency file path */ + DEPENDENCY_FILE("dependency_file"), + /** Variable for the module file name. */ + MODULE_NAME("module_name"), + /** + * Variable for the collection of include paths. + * + * @see CcCompilationInfo#getIncludeDirs(). + */ + INCLUDE_PATHS("include_paths"), + /** + * Variable for the collection of quote include paths. + * + * @see CcCompilationInfo#getIncludeDirs(). + */ + QUOTE_INCLUDE_PATHS("quote_include_paths"), + /** + * Variable for the collection of system include paths. + * + * @see CcCompilationInfo#getIncludeDirs(). + */ + SYSTEM_INCLUDE_PATHS("system_include_paths"), + /** Variable for the module map file name. */ + MODULE_MAP_FILE("module_map_file"), + /** Variable for the dependent module map file name. */ + DEPENDENT_MODULE_MAP_FILES("dependent_module_map_files"), + /** Variable for the collection of module files. */ + MODULE_FILES("module_files"), + /** Variable for the collection of macros defined for preprocessor. */ + PREPROCESSOR_DEFINES("preprocessor_defines"), + /** Variable for the gcov coverage file path. */ + GCOV_GCNO_FILE("gcov_gcno_file"), + /** Variable for the LTO indexing bitcode file. */ + LTO_INDEXING_BITCODE_FILE("lto_indexing_bitcode_file"), + /** Variable for the per object debug info file. */ + PER_OBJECT_DEBUG_INFO_FILE("per_object_debug_info_file"), + /** Variable present when the output is compiled as position independent. */ + PIC("pic"), + /** Variable marking that we are generating preprocessed sources (from --save_temps). */ + OUTPUT_PREPROCESS_FILE("output_preprocess_file"), + /** Variable marking that we are generating assembly source (from --save_temps). */ + OUTPUT_ASSEMBLY_FILE("output_assembly_file"), + /** Path to the fdo instrument artifact */ + FDO_INSTRUMENT_PATH("fdo_instrument_path"), + /** Path to the fdo profile artifact */ + FDO_PROFILE_PATH("fdo_profile_path"), + /** Variable for includes that compiler needs to include into sources. */ + INCLUDES("includes"); - CompileBuildVariables(String variableName) { - this.variableName = variableName; - } + private final String variableName; - public String getVariableName() { - return variableName; - } + CompileBuildVariables(String variableName) { + this.variableName = variableName; } - public static Variables setupCompileBuildVariables( + public static Variables setupVariables( RuleContext ruleContext, FeatureConfiguration featureConfiguration, CcToolchainProvider ccToolchainProvider, @@ -157,14 +127,13 @@ public class CcBuildVariables { new Variables.Builder(ccToolchainProvider.getBuildVariables()); buildVariables.addStringSequenceVariable( - CompileBuildVariables.USER_COMPILE_FLAGS.getVariableName(), userCompileFlags); + USER_COMPILE_FLAGS.getVariableName(), userCompileFlags); - buildVariables.addStringVariable( - CompileBuildVariables.SOURCE_FILE.getVariableName(), sourceFile.getExecPathString()); + buildVariables.addStringVariable(SOURCE_FILE.getVariableName(), sourceFile.getExecPathString()); String sourceFilename = sourceFile.getExecPathString(); buildVariables.addLazyStringSequenceVariable( - CompileBuildVariables.LEGACY_COMPILE_FLAGS.getVariableName(), + LEGACY_COMPILE_FLAGS.getVariableName(), getLegacyCompileFlagsSupplier( ruleContext.getFragment(CppConfiguration.class), ccToolchainProvider, @@ -174,7 +143,7 @@ public class CcBuildVariables { if (!CppFileTypes.OBJC_SOURCE.matches(sourceFilename) && !CppFileTypes.OBJCPP_SOURCE.matches(sourceFilename)) { buildVariables.addLazyStringSequenceVariable( - CompileBuildVariables.UNFILTERED_COMPILE_FLAGS.getVariableName(), + UNFILTERED_COMPILE_FLAGS.getVariableName(), getUnfilteredCompileFlagsSupplier(ccToolchainProvider, features)); } @@ -188,54 +157,45 @@ public class CcBuildVariables { CppFileTypes.PIC_PREPROCESSED_C, CppFileTypes.PIC_PREPROCESSED_CPP)) { buildVariables.addStringVariable( - CompileBuildVariables.OUTPUT_OBJECT_FILE.getVariableName(), - realOutputFilePath.getSafePathString()); + OUTPUT_OBJECT_FILE.getVariableName(), realOutputFilePath.getSafePathString()); } buildVariables.addStringVariable( - CompileBuildVariables.OUTPUT_FILE.getVariableName(), - realOutputFilePath.getSafePathString()); + OUTPUT_FILE.getVariableName(), realOutputFilePath.getSafePathString()); // Set dependency_file to enable <object>.d file generation. if (dotdFileExecPath != null) { - buildVariables.addStringVariable( - CompileBuildVariables.DEPENDENCY_FILE.getVariableName(), dotdFileExecPath); + buildVariables.addStringVariable(DEPENDENCY_FILE.getVariableName(), dotdFileExecPath); } 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.getVariableName(), cppModuleMap.getName()); buildVariables.addStringVariable( - CompileBuildVariables.MODULE_NAME.getVariableName(), cppModuleMap.getName()); - buildVariables.addStringVariable( - CompileBuildVariables.MODULE_MAP_FILE.getVariableName(), - cppModuleMap.getArtifact().getExecPathString()); + MODULE_MAP_FILE.getVariableName(), cppModuleMap.getArtifact().getExecPathString()); StringSequenceBuilder sequence = new StringSequenceBuilder(); for (Artifact artifact : ccCompilationInfo.getDirectModuleMaps()) { sequence.addValue(artifact.getExecPathString()); } - buildVariables.addCustomBuiltVariable( - CompileBuildVariables.DEPENDENT_MODULE_MAP_FILES.getVariableName(), sequence); + buildVariables.addCustomBuiltVariable(DEPENDENT_MODULE_MAP_FILES.getVariableName(), sequence); } if (featureConfiguration.isEnabled(CppRuleClasses.USE_HEADER_MODULES)) { // Module inputs will be set later when the action is executed. - buildVariables.addStringSequenceVariable( - CompileBuildVariables.MODULE_FILES.getVariableName(), ImmutableSet.of()); + buildVariables.addStringSequenceVariable(MODULE_FILES.getVariableName(), ImmutableSet.of()); } if (featureConfiguration.isEnabled(CppRuleClasses.INCLUDE_PATHS)) { buildVariables.addStringSequenceVariable( - CompileBuildVariables.INCLUDE_PATHS.getVariableName(), - getSafePathStrings(ccCompilationInfo.getIncludeDirs())); + INCLUDE_PATHS.getVariableName(), getSafePathStrings(ccCompilationInfo.getIncludeDirs())); buildVariables.addStringSequenceVariable( - CompileBuildVariables.QUOTE_INCLUDE_PATHS.getVariableName(), + QUOTE_INCLUDE_PATHS.getVariableName(), getSafePathStrings(ccCompilationInfo.getQuoteIncludeDirs())); buildVariables.addStringSequenceVariable( - CompileBuildVariables.SYSTEM_INCLUDE_PATHS.getVariableName(), + SYSTEM_INCLUDE_PATHS.getVariableName(), getSafePathStrings(ccCompilationInfo.getSystemIncludeDirs())); } if (!includes.isEmpty()) { - buildVariables.addStringSequenceVariable( - CompileBuildVariables.INCLUDES.getVariableName(), includes); + buildVariables.addStringSequenceVariable(INCLUDES.getVariableName(), includes); } if (featureConfiguration.isEnabled(CppRuleClasses.PREPROCESSOR_DEFINES)) { @@ -251,32 +211,29 @@ public class CcBuildVariables { defines = ccCompilationInfo.getDefines(); } - buildVariables.addStringSequenceVariable( - CompileBuildVariables.PREPROCESSOR_DEFINES.getVariableName(), defines); + buildVariables.addStringSequenceVariable(PREPROCESSOR_DEFINES.getVariableName(), defines); } if (usePic) { if (!featureConfiguration.isEnabled(CppRuleClasses.PIC)) { ruleContext.ruleError(CcCommon.PIC_CONFIGURATION_ERROR); } - buildVariables.addStringVariable(CompileBuildVariables.PIC.getVariableName(), ""); + buildVariables.addStringVariable(PIC.getVariableName(), ""); } if (gcnoFile != null) { buildVariables.addStringVariable( - CompileBuildVariables.GCOV_GCNO_FILE.getVariableName(), gcnoFile.getExecPathString()); + GCOV_GCNO_FILE.getVariableName(), gcnoFile.getExecPathString()); } if (dwoFile != null) { buildVariables.addStringVariable( - CompileBuildVariables.PER_OBJECT_DEBUG_INFO_FILE.getVariableName(), - dwoFile.getExecPathString()); + PER_OBJECT_DEBUG_INFO_FILE.getVariableName(), dwoFile.getExecPathString()); } if (ltoIndexingFile != null) { buildVariables.addStringVariable( - CompileBuildVariables.LTO_INDEXING_BITCODE_FILE.getVariableName(), - ltoIndexingFile.getExecPathString()); + LTO_INDEXING_BITCODE_FILE.getVariableName(), ltoIndexingFile.getExecPathString()); } buildVariables.addAllStringVariables(additionalBuildVariables); @@ -332,4 +289,8 @@ public class CcBuildVariables { CcToolchainProvider ccToolchain, ImmutableSet<String> features) { return () -> ccToolchain.getUnfilteredCompilerOptions(features); } + + public String getVariableName() { + return variableName; + } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java index e15eaabe29..01d0075a5f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CompileCommandLine.java @@ -17,7 +17,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.rules.cpp.CcBuildVariables.CompileBuildVariables; import com.google.devtools.build.lib.rules.cpp.CcCommon.CoptsFilter; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables; 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 adf2e0a1f3..c79c3da3e6 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 @@ -57,7 +57,6 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.packages.RuleClass.ConfiguredTargetFactory.RuleErrorException; import com.google.devtools.build.lib.packages.RuleErrorConsumer; -import com.google.devtools.build.lib.rules.cpp.CcBuildVariables.StripBuildVariables; import com.google.devtools.build.lib.rules.cpp.CcCompilationInfo.Builder; import com.google.devtools.build.lib.rules.cpp.CcLinkParams.Linkstamp; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; 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 670137705a..b3e8b56a92 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 @@ -156,7 +156,7 @@ public class CppLinkstampCompileHelper { codeCoverageEnabled)) .build(); - return CcBuildVariables.setupCompileBuildVariables( + return CompileBuildVariables.setupVariables( ruleContext, featureConfiguration, ccToolchainProvider, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java index 443c2d41ad..e86514e199 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java @@ -32,7 +32,6 @@ import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; -import com.google.devtools.build.lib.rules.cpp.CcBuildVariables.CompileBuildVariables; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.FeatureConfiguration; import com.google.devtools.build.lib.skyframe.FileValue; import com.google.devtools.build.lib.skyframe.PrecomputedValue; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/StripBuildVariables.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/StripBuildVariables.java new file mode 100644 index 0000000000..65819085bf --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/StripBuildVariables.java @@ -0,0 +1,32 @@ +// Copyright 2014 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; + +/** Enum covering all build variables we create for 'strip' actions. */ +public enum StripBuildVariables { + /** Variable for the path to the compilation output file. */ + OUTPUT_FILE("output_file"), + /** Variable for stripopts. */ + STRIPOPTS("stripopts"); + + private final String variableName; + + StripBuildVariables(String variableName) { + this.variableName = variableName; + } + + public String getVariableName() { + return variableName; + } +} diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java index 491c51593a..2714ef51c9 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java @@ -22,7 +22,6 @@ import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.util.AnalysisMock; import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; -import com.google.devtools.build.lib.rules.cpp.CcBuildVariables.CompileBuildVariables; import com.google.devtools.build.lib.rules.cpp.CcToolchainFeatures.Variables; import org.junit.Test; import org.junit.runner.RunWith; |