aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVinh Tran <vinhdaitran@google.com>2023-03-08 10:14:55 -0500
committerVinh Tran <vinhdaitran@google.com>2023-03-08 19:12:18 -0500
commit07fbb6f8d4f2e672b7fd10cb795c1e7be01813d6 (patch)
tree63bcc0e03f1bb11f1e93ab49bba81c42a4d83b96
parentac62362c8180259b48fc6611bc5ad894828e268e (diff)
downloadbazel-07fbb6f8d4f2e672b7fd10cb795c1e7be01813d6.tar.gz
Fix staging_dir_builder to also copy files' permission mode
When building staging_dir, the script used shutil.copyfile which only copy the file data. This makes Soong script like build/soong/scripts/gen_ndk_usedby_apex.sh not being able to find the executable artifacts. Using shutil.copy ensures the permission mode is copied over to the destination. Test: With this fix, diff in using.txt is reduced to just 1 line (ceilf@LIBC) Bug: 272004164 Change-Id: I2ed93a24245f363d1ebf05335528d68a35e21106
-rw-r--r--rules/staging_dir_builder.py5
-rwxr-xr-xrules/staging_dir_builder_test.sh17
2 files changed, 21 insertions, 1 deletions
diff --git a/rules/staging_dir_builder.py b/rules/staging_dir_builder.py
index a5bcee9e..dea82bf2 100644
--- a/rules/staging_dir_builder.py
+++ b/rules/staging_dir_builder.py
@@ -98,7 +98,10 @@ def build_staging_dir(file_mapping_path, staging_dir_path, command_argv):
path_in_bazel = os.readlink(path_in_bazel)
os.makedirs(os.path.dirname(path_in_staging_dir), exist_ok=True)
- shutil.copyfile(path_in_bazel, path_in_staging_dir, follow_symlinks=False)
+ # shutil.copy copies the file data and the file's permission mode
+ # file's permission mode is helpful for tools, such as build/soong/scripts/gen_ndk_usedby_apex.sh,
+ # that rely on the permission mode of the artifacts
+ shutil.copy(path_in_bazel, path_in_staging_dir, follow_symlinks=False)
result = subprocess.run(command_argv)
diff --git a/rules/staging_dir_builder_test.sh b/rules/staging_dir_builder_test.sh
index e3674596..578cbd48 100755
--- a/rules/staging_dir_builder_test.sh
+++ b/rules/staging_dir_builder_test.sh
@@ -52,7 +52,9 @@ trap cleanup ERR
# 5. a two-level sumlink without "execroot/__main__" in the path
# 6. a three-level symlink with "execroot/__main__" in the path
echo "test file1" > "${input_dir}/file1"
+chmod 755 "${input_dir}/file1"
echo "test file2" > "${input_dir}/file2"
+chmod 755 "${input_dir}/file2"
mkdir -p "${input_dir}/execroot/__main__"
ln -s "${input_dir}/file1" "${input_dir}/one_level_sym"
ln -s "${input_dir}/file2" "${input_dir}/execroot/__main__/middle_sym"
@@ -173,6 +175,21 @@ diff ${input_dir}/file2 ${output_dir}/dir5/two_level_sym_in_execroot
[ `readlink ${output_dir}/dir6/two_level_sym_not_in_execroot` = "${input_dir}/file1" ]
diff ${input_dir}/file2 ${output_dir}/dir7/three_level_sym_in_execroot
+input_perms="$(stat -c '%A' ${input_dir}/file1)"
+output_perms="$(stat -c '%A' ${staging_dir}/dir1/file1)"
+if [ ${input_perms} != ${output_perms} ]; then
+ echo "File permissions not matched!"
+ exit 1
+fi
+
+input_perms="$(stat -c '%A' ${input_dir}/file2)"
+output_perms="$(stat -c '%A' ${staging_dir}/dir5/two_level_sym_in_execroot)"
+if [ ${input_perms} != ${output_perms} ]; then
+ echo "File permissions not matched!"
+ exit 1
+fi
+
+
cleanup
echo "Passed for all test cases"