Skip to content

Commit 094a0aa

Browse files
keithcopybara-github
authored andcommitted
Accept tildes in --override_module
This is useful for adding this in your global ~/.bazelrc file for easy rules debugging. See also bazelbuild#15417 Closes bazelbuild#17218. PiperOrigin-RevId: 502854597 Change-Id: Ic26289c6497edd31187dde2c7cda78c2177a56c4
1 parent e8ff51f commit 094a0aa

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptions.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,12 @@ public ModuleOverride convert(String input) throws OptionsParsingException {
350350
OptionsUtils.AbsolutePathFragmentConverter absolutePathFragmentConverter =
351351
new OptionsUtils.AbsolutePathFragmentConverter();
352352
try {
353-
var unused = absolutePathFragmentConverter.convert(pieces[1]);
353+
var path = absolutePathFragmentConverter.convert(pieces[1]);
354+
return ModuleOverride.create(pieces[0], path.toString());
354355
} catch (OptionsParsingException e) {
355356
throw new OptionsParsingException(
356357
"Module override directory must be an absolute path", input, e);
357358
}
358-
return ModuleOverride.create(pieces[0], pieces[1]);
359359
}
360360

361361
@Override

src/test/java/com/google/devtools/build/lib/bazel/repository/RepositoryOptionsTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import static com.google.common.base.StandardSystemProperty.USER_HOME;
1818
import static com.google.common.truth.Truth.assertThat;
1919

20+
import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.ModuleOverride;
21+
import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.ModuleOverrideConverter;
2022
import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.RepositoryOverride;
2123
import com.google.devtools.build.lib.bazel.repository.RepositoryOptions.RepositoryOverrideConverter;
2224
import com.google.devtools.build.lib.cmdline.RepositoryName;
@@ -60,6 +62,14 @@ public void testOverridePathWithTilde() throws Exception {
6062
assertThat(actual.path()).isEqualTo(PathFragment.create(USER_HOME.value() + "/bar"));
6163
}
6264

65+
@Test
66+
public void testModuleOverridePathWithTilde() throws Exception {
67+
var converter = new ModuleOverrideConverter();
68+
ModuleOverride actual = converter.convert("foo=~/bar");
69+
assertThat(PathFragment.create(actual.path()))
70+
.isEqualTo(PathFragment.create(USER_HOME.value() + "/bar"));
71+
}
72+
6373
@Test
6474
public void testInvalidOverride() throws Exception {
6575
expectedException.expect(OptionsParsingException.class);

0 commit comments

Comments
 (0)