Skip to content

Commit

Permalink
Apply tar remap_paths to runfiles full paths (bazelbuild#812)
Browse files Browse the repository at this point in the history
  • Loading branch information
dieortin authored Feb 1, 2024
1 parent 1cbb70d commit 3a2508f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/private/pkg_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,11 @@ def add_from_default_info(
# the executable, but that is not always obvious. When in doubt,
# the first file of DefaultInfo.files should be the right target.
base_file = the_executable or all_files[0]
base_file_path = mapping_context.path_mapper(
dest_path(base_file, data_path, data_path_without_prefix))
base_file_path = dest_path(base_file, data_path, data_path_without_prefix)
base_path = base_file_path + ".runfiles"

for rf in runfiles.files.to_list():
d_path = base_path + "/" + rf.short_path
d_path = mapping_context.path_mapper(base_path + "/" + rf.short_path)
fmode = "0755" if rf == the_executable else mapping_context.default_mode
_check_dest(mapping_context.content_map, d_path, rf, src.label, mapping_context.allow_duplicates_with_different_content)
mapping_context.content_map[d_path] = _DestFile(
Expand Down
78 changes: 78 additions & 0 deletions tests/tar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,84 @@ verify_archive_test(
}),
)

pkg_tar(
name = "test-tar-remap-runfiles-base-path",
srcs = [
":a_program",
"//tests:an_executable",
],
include_runfiles = True,
remap_paths = {
"/a_program": "/new_name",
"/an_executable": "/other/different_name",
},
)

verify_archive_test(
name = "runfiles_remap_base_path_test",
must_contain = [
"new_name",
"new_name.runfiles/tests/tar/BUILD",
"executable.sh",
] + select({
"@platforms//os:windows": [
"other/different_name.exe",
"other/different_name.exe.runfiles/tests/foo.cc",
"other/different_name.exe.runfiles/tests/an_executable.exe",
"other/different_name.exe.runfiles/tests/testdata/hello.txt",
],
"//conditions:default": [
"other/different_name",
"other/different_name.runfiles/tests/foo.cc",
"other/different_name.runfiles/tests/an_executable",
"other/different_name.runfiles/tests/testdata/hello.txt",
],
}),
target = ":test-tar-remap-runfiles-base-path",
)

pkg_tar(
name = "test-tar-remap-runfiles-full-paths",
srcs = [
":a_program",
"//tests:an_executable",
],
include_runfiles = True,
remap_paths = {
# rename the entire runfiles directory
"/a_program.runfiles/": "/a/program/runfiles/",
# rename a specific file
"/an_executable.runfiles/tests/testdata/hello.txt": "/myfiles/hello.txt",
"/an_executable.exe.runfiles/tests/testdata/hello.txt": "/myfiles/hello.txt",
# rename a specific subdirectory
"/an_executable.runfiles/tests/": "/mytests/",
"/an_executable.exe.runfiles/tests/": "/mytests/",
},
)

verify_archive_test(
name = "runfiles_remap_full_paths_test",
must_contain = [
"a_program",
"a/program/runfiles/tests/tar/BUILD",
"executable.sh",
] + select({
"@platforms//os:windows": [
"an_executable.exe",
"mytests/foo.cc",
"mytests/an_executable.exe",
"myfiles/hello.txt",
],
"//conditions:default": [
"an_executable",
"mytests/foo.cc",
"mytests/an_executable",
"myfiles/hello.txt",
],
}),
target = ":test-tar-remap-runfiles-full-paths",
)

pkg_tar(
name = "test_tar_leading_dotslash",
srcs = [
Expand Down

0 comments on commit 3a2508f

Please sign in to comment.