diff --git a/tools/bash/runfiles/runfiles.bash b/tools/bash/runfiles/runfiles.bash index 6607317c759ab8..540eb90d21461d 100644 --- a/tools/bash/runfiles/runfiles.bash +++ b/tools/bash/runfiles/runfiles.bash @@ -142,7 +142,10 @@ function rlocation() { if [[ -f "$RUNFILES_REPO_MAPPING" ]]; then local -r target_repo_apparent_name=$(echo "$1" | cut -d / -f 1) - local -r remainder=$(echo "$1" | cut -d / -f 2-) + # Use -s to get an empty remainder if the argument does not contain a slash. + # The repo mapping should not be applied to single segment paths, which may + # be root symlinks. + local -r remainder=$(echo "$1" | cut -s -d / -f 2-) if [[ -n "$remainder" ]]; then if [[ -z "${2+x}" ]]; then local -r source_repo=$(runfiles_current_repository 2) diff --git a/tools/bash/runfiles/runfiles_test.bash b/tools/bash/runfiles/runfiles_test.bash index 1e1c096b29e9cd..d9c384787a9462 100755 --- a/tools/bash/runfiles/runfiles_test.bash +++ b/tools/bash/runfiles/runfiles_test.bash @@ -216,10 +216,12 @@ function test_directory_based_runfiles_with_repo_mapping_from_main() { export RUNFILES_DIR=${tmpdir}/mock/runfiles mkdir -p "$RUNFILES_DIR" cat > "$RUNFILES_DIR/_repo_mapping" < "$RUNFILES_DIR/_repo_mapping" < "$tmpdir/foo.repo_mapping" < "$tmpdir/foo.repo_mapping" < rm(MockFile::Create( - "foo" + uid + ".repo_mapping", - {",my_module,_main", ",my_protobuf,protobuf~3.19.2", - ",my_workspace,_main", "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); + unique_ptr rm( + MockFile::Create("foo" + uid + ".repo_mapping", + {",config.json,config.json~1.2.3", ",my_module,_main", + ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", + "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); ASSERT_TRUE(rm != nullptr); unique_ptr mf(MockFile::Create( "foo" + uid + ".runfiles_manifest", @@ -644,10 +646,12 @@ TEST_F(RunfilesTest, ManifestBasedRlocationWithRepoMapping_fromMain) { TEST_F(RunfilesTest, ManifestBasedRlocationWithRepoMapping_fromOtherRepo) { string uid = LINE_AS_STRING(); - unique_ptr rm(MockFile::Create( - "foo" + uid + ".repo_mapping", - {",my_module,_main", ",my_protobuf,protobuf~3.19.2", - ",my_workspace,_main", "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); + unique_ptr rm( + MockFile::Create("foo" + uid + ".repo_mapping", + {",config.json,config.json~1.2.3", ",my_module,_main", + ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", + "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); ASSERT_TRUE(rm != nullptr); unique_ptr mf(MockFile::Create( "foo" + uid + ".runfiles_manifest", @@ -699,10 +703,12 @@ TEST_F(RunfilesTest, ManifestBasedRlocationWithRepoMapping_fromOtherRepo) { TEST_F(RunfilesTest, DirectoryBasedRlocationWithRepoMapping_fromMain) { string uid = LINE_AS_STRING(); - unique_ptr rm(MockFile::Create( - "foo" + uid + ".runfiles/_repo_mapping", - {",my_module,_main", ",my_protobuf,protobuf~3.19.2", - ",my_workspace,_main", "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); + unique_ptr rm( + MockFile::Create("foo" + uid + ".runfiles/_repo_mapping", + {",config.json,config.json~1.2.3", ",my_module,_main", + ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", + "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); ASSERT_TRUE(rm != nullptr); string dir = rm->DirName(); string argv0(dir.substr(0, dir.size() - string(".runfiles").size())); @@ -746,10 +752,12 @@ TEST_F(RunfilesTest, DirectoryBasedRlocationWithRepoMapping_fromMain) { TEST_F(RunfilesTest, DirectoryBasedRlocationWithRepoMapping_fromOtherRepo) { string uid = LINE_AS_STRING(); - unique_ptr rm(MockFile::Create( - "foo" + uid + ".runfiles/_repo_mapping", - {",my_module,_main", ",my_protobuf,protobuf~3.19.2", - ",my_workspace,_main", "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); + unique_ptr rm( + MockFile::Create("foo" + uid + ".runfiles/_repo_mapping", + {",config.json,config.json~1.2.3", ",my_module,_main", + ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", + "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); ASSERT_TRUE(rm != nullptr); string dir = rm->DirName(); string argv0(dir.substr(0, dir.size() - string(".runfiles").size())); @@ -790,10 +798,12 @@ TEST_F(RunfilesTest, DirectoryBasedRlocationWithRepoMapping_fromOtherRepo) { TEST_F(RunfilesTest, DirectoryBasedRlocationWithRepoMapping_fromOtherRepo_withSourceRepo) { string uid = LINE_AS_STRING(); - unique_ptr rm(MockFile::Create( - "foo" + uid + ".runfiles/_repo_mapping", - {",my_module,_main", ",my_protobuf,protobuf~3.19.2", - ",my_workspace,_main", "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); + unique_ptr rm( + MockFile::Create("foo" + uid + ".runfiles/_repo_mapping", + {",config.json,config.json~1.2.3", ",my_module,_main", + ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", + "protobuf~3.19.2,protobuf,protobuf~3.19.2"})); ASSERT_TRUE(rm != nullptr); string dir = rm->DirName(); string argv0(dir.substr(0, dir.size() - string(".runfiles").size())); diff --git a/tools/java/runfiles/testing/RunfilesTest.java b/tools/java/runfiles/testing/RunfilesTest.java index 8b88ce28bd4e3d..92d420f77ce7bf 100644 --- a/tools/java/runfiles/testing/RunfilesTest.java +++ b/tools/java/runfiles/testing/RunfilesTest.java @@ -264,9 +264,11 @@ public void testManifestBasedRlocationWithRepoMapping_fromMain() throws Exceptio tempFile( "foo.repo_mapping", ImmutableList.of( + ",config.json,config.json~1.2.3", ",my_module,_main", ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", "protobuf~3.19.2,protobuf,protobuf~3.19.2")); Path mf = tempFile( @@ -318,9 +320,11 @@ public void testManifestBasedRlocationUnmapped() throws Exception { tempFile( "foo.repo_mapping", ImmutableList.of( + ",config.json,config.json~1.2.3", ",my_module,_main", ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", "protobuf~3.19.2,protobuf,protobuf~3.19.2")); Path mf = tempFile( @@ -367,9 +371,11 @@ public void testManifestBasedRlocationWithRepoMapping_fromOtherRepo() throws Exc tempFile( "foo.repo_mapping", ImmutableList.of( + ",config.json,config.json~1.2.3", ",my_module,_main", ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", "protobuf~3.19.2,protobuf,protobuf~3.19.2")); Path mf = tempFile( @@ -419,9 +425,11 @@ public void testDirectoryBasedRlocationWithRepoMapping_fromMain() throws Excepti tempFile( dir.resolve("_repo_mapping").toString(), ImmutableList.of( + ",config.json,config.json~1.2.3", ",my_module,_main", ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", "protobuf~3.19.2,protobuf,protobuf~3.19.2")); Runfiles r = Runfiles.createDirectoryBasedForTesting(dir.toString()).withSourceRepository(""); @@ -458,9 +466,11 @@ public void testDirectoryBasedRlocationUnmapped() throws Exception { tempFile( dir.resolve("_repo_mapping").toString(), ImmutableList.of( + ",config.json,config.json~1.2.3", ",my_module,_main", ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", "protobuf~3.19.2,protobuf,protobuf~3.19.2")); Runfiles r = Runfiles.createDirectoryBasedForTesting(dir.toString()).unmapped(); @@ -497,9 +507,11 @@ public void testDirectoryBasedRlocationWithRepoMapping_fromOtherRepo() throws Ex tempFile( dir.resolve("_repo_mapping").toString(), ImmutableList.of( + ",config.json,config.json~1.2.3", ",my_module,_main", ",my_protobuf,protobuf~3.19.2", ",my_workspace,_main", + "protobuf~3.19.2,config.json,config.json~1.2.3", "protobuf~3.19.2,protobuf,protobuf~3.19.2")); Runfiles r = Runfiles.createDirectoryBasedForTesting(dir.toString())