From 0f30bf96b79cf57bbe3553503d0bd33f4d734f3b Mon Sep 17 00:00:00 2001 From: Jason Bedard Date: Wed, 6 Apr 2022 11:25:17 -0700 Subject: [PATCH] fix(write_source_files): fix nested directories (#65) --- ...write_source_files_subdir_multiple_runs.sh | 9 ++++ e2e/write_source_files_symlinks.sh | 18 ++++++++ lib/private/write_source_file.bzl | 7 ++-- lib/tests/write_source_files/.gitignore | 4 +- lib/tests/write_source_files/BUILD.bazel | 41 +++++++++++++++++++ 5 files changed, 75 insertions(+), 4 deletions(-) create mode 100755 e2e/write_source_files_subdir_multiple_runs.sh create mode 100755 e2e/write_source_files_symlinks.sh diff --git a/e2e/write_source_files_subdir_multiple_runs.sh b/e2e/write_source_files_subdir_multiple_runs.sh new file mode 100755 index 0000000..5ec7048 --- /dev/null +++ b/e2e/write_source_files_subdir_multiple_runs.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +bazel run //lib/tests/write_source_files:write_subdir +[ -e lib/tests/write_source_files/subdir_test/a/b/c/test.txt ] + +bazel run //lib/tests/write_source_files:write_subdir +[ -e lib/tests/write_source_files/subdir_test/a/b/c/test.txt ] diff --git a/e2e/write_source_files_symlinks.sh b/e2e/write_source_files_symlinks.sh new file mode 100755 index 0000000..7b4dde7 --- /dev/null +++ b/e2e/write_source_files_symlinks.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +bazel run //lib/tests/write_source_files:write_symlinks + +# Ensure exists +[ -e lib/tests/write_source_files/symlink_test/a/test.txt ] +[ -e lib/tests/write_source_files/symlink_test/b/test.txt ] + +# Exit if any symlinks +if [ -L lib/tests/write_source_files/symlink_test/a/test.txt ]; then + exit 1 +fi + +if [ -L lib/tests/write_source_files/symlink_test/b/test.txt ]; then + exit 1 +fi diff --git a/lib/private/write_source_file.bzl b/lib/private/write_source_file.bzl index 71522fb..006c702 100644 --- a/lib/private/write_source_file.bzl +++ b/lib/private/write_source_file.bzl @@ -164,11 +164,12 @@ echo "Copying $in to $out in $PWD" if [[ -f "$in" ]]; then cp -f "$in" "$out" - chmod 664 "$out" + chmod ug+w "$out" else + rm -Rf "$out"/* mkdir -p "$out" - cp -fR "$in"/* "$out" - chmod 664 "$out"/* + cp -fRL "$in"/* "$out" + chmod -R ug+w "$out"/* fi """.format(in_path = in_path, out_path = out_path)) diff --git a/lib/tests/write_source_files/.gitignore b/lib/tests/write_source_files/.gitignore index 7e2f1de..38bb718 100644 --- a/lib/tests/write_source_files/.gitignore +++ b/lib/tests/write_source_files/.gitignore @@ -1 +1,3 @@ -dist.js \ No newline at end of file +dist.js +subdir_test +symlink_test \ No newline at end of file diff --git a/lib/tests/write_source_files/BUILD.bazel b/lib/tests/write_source_files/BUILD.bazel index 167bad0..324b4d3 100644 --- a/lib/tests/write_source_files/BUILD.bazel +++ b/lib/tests/write_source_files/BUILD.bazel @@ -127,8 +127,49 @@ genrule( ) # ibazel run //lib/tests/write_source_files:write_dist +# See e2e/write_source_files_gitignored write_source_files( name = "write_dist", diff_test = False, files = {"dist.js": ":dist"}, ) + +# Generate a readonly file in nested readonly directories +genrule( + name = "subdir", + outs = ["subdir_test"], + cmd = ";".join([ + "mkdir -p $@/a/b/c", + "echo 'test' > $@/a/b/c/test.txt", + "chmod -R -w $@/*" + ]), +) + +# Write nested subdirectories to source +# See e2e/write_source_files_subdir_multiple_runs +write_source_files( + name = "write_subdir", + diff_test = False, + files = {"subdir_test": ":subdir"}, +) + + +# Generate some directories including symlinks +genrule( + name = "symlinks", + outs = ["symlink_test"], + cmd = ";".join([ + "mkdir -p $@/a $@/b", + "echo 'test' > $@/a/test.txt", + "pushd $@/b", + "ln -s ../a/test.txt", + ]), +) + +# Write symlinks to source +# See e2e/write_source_files_symlinks +write_source_files( + name = "write_symlinks", + diff_test = False, + files = {"symlink_test": ":symlinks"}, +) \ No newline at end of file