From 7c8ff9f10192d520a9165ceea2ac7dcd51c8eb2e Mon Sep 17 00:00:00 2001 From: ccalvarin Date: Mon, 20 Nov 2017 15:02:32 -0800 Subject: Add warning for configs that are expanded multiple times. Some flags are relatively immune to repeated mentions, since only the last mention ends up mattering, but in some cases, the values are accumulated. Expanding the same config twice may lead to surprising results, so provide a friendly warning. RELNOTES: None PiperOrigin-RevId: 176422758 --- .../devtools/build/lib/runtime/BlazeOptionHandler.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/main/java/com') diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java index f2510a447e..436a96d25e 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java @@ -457,6 +457,24 @@ public abstract class BlazeOptionHandler { String.format("expanded from --%s", configValueToExpand), expansion); } + + // At this point, we've expanded everything, identify duplicates, if any, to warn about + // re-application. + List configs = optionsParser.getOptions(CommonCommandOptions.class).configs; + Set configSet = new HashSet<>(); + LinkedHashSet duplicateConfigs = new LinkedHashSet<>(); + for (String configValue : configs) { + if (!configSet.add(configValue)) { + duplicateConfigs.add(configValue); + } + } + if (!duplicateConfigs.isEmpty()) { + eventHandler.handle(Event.warn( + String.format( + "The following configs were expanded more than once: %s. For repeatable flags, " + + "repeats are counted twice and may lead to unexpected behavior.", + duplicateConfigs))); + } } private List getExpansion( -- cgit v1.2.3