Skip to content

Commit 281e9ee

Browse files
Add an option to silence warnings about duplicate flags
1 parent bc663c5 commit 281e9ee

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ DetailedExitCode parseOptions(List<String> args, ExtendedEventHandler eventHandl
490490
// to improve the user experience, but not required for safety or correctness.
491491
optionsPolicyEnforcer.enforce(optionsParser, commandAnnotation.name());
492492
// Print warnings for odd options usage
493-
for (String warning : optionsParser.getWarnings()) {
493+
for (String warning : getFilteredWarnings(optionsParser)) {
494494
eventHandler.handle(Event.warn(warning));
495495
}
496496
CommonCommandOptions commonOptions = optionsParser.getOptions(CommonCommandOptions.class);
@@ -704,4 +704,20 @@ private static void partitionCommandLineArgs(
704704
}
705705
}
706706
}
707+
708+
public static ImmutableList<String> getFilteredWarnings(OptionsParser parser) {
709+
CommonCommandOptions commonOptions = parser.getOptions(CommonCommandOptions.class);
710+
Preconditions.checkNotNull(commonOptions,
711+
"getWarnings can only be called after options parsing");
712+
713+
ImmutableList.Builder<String> warnings = ImmutableList.<String>builder();
714+
for (String warning : parser.getWarnings()) {
715+
if (!commonOptions.reportDuplicateOptionsAndConfigs && warning.contains(
716+
"was expanded to from both")) {
717+
continue;
718+
}
719+
warnings.add(warning);
720+
}
721+
return warnings.build();
722+
}
707723
}

src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,14 @@ public String getTypeDescription() {
532532
+ " them.")
533533
public boolean heuristicallyDropNodes;
534534

535+
@Option(
536+
name = "snowflake_report_duplicate_options_and_configs",
537+
defaultValue = "true",
538+
documentationCategory = OptionDocumentationCategory.LOGGING,
539+
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
540+
help = "If enabled, reports flags and configs that were expanded multiple times as warnings.")
541+
public boolean reportDuplicateOptionsAndConfigs;
542+
535543
/** The option converter to check that the user can only specify legal profiler tasks. */
536544
public static class ProfilerTaskConverter extends EnumConverter<ProfilerTask> {
537545
public ProfilerTaskConverter() {

src/main/java/com/google/devtools/build/lib/runtime/ConfigExpander.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ static void expandConfigOptions(
150150

151151
// At this point, we've expanded everything, identify duplicates, if any, to warn about
152152
// re-application.
153-
List<String> configs = optionsParser.getOptions(CommonCommandOptions.class).configs;
153+
CommonCommandOptions commonOptions = optionsParser.getOptions(CommonCommandOptions.class);
154+
if (!commonOptions.reportDuplicateOptionsAndConfigs) {
155+
return;
156+
}
157+
List<String> configs = commonOptions.configs;
154158
Set<String> configSet = new HashSet<>();
155159
LinkedHashSet<String> duplicateConfigs = new LinkedHashSet<>();
156160
for (String configValue : configs) {

0 commit comments

Comments
 (0)