Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Directory hidden files in write_source_file. #860

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/private/write_source_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ fi"""]

if ctx.attr.executable:
executable_file = "chmod +x \"$out\""
executable_dir = "chmod -R +x \"$out\"/*"
executable_dir = "chmod -R +x \"$out\""
jgiles marked this conversation as resolved.
Show resolved Hide resolved
else:
executable_file = "chmod -x \"$out\""
if is_macos:
# -x+X doesn't work on macos so we have to find files and remove the execute bits only from those
executable_dir = "find \"$out\" -type f | xargs chmod -x"
else:
# Remove execute/search bit recursively from files bit not directories: https://superuser.com/a/434418
executable_dir = "chmod -R -x+X \"$out\"/*"
executable_dir = "chmod -R -x+X \"$out\""

for in_path, out_path in paths:
contents.append("""
Expand All @@ -231,10 +231,10 @@ else
echo "Copying directory $in to $out in $PWD"
# in case `cp` from previous command was terminated midway which can result in read-only files/dirs
chmod -R ug+w "$out" > /dev/null 2>&1 || true
rm -Rf "$out"/*
rm -Rf "$out"/{{*,.[!.]*}}
mkdir -p "$out"
cp -fRL "$in"/* "$out"
chmod -R ug+w "$out"/*
cp -fRL "$in"/. "$out"
chmod -R ug+w "$out"
{executable_dir}
fi
""".format(
Expand Down
19 changes: 19 additions & 0 deletions lib/tests/write_source_files/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ output_files(
target = ":g_h-desired",
)

genrule(
name = "hidden-contained",
outs = [".hidden"],
cmd = "echo 'hidden file test' > $@",
)

copy_to_directory(
name = "hidden_dir-desired",
srcs = [
":hidden-contained",
],
)

write_source_file_test(
name = "a_test",
in_file = ":a-desired",
Expand Down Expand Up @@ -137,6 +150,12 @@ write_source_file_test(
out_file = "g.js",
)

write_source_file(
name = "hidden_dir_test",
in_file = ":hidden_dir-desired",
out_file = "hidden_dir",
)

write_source_files(
name = "macro_smoke_test",
additional_update_targets = [
Expand Down
1 change: 1 addition & 0 deletions lib/tests/write_source_files/hidden_dir/.hidden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hidden file test