From 2ec58f60ae1732f4c1d09330c4583050ac8d1f46 Mon Sep 17 00:00:00 2001 From: juliexxia Date: Wed, 20 May 2020 06:31:17 -0700 Subject: [PATCH] Allow blaze info to ignore starlark options Fixes #11301 PiperOrigin-RevId: 312470710 --- .../lib/runtime/StarlarkOptionsParser.java | 19 +++++++++++++++++++ .../lib/runtime/commands/InfoCommand.java | 14 +++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/runtime/StarlarkOptionsParser.java b/src/main/java/com/google/devtools/build/lib/runtime/StarlarkOptionsParser.java index 0b38ed6f355934..949a82d2459ab1 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/StarlarkOptionsParser.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/StarlarkOptionsParser.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.runtime; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.devtools.build.lib.analysis.config.CoreOptionConverters.BUILD_SETTING_CONVERTERS; import static com.google.devtools.build.lib.packages.RuleClass.Builder.STARLARK_BUILD_SETTING_DEFAULT_ATTR_NAME; import static com.google.devtools.build.lib.packages.Type.BOOLEAN; @@ -216,6 +217,24 @@ private Target loadBuildSetting( return buildSetting; } + /** + * Separates out any Starlark options from the given list + * + * @param list List of strings from which to parse out starlark options + * @return Returns a pair of string lists. The first item contains the list of starlark options + * that were removed; the second contains the remaining string from the original list. + */ + public static Pair, ImmutableList> removeStarlarkOptions( + List list) { + ImmutableList removed = + list.stream() + .filter(r -> r.startsWith("--//") || r.startsWith("--no//")) + .collect(toImmutableList()); + ImmutableList kept = + list.stream().filter(r -> !removed.contains(r)).collect(toImmutableList()); + return Pair.of(removed, kept); + } + @VisibleForTesting public static StarlarkOptionsParser newStarlarkOptionsParserForTesting( SkyframeExecutor skyframeExecutor, diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java index cc9aead7200a1f..1e3620c7d1f4e0 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.runtime.InfoItem; +import com.google.devtools.build.lib.runtime.StarlarkOptionsParser; import com.google.devtools.build.lib.runtime.commands.info.BlazeBinInfoItem; import com.google.devtools.build.lib.runtime.commands.info.BlazeGenfilesInfoItem; import com.google.devtools.build.lib.runtime.commands.info.BlazeTestlogsInfoItem; @@ -64,6 +65,7 @@ import com.google.devtools.build.lib.util.DetailedExitCode; import com.google.devtools.build.lib.util.ExitCode; import com.google.devtools.build.lib.util.InterruptedFailureDetails; +import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.io.OutErr; import com.google.devtools.common.options.Option; import com.google.devtools.common.options.OptionDocumentationCategory; @@ -198,7 +200,17 @@ public BlazeCommandResult exec( } } - List residue = optionsParsingResult.getResidue(); + Pair, ImmutableList> starlarkOptionsAndResidue = + StarlarkOptionsParser.removeStarlarkOptions(optionsParsingResult.getResidue()); + ImmutableList removedStarlarkOptions = starlarkOptionsAndResidue.getFirst(); + ImmutableList residue = starlarkOptionsAndResidue.getSecond(); + if (!removedStarlarkOptions.isEmpty()) { + env.getReporter() + .handle( + Event.warn( + "Blaze info does not support starlark options. Ignoring options: " + + removedStarlarkOptions)); + } if (residue.size() > 1) { String message = "at most one key may be specified"; env.getReporter().handle(Event.error(message));