Add Skylark flags as common command options
This makes these flags accessible to all commands, including some that don't do anything with Skylark (e.g. canonicalize-flags). This leads to spammier help messages. But the benefit is that it allows them to appear on a "common" line in the .bazelrc.
Fixes #3538.
RELNOTES: Skylark-related options may now appear as "common" command options in the .bazelrc
PiperOrigin-RevId: 165620829
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandUtils.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandUtils.java
index 8e42ad8..5f57b73 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandUtils.java
@@ -17,6 +17,7 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
+import com.google.devtools.build.lib.syntax.SkylarkSemanticsOptions;
import com.google.devtools.build.lib.util.ResourceFileLoader;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsParser;
@@ -36,7 +37,7 @@
* Options classes used as startup options in Blaze core.
*/
private static final ImmutableList<Class<? extends OptionsBase>> DEFAULT_STARTUP_OPTIONS =
- ImmutableList.<Class<? extends OptionsBase>>of(
+ ImmutableList.of(
BlazeServerStartupOptions.class,
HostJvmStartupOptions.class);
@@ -44,7 +45,12 @@
* The set of option-classes that are common to all Blaze commands.
*/
private static final ImmutableList<Class<? extends OptionsBase>> COMMON_COMMAND_OPTIONS =
- ImmutableList.of(CommonCommandOptions.class, BlazeCommandEventHandler.Options.class);
+ ImmutableList.of(
+ BlazeCommandEventHandler.Options.class,
+ CommonCommandOptions.class,
+ // Skylark options aren't applicable to all commands, but making them a common option
+ // allows users to put them in the common section of the bazelrc. See issue #3538.
+ SkylarkSemanticsOptions.class);
private BlazeCommandUtils() {}
@@ -117,12 +123,12 @@
* names, names and syntax, and full description.
* @param productName the product name
*/
- public static final String expandHelpTopic(String topic, String help,
- Class<? extends BlazeCommand> commandClass,
- Collection<Class<? extends OptionsBase>> options,
- Map<String, String> categoryDescriptions,
- OptionsParser.HelpVerbosity helpVerbosity,
- String productName) {
+ public static String expandHelpTopic(String topic, String help,
+ Class<? extends BlazeCommand> commandClass,
+ Collection<Class<? extends OptionsBase>> options,
+ Map<String, String> categoryDescriptions,
+ OptionsParser.HelpVerbosity helpVerbosity,
+ String productName) {
OptionsParser parser = OptionsParser.newOptionsParser(options);
String template;