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 compatibility with --incompatible_sandbox_hermetic_tmp #1196

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions foreign_cc/private/framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ def cc_external_rule_impl(ctx, attrs):
outputs.libraries.shared_libraries +
outputs.libraries.interface_libraries
)
] + [
"##replace_all_symlinks## $$INSTALLDIR$$",
]

script_text = "\n".join([
Expand Down
12 changes: 12 additions & 0 deletions foreign_cc/private/framework/toolchains/commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ PLATFORM_COMMANDS = {
],
doc = "Replaces absolute path 'abs_path' inside 'dir_' with a placeholder value",
),
"replace_all_symlinks": _command_info(
arguments = [
_argument_info(
name = "dir",
data_type = type(""),
doc = "Directory to search recursively",
),
],
doc = (
"Replace all target symlinks within given directory recursively."
),
),
"replace_in_files": _command_info(
arguments = [
_argument_info(name = "dir_", data_type = type(""), doc = "Directory to search recursively"),
Expand Down
7 changes: 7 additions & 0 deletions foreign_cc/private/framework/toolchains/freebsd_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ if [[ -L "{file}" ]]; then
fi
""".format(file = file)

def replace_all_symlinks(dir):
return """\
find "{dir}" -type l -exec bash -c 'for i in "$@"; do cp -a --remove-destination "$(realpath "$i")" "$i"; done' bash "{{}}" +""".format(
dir = dir,
)

commands = struct(
assert_script_errors = assert_script_errors,
cat = cat,
Expand All @@ -296,6 +302,7 @@ commands = struct(
replace_in_files = replace_in_files,
replace_sandbox_paths = replace_sandbox_paths,
replace_symlink = replace_symlink,
replace_all_symlinks = replace_all_symlinks,
rm_rf = rm_rf,
script_extension = script_extension,
script_prelude = script_prelude,
Expand Down
7 changes: 7 additions & 0 deletions foreign_cc/private/framework/toolchains/linux_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ if [[ -L "{file}" ]]; then
fi
""".format(file = file)

def replace_all_symlinks(dir):
return """\
find "{dir}" -type l -exec bash -c 'for i in "$@"; do cp -a --remove-destination "$(realpath "$i")" "$i"; done' bash "{{}}" +""".format(
dir = dir,
)
Comment on lines +256 to +260

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if the previous repalce_symlink() function could be reused here. This is what I have in mind:

Suggested change
def replace_all_symlinks(dir):
return """\
find "{dir}" -type l -exec bash -c 'for i in "$@"; do cp -a --remove-destination "$(realpath "$i")" "$i"; done' bash "{{}}" +""".format(
dir = dir,
)
def replace_all_symlinks(dir):
return """\
find "{dir}" -type l -exec ##replace_symlink## "{{}}" \\;
""".format(dir = dir)

I am not a starlark expert though. So not sure of the syntax.


commands = struct(
assert_script_errors = assert_script_errors,
cat = cat,
Expand All @@ -278,6 +284,7 @@ commands = struct(
replace_in_files = replace_in_files,
replace_sandbox_paths = replace_sandbox_paths,
replace_symlink = replace_symlink,
replace_all_symlinks = replace_all_symlinks,
rm_rf = rm_rf,
script_extension = script_extension,
script_prelude = script_prelude,
Expand Down
16 changes: 16 additions & 0 deletions foreign_cc/private/framework/toolchains/macos_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,21 @@ if [[ -L "{file}" ]]; then
fi
""".format(file = file)

def replace_all_symlinks(dir):
return """\
function realpath() {{
local previous="$1"
local next=$(readlink "${{previous}}")
while [ -n "${{next}}" ]; do
previous="${{next}}"
next=$(readlink "${{previous}}")
done
echo "${{previous}}"
}}
find "{dir}" -type l -exec bash -c 'for i in "$@"; do cp -af "$(realpath "$i")" "$i"; done' bash "{{}}" +""".format(
dir = dir,
)

commands = struct(
assert_script_errors = assert_script_errors,
cat = cat,
Expand All @@ -291,6 +306,7 @@ commands = struct(
replace_in_files = replace_in_files,
replace_sandbox_paths = replace_sandbox_paths,
replace_symlink = replace_symlink,
replace_all_symlinks = replace_all_symlinks,
rm_rf = rm_rf,
script_extension = script_extension,
script_prelude = script_prelude,
Expand Down
7 changes: 7 additions & 0 deletions foreign_cc/private/framework/toolchains/windows_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ if [[ -L "{file}" ]]; then
fi
""".format(file = file)

def replace_all_symlinks(dir):
return """\
find "{dir}" -type l -exec bash -c 'for i in "$@"; do cp -a --remove-destination "$(realpath "$i")" "$i"; done' bash "{{}}" +""".format(
dir = dir,
)

commands = struct(
assert_script_errors = assert_script_errors,
cat = cat,
Expand All @@ -295,6 +301,7 @@ commands = struct(
replace_in_files = replace_in_files,
replace_sandbox_paths = replace_sandbox_paths,
replace_symlink = replace_symlink,
replace_all_symlinks = replace_all_symlinks,
rm_rf = rm_rf,
script_extension = script_extension,
script_prelude = script_prelude,
Expand Down