From c1125de0f9030d90d6c4fcaa0c1f2f1a61018416 Mon Sep 17 00:00:00 2001 From: ccalvarin Date: Fri, 6 Apr 2018 10:59:56 -0700 Subject: Disallow undefined configs by default. This brings it in line with other flags, where a malformed value is an error. RELNOTES(INC): --config=foo will error if no 'foo' config exists. PiperOrigin-RevId: 191910781 --- .../build/lib/runtime/CommonCommandOptions.java | 2 +- .../build/lib/runtime/BlazeOptionHandlerTest.java | 44 +++++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java index 4c37fab659..8d520e90cf 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/CommonCommandOptions.java @@ -107,7 +107,7 @@ public class CommonCommandOptions extends OptionsBase { @Option( name = "allow_undefined_configs", - defaultValue = "true", + defaultValue = "false", documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, effectTags = {OptionEffectTag.EAGERNESS_TO_EXIT}, help = "Do not throw an error when the config is not defined." diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BlazeOptionHandlerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BlazeOptionHandlerTest.java index 567499ca7d..d9454bcbbd 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/BlazeOptionHandlerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/BlazeOptionHandlerTest.java @@ -450,15 +450,47 @@ public class BlazeOptionHandlerTest { public void testExpandConfigOptions_withConfigForUnapplicableCommand_fixedPoint() throws Exception { makeFixedPointExpandingConfigOptionHandler(); + try { testExpandConfigOptions_withConfigForUnapplicableCommand(); + fail(); + } catch (OptionsParsingException e) { + assertThat(e) + .hasMessageThat() + .contains("Config values are not defined in any .rc file: other"); + } + } + + @Test + public void testExpandConfigOptions_withConfigForUnapplicableCommand_inPlace() throws Exception { + makeInPlaceExpandingConfigOptionHandler(); + try { + testExpandConfigOptions_withConfigForUnapplicableCommand(); + fail(); + } catch (OptionsParsingException e) { + assertThat(e).hasMessageThat().contains("Config value other is not defined in any .rc file"); + } + } + + private void testExpandConfigOptions_withConfigForUnapplicableCommand_allowUndefined() + throws Exception { + parser.parse("--config=other", "--allow_undefined_configs"); + optionHandler.expandConfigOptions(eventHandler, structuredArgsFrom2SimpleRcsWithOnlyResidue()); + } + + @Test + public void testExpandConfigOptions_withConfigForUnapplicableCommand_allowUndefined_fixedPoint() + throws Exception { + makeFixedPointExpandingConfigOptionHandler(); + testExpandConfigOptions_withConfigForUnapplicableCommand_allowUndefined(); assertThat(eventHandler.getEvents()) .contains(Event.warn("Config values are not defined in any .rc file: other")); } @Test - public void testExpandConfigOptions_withConfigForUnapplicableCommand_inPlace() throws Exception { + public void testExpandConfigOptions_withConfigForUnapplicableCommand_allowUndefined_inPlace() + throws Exception { makeInPlaceExpandingConfigOptionHandler(); - testExpandConfigOptions_withConfigForUnapplicableCommand(); + testExpandConfigOptions_withConfigForUnapplicableCommand_allowUndefined(); assertThat(eventHandler.getEvents()) .contains(Event.warn("Config value other is not defined in any .rc file")); } @@ -486,8 +518,8 @@ public class BlazeOptionHandlerTest { .contains(Event.warn("Config value invalid is not defined in any .rc file")); } - private void testNoAllowUndefinedConfig() throws OptionsParsingException { - parser.parse("--config=invalid", "--noallow_undefined_configs"); + private void testUndefinedConfig() throws OptionsParsingException { + parser.parse("--config=invalid"); optionHandler.expandConfigOptions(eventHandler, ArrayListMultimap.create()); } @@ -495,7 +527,7 @@ public class BlazeOptionHandlerTest { public void testNoAllowUndefinedConfig_fixedPoint() { makeFixedPointExpandingConfigOptionHandler(); try { - testNoAllowUndefinedConfig(); + testUndefinedConfig(); fail(); } catch (OptionsParsingException e) { assertThat(e) @@ -508,7 +540,7 @@ public class BlazeOptionHandlerTest { public void testNoAllowUndefinedConfig_inPlace() { makeInPlaceExpandingConfigOptionHandler(); try { - testNoAllowUndefinedConfig(); + testUndefinedConfig(); fail(); } catch (OptionsParsingException e) { assertThat(e) -- cgit v1.2.3