Skip to content

Commit

Permalink
Accept tildes in --override_module
Browse files Browse the repository at this point in the history
This is useful for adding this in your global ~/.bazelrc file for easy rules debugging.

See also #15417

Closes #17218.

PiperOrigin-RevId: 502854597
Change-Id: Ic26289c6497edd31187dde2c7cda78c2177a56c4
  • Loading branch information
keith authored and hvadehra committed Feb 14, 2023
1 parent c4f6c36 commit 0d64ac0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0d64ac0

Please sign in to comment.