fix: Directory hidden files in write_source_file. (#860)
* Fix #667: Dir hidden files in write_source_file. Copy and manage hidden files starting with "." in write_source_files. Previously these files were not supported if they were in the top level of the directory to copy. * Add test and fix error messages from cp, chmod. * Also fix executable dir case. * Fix issue with copying directory rather than contents.
This commit is contained in:
parent
0cb85f693d
commit
3c0dbd5895
|
@ -201,7 +201,7 @@ fi"""]
|
||||||
|
|
||||||
if ctx.attr.executable:
|
if ctx.attr.executable:
|
||||||
executable_file = "chmod +x \"$out\""
|
executable_file = "chmod +x \"$out\""
|
||||||
executable_dir = "chmod -R +x \"$out\"/*"
|
executable_dir = "chmod -R +x \"$out\""
|
||||||
else:
|
else:
|
||||||
executable_file = "chmod -x \"$out\""
|
executable_file = "chmod -x \"$out\""
|
||||||
if is_macos:
|
if is_macos:
|
||||||
|
@ -209,7 +209,7 @@ fi"""]
|
||||||
executable_dir = "find \"$out\" -type f | xargs chmod -x"
|
executable_dir = "find \"$out\" -type f | xargs chmod -x"
|
||||||
else:
|
else:
|
||||||
# Remove execute/search bit recursively from files bit not directories: https://superuser.com/a/434418
|
# 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:
|
for in_path, out_path in paths:
|
||||||
contents.append("""
|
contents.append("""
|
||||||
|
@ -231,10 +231,10 @@ else
|
||||||
echo "Copying directory $in to $out in $PWD"
|
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
|
# 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
|
chmod -R ug+w "$out" > /dev/null 2>&1 || true
|
||||||
rm -Rf "$out"/*
|
rm -Rf "$out"/{{*,.[!.]*}}
|
||||||
mkdir -p "$out"
|
mkdir -p "$out"
|
||||||
cp -fRL "$in"/* "$out"
|
cp -fRL "$in"/. "$out"
|
||||||
chmod -R ug+w "$out"/*
|
chmod -R ug+w "$out"
|
||||||
{executable_dir}
|
{executable_dir}
|
||||||
fi
|
fi
|
||||||
""".format(
|
""".format(
|
||||||
|
|
|
@ -101,6 +101,19 @@ output_files(
|
||||||
target = ":g_h-desired",
|
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(
|
write_source_file_test(
|
||||||
name = "a_test",
|
name = "a_test",
|
||||||
in_file = ":a-desired",
|
in_file = ":a-desired",
|
||||||
|
@ -137,6 +150,12 @@ write_source_file_test(
|
||||||
out_file = "g.js",
|
out_file = "g.js",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
write_source_file(
|
||||||
|
name = "hidden_dir_test",
|
||||||
|
in_file = ":hidden_dir-desired",
|
||||||
|
out_file = "hidden_dir",
|
||||||
|
)
|
||||||
|
|
||||||
write_source_files(
|
write_source_files(
|
||||||
name = "macro_smoke_test",
|
name = "macro_smoke_test",
|
||||||
additional_update_targets = [
|
additional_update_targets = [
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
hidden file test
|
Loading…
Reference in New Issue