Apply tar remap_paths to runfiles full paths (#812)

This commit is contained in:
Diego Ortin 2024-02-01 15:06:29 +01:00 committed by GitHub
parent 1cbb70dfa2
commit 3a2508f9f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 80 additions and 3 deletions

View File

@ -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(

View File

@ -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 = [