Create "internal" category of command-line options.
This is intended to be used for "flags" which should never appear on the
command line - things like configuration distinguishers, which are used
internally and must be part of the build options, but should always be set
to their default value at the top level.
This is already a convention within Bazel, but doesn't actually work the way
Bazel expects - flags with spaces can be set by simply escaping or quoting
the spaces so that word splitting will not break on them. This means they
can also be matched by config_settings, which pass a single string.
Forbidding the parser from matching these flags solves both of these
unintended cases.
Existing cases like this have also been converted to internal.
--
PiperOrigin-RevId: 150497246
MOS_MIGRATED_REVID=150497246
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
index 28ce907..3bf92ec 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.analysis;
import static com.google.common.truth.Truth.assertThat;
+import static com.google.common.truth.Truth.assertWithMessage;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertEventCount;
import static com.google.devtools.build.lib.testutil.MoreAsserts.assertEventCountAtLeast;
import static org.junit.Assert.assertEquals;
@@ -37,6 +38,7 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.FailAction;
import com.google.devtools.build.lib.analysis.BuildView.AnalysisResult;
+import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
import com.google.devtools.build.lib.analysis.config.ConfigurationFactory;
import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException;
import com.google.devtools.build.lib.analysis.util.AnalysisMock;
@@ -59,6 +61,8 @@
import com.google.devtools.build.skyframe.NotifyingHelper.Order;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.TrackingAwaiter;
+import com.google.devtools.common.options.Options;
+import com.google.devtools.common.options.OptionsParsingException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
@@ -384,20 +388,24 @@
}
/**
- * Tests that the {@code --configuration short name} option cannot be used on
+ * Tests that the {@code --output directory name} option cannot be used on
* the command line.
*/
@Test
public void testConfigurationShortName() throws Exception {
- useConfiguration("--output directory name=foo");
- reporter.removeHandler(failFastHandler);
+ // Check that output directory name is still the name, otherwise this test is not testing what
+ // we expect.
+ BuildConfiguration.Options options = Options.getDefaults(BuildConfiguration.Options.class);
+ options.outputDirectoryName = "/home/wonkaw/wonka_chocolate/factory/out";
+ assertWithMessage("The flag's name may have been changed; this test may need to be updated.")
+ .that(options.asMap().get("output directory name"))
+ .isEqualTo("/home/wonkaw/wonka_chocolate/factory/out");
+
try {
- update(defaultFlags());
+ useConfiguration("--output directory name=foo");
fail();
- } catch (InvalidConfigurationException e) {
- assertThat(e).hasMessage("Build options are invalid");
- assertContainsEvent(
- "The internal '--output directory name' option cannot be used on the command line");
+ } catch (OptionsParsingException e) {
+ assertThat(e).hasMessage("Unrecognized option: --output directory name=foo");
}
}