diff options
author | 2017-11-20 15:02:32 -0800 | |
---|---|---|
committer | 2017-11-20 15:04:45 -0800 | |
commit | 7c8ff9f10192d520a9165ceea2ac7dcd51c8eb2e (patch) | |
tree | 3997f3bbe2b5876d944c5888365e16a3c60ecef6 /src/main/java/com/google/devtools/build/lib | |
parent | 0b30976d6a075577e9a9fc9df37ee4e784bb0ebb (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BlazeOptionHandler.java | 18 |
1 files changed, 18 insertions, 0 deletions
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<String> configs = optionsParser.getOptions(CommonCommandOptions.class).configs; + Set<String> configSet = new HashSet<>(); + LinkedHashSet<String> 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<String> getExpansion( |