-
Notifications
You must be signed in to change notification settings - Fork 249
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
Add specific shell command support for FreeBSD. #387
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
162 changes: 162 additions & 0 deletions
162
tools/build_defs/shell_toolchain/toolchains/impl/bsd_commands.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
load("@rules_foreign_cc//tools/build_defs/shell_toolchain/toolchains:function_and_call.bzl", "FunctionAndCall") | ||
|
||
_REPLACE_VALUE = "\${EXT_BUILD_DEPS}" | ||
|
||
def os_name(): | ||
return "bsd" | ||
|
||
def pwd(): | ||
return "$(pwd)" | ||
|
||
def echo(text): | ||
return "printf \"{text}\"".format(text = text) | ||
|
||
def export_var(name, value): | ||
return "export {name}={value}".format(name = name, value = value) | ||
|
||
def local_var(name, value): | ||
return "local {name}={value}".format(name = name, value = value) | ||
|
||
def use_var(name): | ||
return "$" + name | ||
|
||
def env(): | ||
return "env" | ||
|
||
def path(expression): | ||
return "export PATH=\"{expression}:$PATH\"".format(expression = expression) | ||
|
||
def touch(path): | ||
return "touch " + path | ||
|
||
def mkdirs(path): | ||
return "mkdir -p " + path | ||
|
||
def tmpdir(): | ||
return "$(mktemp -d)" | ||
|
||
def if_else(condition, if_text, else_text): | ||
return """ | ||
if [ {condition} ]; then | ||
{if_text} | ||
else | ||
{else_text} | ||
fi | ||
""".format(condition = condition, if_text = if_text, else_text = else_text) | ||
|
||
def define_function(name, text): | ||
lines = [] | ||
lines.append("function " + name + "() {") | ||
for line_ in text.splitlines(): | ||
lines.append(" " + line_) | ||
lines.append("}") | ||
return "\n".join(lines) | ||
|
||
def replace_in_files(dir, from_, to_): | ||
return FunctionAndCall( | ||
text = """if [ -d "$1" ]; then | ||
find -L $1 -type f \ | ||
\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \) \ | ||
-exec sed -i 's@'"$2"'@'"$3"'@g' {} ';' | ||
fi | ||
""", | ||
) | ||
|
||
def copy_dir_contents_to_dir(source, target): | ||
return """gcp -L -r --no-target-directory "{}" "{}" """.format(source, target) | ||
|
||
def symlink_contents_to_dir(source, target): | ||
text = """local target="$2" | ||
mkdir -p "$target" | ||
if [[ -f "$1" ]]; then | ||
##symlink_to_dir## "$1" "$target" | ||
elif [[ -L "$1" ]]; then | ||
local actual=$(readlink "$1") | ||
##symlink_contents_to_dir## "$actual" "$target" | ||
elif [[ -d "$1" ]]; then | ||
local children=$(find -H "$1" -maxdepth 1 -mindepth 1) | ||
for child in $children; do | ||
##symlink_to_dir## "$child" "$target" | ||
done | ||
fi | ||
""" | ||
return FunctionAndCall(text = text) | ||
|
||
def symlink_to_dir(source, target): | ||
text = """local target="$2" | ||
mkdir -p "$target" | ||
if [[ -f "$1" ]]; then | ||
gln -s -t "$target" "$1" | ||
elif [[ -L "$1" ]]; then | ||
gcp $1 $2 | ||
elif [[ -d "$1" ]]; then | ||
local children=$(find -H "$1" -maxdepth 1 -mindepth 1) | ||
local dirname=$(basename "$1") | ||
mkdir -p "$target/$dirname" | ||
for child in $children; do | ||
##symlink_to_dir## "$child" "$target/$dirname" | ||
done | ||
else | ||
echo "Can not copy $1" | ||
fi | ||
""" | ||
return FunctionAndCall(text = text) | ||
|
||
def script_prelude(): | ||
return "set -e" | ||
|
||
def increment_pkg_config_path(source): | ||
text = """local children=$(find $1 -mindepth 1 -name '*.pc') | ||
# assume there is only one directory with pkg config | ||
for child in $children; do | ||
export PKG_CONFIG_PATH="$$PKG_CONFIG_PATH$$:$(dirname $child)" | ||
return | ||
done | ||
""" | ||
return FunctionAndCall(text = text) | ||
|
||
def cat(filepath): | ||
return "cat \"{}\"".format(filepath) | ||
|
||
def redirect_out_err(from_process, to_file): | ||
return from_process + " &> " + to_file | ||
|
||
def assert_script_errors(): | ||
return "set -e" | ||
|
||
def cleanup_function(on_success, on_failure): | ||
text = "\n".join([ | ||
"local ecode=$?", | ||
"if [ $ecode -eq 0 ]; then", | ||
on_success, | ||
"else", | ||
on_failure, | ||
"fi", | ||
]) | ||
return FunctionAndCall(text = text, call = "trap \"cleanup_function\" EXIT") | ||
|
||
def children_to_path(dir_): | ||
text = """if [ -d {dir_} ]; then | ||
local tools=$(find $EXT_BUILD_DEPS/bin -maxdepth 1 -mindepth 1) | ||
for tool in $tools; | ||
do | ||
if [[ -d \"$tool\" ]] || [[ -L \"$tool\" ]]; then | ||
export PATH=$PATH:$tool | ||
fi | ||
done | ||
fi""".format(dir_ = dir_) | ||
return FunctionAndCall(text = text) | ||
|
||
def define_absolute_paths(dir_, abs_path): | ||
return "##replace_in_files## {dir_} {REPLACE_VALUE} {abs_path}".format( | ||
dir_ = dir_, | ||
REPLACE_VALUE = _REPLACE_VALUE, | ||
abs_path = abs_path, | ||
) | ||
|
||
def replace_absolute_paths(dir_, abs_path): | ||
return "##replace_in_files## {dir_} {abs_path} {REPLACE_VALUE}".format( | ||
dir_ = dir_, | ||
REPLACE_VALUE = _REPLACE_VALUE, | ||
abs_path = abs_path, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a recent bugfix for this section of code on other platforms. Does this also suffer from the same issue solved in #416 ?