diff options
author | 2017-08-17 22:28:22 +0200 | |
---|---|---|
committer | 2017-08-18 09:02:02 +0200 | |
commit | 41655a9d68008ada3bb4dc5540c21badf25809ed (patch) | |
tree | 7e218d08cebc59db8af32f8706df77afa9da14ee | |
parent | f426544e67170d31b9d228ecf4cdc4b6ce1ba00d (diff) |
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
5 files changed, 16 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java index f7cd063717..9f9923d154 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/FetchCommand.java @@ -32,7 +32,6 @@ import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.runtime.commands.QueryCommand; -import com.google.devtools.build.lib.syntax.SkylarkSemanticsOptions; import com.google.devtools.build.lib.util.AbruptExitException; import com.google.devtools.build.lib.util.ExitCode; import com.google.devtools.common.options.OptionsParser; @@ -45,7 +44,6 @@ import java.io.IOException; @Command(name = FetchCommand.NAME, options = { PackageCacheOptions.class, - SkylarkSemanticsOptions.class, FetchOptions.class, }, help = "resource:fetch.txt", 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 8e42ad8f41..5f57b735bd 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.ImmutableList; 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 @@ public class BlazeCommandUtils { * 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 @@ public class BlazeCommandUtils { * 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 @@ public class BlazeCommandUtils { * 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; diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java index fb7b4d2f2e..5f8077f2e6 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java @@ -25,7 +25,6 @@ import com.google.devtools.build.lib.runtime.BlazeCommand; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; -import com.google.devtools.build.lib.syntax.SkylarkSemanticsOptions; import com.google.devtools.build.lib.util.ExitCode; import com.google.devtools.common.options.OptionsParser; import com.google.devtools.common.options.OptionsProvider; @@ -41,7 +40,6 @@ import java.util.List; ExecutionOptions.class, LocalExecutionOptions.class, PackageCacheOptions.class, - SkylarkSemanticsOptions.class, BuildView.Options.class, LoadingOptions.class, }, diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java index 879806de79..ec8ae85db4 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java @@ -39,7 +39,6 @@ import com.google.devtools.build.lib.runtime.BlazeCommand; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; -import com.google.devtools.build.lib.syntax.SkylarkSemanticsOptions; import com.google.devtools.build.lib.util.AbruptExitException; import com.google.devtools.build.lib.util.ExitCode; import com.google.devtools.build.lib.vfs.FileSystemUtils; @@ -58,7 +57,6 @@ import java.util.Set; */ @Command(name = "query", options = { PackageCacheOptions.class, - SkylarkSemanticsOptions.class, QueryOptions.class }, help = "resource:query.txt", shortDescription = "Executes a dependency graph query.", diff --git a/src/test/java/com/google/devtools/build/lib/runtime/AbstractCommandTest.java b/src/test/java/com/google/devtools/build/lib/runtime/AbstractCommandTest.java index 14731206b6..7f8c8a1907 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/AbstractCommandTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/AbstractCommandTest.java @@ -17,6 +17,7 @@ import static com.google.common.truth.Truth.assertThat; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider; +import com.google.devtools.build.lib.syntax.SkylarkSemanticsOptions; import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.util.ExitCode; import com.google.devtools.common.options.Option; @@ -137,6 +138,7 @@ public class AbstractCommandTest { Collections.addAll(result, optionClasses); result.add(BlazeCommandEventHandler.Options.class); result.add(CommonCommandOptions.class); + result.add(SkylarkSemanticsOptions.class); return result; } } |