diff options
author | Lukacs Berki <lberki@google.com> | 2016-05-24 13:19:48 +0000 |
---|---|---|
committer | Yue Gan <yueg@google.com> | 2016-05-25 08:33:53 +0000 |
commit | a5c2fa4018fdbfff7ce426d3780592eb2d17ce3f (patch) | |
tree | ca883d4c60b64bc231879b33b28c494a89bda32a /src/main/java/com/google/devtools/build/lib | |
parent | c6d3cccfc647071eb9bd03fb60043922b8560931 (diff) |
Move -frandom-seed= into a feature.
One more thing that doesn't work on Windows is gone.
As a drive-by fix, also remove usePic from CppCompileAction since it's not needed anymore.
--
MOS_MIGRATED_REVID=123099120
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
7 files changed, 41 insertions, 21 deletions
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 6ac68d579f..1a88ae9967 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 @@ -83,6 +83,7 @@ public final class CcCommon { * Features we request to enable unless a rule explicitly doesn't support them. */ private static final ImmutableSet<String> DEFAULT_FEATURES = ImmutableSet.of( + CppRuleClasses.RANDOM_SEED, CppRuleClasses.MODULE_MAPS, CppRuleClasses.MODULE_MAP_HOME_CWD, CppRuleClasses.HEADER_MODULE_INCLUDES_DEPENDENCIES, 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 167f59268f..6a3db11b3c 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 @@ -171,7 +171,6 @@ public class CppCompileAction extends AbstractAction private final Iterable<IncludeScannable> lipoScannables; private final ImmutableList<Artifact> builtinIncludeFiles; @VisibleForTesting public final CppCompileCommandLine cppCompileCommandLine; - private final boolean usePic; private final ImmutableSet<String> executionRequirements; @VisibleForTesting @@ -254,7 +253,6 @@ public class CppCompileAction extends AbstractAction SpecialInputsHandler specialInputsHandler, Iterable<IncludeScannable> lipoScannables, UUID actionClassId, - boolean usePic, ImmutableSet<String> executionRequirements, String actionName, RuleContext ruleContext) { @@ -295,7 +293,6 @@ public class CppCompileAction extends AbstractAction this.actionContext = actionContext; this.lipoScannables = lipoScannables; this.actionClassId = actionClassId; - this.usePic = usePic; this.executionRequirements = executionRequirements; // We do not need to include the middleman artifact since it is a generated @@ -1359,14 +1356,6 @@ public class CppCompileAction extends AbstractAction // own include paths first. options.addAll(toolchain.getUnfilteredCompilerOptions(features)); - // GCC gives randomized names to symbols which are defined in - // an anonymous namespace but have external linkage. To make - // computation of these deterministic, we want to override the - // default seed for the random number generator. It's safe to use - // any value which differs for all translation units; we use the - // path to the object file. - options.add("-frandom-seed=" + outputFile.getExecPathString()); - // Add the options of --per_file_copt, if the label or the base name of the source file // matches the specified regular expression filter. for (PerLabelOptions perLabelOptions : cppConfiguration.getPerFileCopts()) { 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 97f05b8694..0df93ecd33 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 @@ -300,8 +300,7 @@ public class CppCompileActionBuilder { actionContext, ImmutableList.copyOf(copts), getNocoptPredicate(nocopts), - ruleContext, - usePic); + ruleContext); } else { NestedSet<Artifact> realMandatoryInputs = realMandatoryInputsBuilder.build(); @@ -328,7 +327,6 @@ public class CppCompileActionBuilder { specialInputsHandler, getLipoScannables(realMandatoryInputs), actionClassId, - usePic, executionRequirements, getActionName(), ruleContext); @@ -400,6 +398,10 @@ public class CppCompileActionBuilder { return this; } + Artifact getOutputFile() { + return outputFile; + } + /** * The temp output file is not an artifact, since it does not appear in the outputs of the * action. diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index c9085971c9..957851256d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -692,6 +692,27 @@ public class CppConfiguration extends BuildConfiguration.Fragment { return toolchain; } try { + if (!features.contains("random_seed")) { + // GCC and Clang give randomized names to symbols which are defined in + // an anonymous namespace but have external linkage. To make + // computation of these deterministic, we want to override the + // default seed for the random number generator. It's safe to use + // any value which differs for all translation units; we use the + // path to the object file. + TextFormat.merge("" + + "feature {" + + " name: 'random_seed'" + + " flag_set {" + + " action: 'c++-compile'" + + " action: 'c++-module-compile'" + + " flag_group {" + + " flag: '-frandom-seed=%{output_file}'" + + " }" + + " }" + + "}", + toolchainBuilder); + } + if (!features.contains("pic")) { TextFormat.merge("" + "feature {" diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java index c4b490e8e5..76e49c40e9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java @@ -363,6 +363,8 @@ public final class CppModel { CppCompilationContext builderContext = builder.getContext(); CppModuleMap cppModuleMap = builderContext.getCppModuleMap(); + buildVariables.addVariable("output_file", builder.getOutputFile().getExecPathString()); + 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. @@ -831,24 +833,25 @@ public final class CppModel { String iExt = isCFile ? ".i" : ".ii"; String picExt = usePic ? ".pic" : ""; - CppCompileActionBuilder dBuilder = new CppCompileActionBuilder(builder); - setupBuildVariables(dBuilder, usePic, ccRelativeName, source.getExecPath(), null); - CppCompileActionBuilder sdBuilder = new CppCompileActionBuilder(builder); - setupBuildVariables(sdBuilder, usePic, ccRelativeName, source.getExecPath(), null); + CppCompileActionBuilder dBuilder = new CppCompileActionBuilder(builder); dBuilder .setOutputFile(ruleContext.getRelatedArtifact(outputName, picExt + iExt)) .setDotdFile(outputName, picExt + iExt + ".d"); + setupBuildVariables(dBuilder, usePic, ccRelativeName, source.getExecPath(), null); semantics.finalizeCompileActionBuilder(ruleContext, dBuilder); CppCompileAction dAction = dBuilder.build(); ruleContext.registerAction(dAction); + CppCompileActionBuilder sdBuilder = new CppCompileActionBuilder(builder); sdBuilder .setOutputFile(ruleContext.getRelatedArtifact(outputName, picExt + ".s")) .setDotdFile(outputName, picExt + ".s.d"); + setupBuildVariables(sdBuilder, usePic, ccRelativeName, source.getExecPath(), null); semantics.finalizeCompileActionBuilder(ruleContext, sdBuilder); CppCompileAction sdAction = sdBuilder.build(); ruleContext.registerAction(sdAction); + return ImmutableList.of( dAction.getOutputFile(), sdAction.getOutputFile()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java index eca4a6d189..81c7fb8384 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java @@ -96,6 +96,12 @@ public class CppRuleClasses { public static final String MODULE_MAPS = "module_maps"; /** + * A string constant for the random_seed feature. This is used by gcc and Clangfor the + * randomization of symbol names that are in the anonymous namespace but have external linkage. + */ + public static final String RANDOM_SEED = "random_seed"; + + /** * A string constant for the module_map_home_cwd feature. */ public static final String MODULE_MAP_HOME_CWD = "module_map_home_cwd"; 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 644b16b409..a548ca30de 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 @@ -76,8 +76,7 @@ public class FakeCppCompileAction extends CppCompileAction { Class<? extends CppCompileActionContext> actionContext, ImmutableList<String> copts, Predicate<String> nocopts, - RuleContext ruleContext, - boolean usePic) { + RuleContext ruleContext) { super( owner, features, @@ -108,7 +107,6 @@ public class FakeCppCompileAction extends CppCompileAction { VOID_SPECIAL_INPUTS_HANDLER, ImmutableList.<IncludeScannable>of(), GUID, - usePic, ImmutableSet.<String>of(), CppCompileAction.CPP_COMPILE, ruleContext); |