From 094a0aabed1e018e6503bc3ac844c8022b71a527 Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 18 Jan 2023 06:00:37 -0800 Subject: [PATCH] Accept tildes in --override_module This is useful for adding this in your global ~/.bazelrc file for easy rules debugging. See also https://github.com/bazelbuild/bazel/pull/15417 Closes #17218. PiperOrigin-RevId: 502854597 Change-Id: Ic26289c6497edd31187dde2c7cda78c2177a56c4 --- .../build/lib/bazel/repository/RepositoryOptions.java | 4 ++-- .../lib/bazel/repository/RepositoryOptionsTest.java | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java index 2e515fc7e46164..02f013fa014eb9 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java @@ -350,12 +350,12 @@ public ModuleOverride convert(String input) throws OptionsParsingException { OptionsUtils.AbsolutePathFragmentConverter absolutePathFragmentConverter = new OptionsUtils.AbsolutePathFragmentConverter(); try { - var unused = absolutePathFragmentConverter.convert(pieces[1]); + var path = absolutePathFragmentConverter.convert(pieces[1]); + return ModuleOverride.create(pieces[0], path.toString()); } catch (OptionsParsingException e) { throw new OptionsParsingException( "Module override directory must be an absolute path", input, e); } - return ModuleOverride.create(pieces[0], pieces[1]); } @Override diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptionsTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptionsTest.java index 478a09937f72c4..5de4cc8b5a8ec5 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptionsTest.java @@ -17,6 +17,8 @@ import static com.google.common.base.StandardSystemProperty.USER_HOME; import static com.google.common.truth.Truth.assertThat; +import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.ModuleOverride; +import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.ModuleOverrideConverter; import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.RepositoryOverride; import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.RepositoryOverrideConverter; import com.google.devtools.build.lib.cmdline.RepositoryName; @@ -60,6 +62,14 @@ public void testOverridePathWithTilde() throws Exception { assertThat(actual.path()).isEqualTo(PathFragment.create(USER_HOME.value() + "/bar")); } + @Test + public void testModuleOverridePathWithTilde() throws Exception { + var converter = new ModuleOverrideConverter(); + ModuleOverride actual = converter.convert("foo=~/bar"); + assertThat(PathFragment.create(actual.path())) + .isEqualTo(PathFragment.create(USER_HOME.value() + "/bar")); + } + @Test public void testInvalidOverride() throws Exception { expectedException.expect(OptionsParsingException.class);