Add integration test for --all_incompatible_changes flag conflicts

This adds a new warning when the same flag is expanded to by multiple expansion flags. This extends an existing suite of warnings, e.g. for when an expansion flag conflicts with an explicit option.

The blaze canonicalize-flags command now takes a new flag --show_warnings. This flag causes any warnings encountered while parsing the given command line to be printed to stderr.

RELNOTES: blaze canonicalize-flags now takes a --show_warnings flag

PiperOrigin-RevId: 152186672

GitOrigin-RevId: e11775c2394fc48ac7fe5b632b47ae952dd552b4
Change-Id: Id14310d27000d5c7cbe6fe4ec236c3591b9ff1be
diff --git a/java/com/google/devtools/common/options/OptionsParserImpl.java b/java/com/google/devtools/common/options/OptionsParserImpl.java
index 94702c9..fd3a8ce 100644
--- a/java/com/google/devtools/common/options/OptionsParserImpl.java
+++ b/java/com/google/devtools/common/options/OptionsParserImpl.java
@@ -296,6 +296,15 @@
           // Create a warning if an expansion option overrides an explicit option:
           warnings.add("The option '" + expandedFrom + "' was expanded and now overrides a "
               + "previous explicitly specified option '" + name + "'");
+        } else if ((entry.getExpansionParent() != null) && (expandedFrom != null)) {
+          warnings.add(
+              "The option '"
+                  + name
+                  + "' was expanded to from both options '"
+                  + entry.getExpansionParent()
+                  + "' and '"
+                  + expandedFrom
+                  + "'");
         }
 
         // Record the new value:
@@ -633,6 +642,8 @@
       field = optionsData.getFieldFromName(name);
 
       // Look for a "no"-prefixed option name: "no<optionName>" or "no_<optionName>".
+      // Note: It is impossible to specify "--no_foo" for a flag named "--_foo", since that'll be
+      // interpreted as the "no_" negating prefix for "--foo".
       if (field == null && name.startsWith("no")) {
         name = name.substring(name.startsWith("no_") ? 3 : 2);
         field = optionsData.getFieldFromName(name);