Skip to content

Commit

Permalink
Accept tildes in --override_repository
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.

Closes bazelbuild#15417.

PiperOrigin-RevId: 460689663
Change-Id: I12206d24002e606f3769bb3faed0b73701ed5aad
  • Loading branch information
keith authored and aranguyen committed Jul 20, 2022
1 parent d14bdca commit 3c601dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,14 @@ public RepositoryOverride convert(String input) throws OptionsParsingException {
throw new OptionsParsingException(
"Repository overrides must be of the form 'repository-name=path'", input);
}
PathFragment path = PathFragment.create(pieces[1]);
if (!path.isAbsolute()) {
OptionsUtils.AbsolutePathFragmentConverter absolutePathFragmentConverter =
new OptionsUtils.AbsolutePathFragmentConverter();
PathFragment path;
try {
path = absolutePathFragmentConverter.convert(pieces[1]);
} catch (OptionsParsingException e) {
throw new OptionsParsingException(
"Repository override directory must be an absolute path", input);
"Repository override directory must be an absolute path", input, e);
}
try {
return RepositoryOverride.create(RepositoryName.create(pieces[0]), path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.google.devtools.build.lib.bazel.repository;

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.RepositoryOverride;
Expand Down Expand Up @@ -52,6 +53,13 @@ public void testOverridePathWithEqualsSign() throws Exception {
assertThat(actual.path()).isEqualTo(PathFragment.create("/bar=/baz"));
}

@Test
public void testOverridePathWithTilde() 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);
Expand Down

0 comments on commit 3c601dc

Please sign in to comment.