diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BazelStartupOptionsModule.java b/src/main/java/com/google/devtools/build/lib/bazel/BazelStartupOptionsModule.java index cc126829118ff8..fb67c4a01d6e9e 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/BazelStartupOptionsModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/BazelStartupOptionsModule.java @@ -33,13 +33,15 @@ public static final class Options extends OptionsBase { valueHelp = "", help = "The location of the user .bazelrc file containing default values of " - + "Bazel options. This option can also be specified multiple times.\n" + + "Bazel options. " + + "/dev/null indicates that all further `--bazelrc`s will be ignored, " + + "This is useful to disable the search for a user rc file, " + + "e.g. in release builds.\n" + + "This option can also be specified multiple times.\n" + "E.g. with " + "`--bazelrc=x.rc --bazelrc=y.rc --bazelrc=/dev/null --bazelrc=z.rc`,\n" - + " 1) x.rc and y.rc will be read.\n" - + " 2) /dev/null indicates that all further `--bazelrc`s will be ignored, " - + "so in this case z.rc will be ignored. This is useful " - + "to disable the search for a user rc file, e.g. in release builds.\n" + + " 1) x.rc and y.rc are read.\n" + + " 2) z.rc is ignored due to the prior /dev/null.\n" + "If unspecified, Bazel uses the first .bazelrc file it finds in " + "the following two locations: the workspace directory, then the user's home " + "directory.\n" diff --git a/src/test/cpp/blaze_util_test.cc b/src/test/cpp/blaze_util_test.cc index 866ba5068b324d..6aaee3665dca18 100644 --- a/src/test/cpp/blaze_util_test.cc +++ b/src/test/cpp/blaze_util_test.cc @@ -234,88 +234,270 @@ TEST_F(BlazeUtilTest, TestSearchUnaryCommandOptionWarnsAboutDuplicates) { } } -void assert_equal_vector_char_pointer(std::vector expected, std::vector actual) { - ASSERT_EQ(actual.size(), expected.size()) << "Vectors expected and actual are of unequal length"; +void assert_equal_vector_char_pointer(std::vector expected, + std::vector actual) { + ASSERT_EQ(actual.size(), expected.size()) + << "Vectors expected and actual are of unequal length"; for (int i = 0; i < actual.size(); ++i) { - ASSERT_EQ(actual[i], expected[i]) << "Vectors expected and actual differ at index " << i; + ASSERT_EQ(actual[i], expected[i]) + << "Vectors expected and actual differ at index " << i; } } TEST_F(BlazeUtilTest, TestSearchAllUnaryForEmpty) { - assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({"bazel", "build", ":target"}, "")); + assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({ + "bazel", + "build", + ":target" + }, "")); } TEST_F(BlazeUtilTest, TestSearchAllUnaryFlagNotPresent) { - assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({"bazel", "build", ":target"}, "--flag")); -} - -TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithEquals) { - assert_equal_vector_char_pointer({"value"}, GetAllUnaryOptionValues({"bazel", "--flag=value", "build", ":target"}, "--flag")); -} - -TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithEquals2) { - assert_equal_vector_char_pointer({"value1", "value2"}, GetAllUnaryOptionValues({"bazel", "--flag=value1", "--flag=value2", "build", ":target"}, "--flag")); -} - -TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithRepeatingFlag) { - assert_equal_vector_char_pointer({"--flag"}, GetAllUnaryOptionValues({"bazel", "--flag", "--flag", "value1", "build", ":target"}, "--flag")); -} - -TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithRepeatingFlagOptionsOnly) { - assert_equal_vector_char_pointer({"--flag"}, GetAllUnaryOptionValues({"bazel", "--flag", "--flag", "value1"}, "--flag")); -} - -TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithRepeatingFlagOptionsOnlyMulti) { - assert_equal_vector_char_pointer({"--flag", "value1"}, GetAllUnaryOptionValues({"bazel", "--flag", "--flag", "--flag", "value1"}, "--flag")); -} - -TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithRepeatingFlagOptionsOnlyMultiWithEquals) { - assert_equal_vector_char_pointer({"--flag", "value1"}, GetAllUnaryOptionValues({"bazel", "--flag=--flag", "--flag", "value1"}, "--flag")); -} - -TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithEquals3) { - assert_equal_vector_char_pointer({"value1", "value2", "value3"}, GetAllUnaryOptionValues({"bazel", "--flag=value1", "--flag=value2", "--flag=value3", "build", ":target"}, "--flag")); -} - -TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithoutEquals) { - assert_equal_vector_char_pointer({"value"}, GetAllUnaryOptionValues({"bazel", "--flag", "value", "build", ":target"}, "--flag")); -} - -TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithoutEquals2) { - assert_equal_vector_char_pointer({"value1", "value2"}, GetAllUnaryOptionValues({"bazel", "--flag", "value1", "--flag", "value2", "build", ":target"}, "--flag")); + assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({ + "bazel", + "build", + ":target" + }, "--flag")); +} + +TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithEquals) { + assert_equal_vector_char_pointer({ + "value" + }, + GetAllUnaryOptionValues({ + "bazel", + "--flag=value", + "build", + ":target" + }, "--flag") + ); +} + +TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithEquals2) { + assert_equal_vector_char_pointer({ + "value1", + "value2" + }, + GetAllUnaryOptionValues({ + "bazel", + "--flag=value1", + "--flag=value2", + "build", + ":target" + }, "--flag") + ); +} + +TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithRepeatingFlag) { + assert_equal_vector_char_pointer({ + "--flag" + }, + GetAllUnaryOptionValues({ + "bazel", + "--flag", + "--flag", + "value1", + "build", + ":target" + }, "--flag") + ); +} + +TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithRepeatingFlagOptions) { + assert_equal_vector_char_pointer({ + "--flag" + }, + GetAllUnaryOptionValues({ + "bazel", + "--flag", + "--flag", + "value1" + }, "--flag") + ); +} + +TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionValuesWithEquals) { + assert_equal_vector_char_pointer({ + "--flag", + "value1" + }, + GetAllUnaryOptionValues({ + "bazel", + "--flag=--flag", + "--flag", + "value1" + }, "--flag") + ); +} + +TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithEquals3) { + assert_equal_vector_char_pointer({ + "value1", + "value2", + "value3" + }, + GetAllUnaryOptionValues({ + "bazel", + "--flag=value1", + "--flag=value2", + "--flag=value3", + "build", + ":target" + }, "--flag") + ); +} + +TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithoutEquals) { + assert_equal_vector_char_pointer({ + "value" + }, + GetAllUnaryOptionValues({ + "bazel", + "--flag", + "value", + "build", + ":target" + }, "--flag") + ); +} + +TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithoutEquals2) { + assert_equal_vector_char_pointer({ + "value1", + "value2" + }, + GetAllUnaryOptionValues({ + "bazel", + "--flag", + "value1", + "--flag", + "value2", + "build", + ":target" + }, "--flag") + ); } TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithEquals) { - assert_equal_vector_char_pointer({"value"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag", "value"}, "--flag")); + assert_equal_vector_char_pointer({ + "value" + }, + GetAllUnaryOptionValues({ + "bazel", + "build", + ":target", + "--flag", + "value" + }, "--flag") + ); } TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithEquals2) { - assert_equal_vector_char_pointer({"value1","value2"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag", "value1", "--flag", "value2"}, "--flag")); + assert_equal_vector_char_pointer({ + "value1", + "value2" + }, + GetAllUnaryOptionValues({ + "bazel", + "build", + ":target", + "--flag", + "value1", + "--flag", + "value2" + }, "--flag") + ); } TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithoutEquals) { - assert_equal_vector_char_pointer({"value"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag=value"}, "--flag")); + assert_equal_vector_char_pointer({ + "value" + }, + GetAllUnaryOptionValues({ + "bazel", + "build", + ":target", + "--flag=value" + }, "--flag") + ); } TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithoutEquals2) { - assert_equal_vector_char_pointer({"value1", "value2"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag=value1", "--flag=value2"}, "--flag")); + assert_equal_vector_char_pointer({ + "value1", + "value2" + }, + GetAllUnaryOptionValues({ + "bazel", + "build", + ":target", + "--flag=value1", + "--flag=value2" + }, "--flag") + ); } TEST_F(BlazeUtilTest, TestSearchAllUnarySkipsAfterDashDashWithEquals) { - assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--", "--flag", "value"}, "--flag")); + assert_equal_vector_char_pointer({}, + GetAllUnaryOptionValues({ + "bazel", + "build", + ":target", + "--", + "--flag", + "value" + }, "--flag") + ); } TEST_F(BlazeUtilTest, TestSearchAllUnarySkipsAfterDashDashWithoutEquals) { - assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--", "--flag=value"}, "--flag")); + assert_equal_vector_char_pointer({}, + GetAllUnaryOptionValues({ + "bazel", + "build", + ":target", + "--", + "--flag=value" + }, "--flag") + ); } TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithIgnoreAfter) { - assert_equal_vector_char_pointer({"value1","/dev/null"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag", "value1", "--flag", "/dev/null", "--flag", "value3"}, "--flag", "/dev/null")); + assert_equal_vector_char_pointer({ + "value1", + "/dev/null" + }, + GetAllUnaryOptionValues({ + "bazel", + "build", + ":target", + "--flag", + "value1", + "--flag", + "/dev/null", + "--flag", + "value3" + }, "--flag", "/dev/null") + ); } TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithIgnoreAfterDevNull) { - assert_equal_vector_char_pointer({"/dev/null"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag", "/dev/null", "--flag", "value2", "--flag", "value3"}, "--flag", "/dev/null")); + assert_equal_vector_char_pointer({ + "/dev/null" + }, + GetAllUnaryOptionValues({ + "bazel", + "build", + ":target", + "--flag", + "/dev/null", + "--flag", + "value2", + "--flag", + "value3" + }, "--flag", "/dev/null") + ); } } // namespace blaze