From f76eae6d24cb40decef892b5223ff5ff287e382e Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Fri, 13 Jan 2023 15:33:04 -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 --- .../build/lib/bazel/repository/RepositoryOptions.java | 4 ++-- .../build/lib/bazel/repository/RepositoryOptionsTest.java | 7 +++++++ 2 files changed, 9 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..01729fc80b5098 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 @@ -60,6 +60,13 @@ public void testOverridePathWithTilde() throws Exception { assertThat(actual.path()).isEqualTo(PathFragment.create(USER_HOME.value() + "/bar")); } + @Test + public void testModuleOverridePathWithTilde() throws Exception { + RepositoryOverride actual = converter.convert("foo=~/bar"); + assertThat(actual.repositoryName()).isEqualTo(RepositoryName.createUnvalidated("foo")); + assertThat(actual.path()).isEqualTo(PathFragment.create(USER_HOME.value() + "/bar")); + } + @Test public void testInvalidOverride() throws Exception { expectedException.expect(OptionsParsingException.class);