mirror of
https://github.com/bazel-contrib/rules_foreign_cc
synced 2024-11-30 16:42:07 +00:00
52 lines
1.4 KiB
Plaintext
Executable file
52 lines
1.4 KiB
Plaintext
Executable file
function symlink_contents_to_dir() {
|
|
local target="$2"
|
|
mkdir -p "$target"
|
|
if [[ -f "$1" ]]; then
|
|
symlink_to_dir "$1" "$target"
|
|
elif [[ -L "$1" && ! -d "$1" ]]; then
|
|
local actual=$(readlink "$1")
|
|
symlink_contents_to_dir "$actual" "$target"
|
|
elif [[ -d "$1" ]]; then
|
|
SAVEIFS=$IFS
|
|
IFS=$'
|
|
'
|
|
local children=($(find "$1/" -maxdepth 1 -mindepth 1))
|
|
IFS=$SAVEIFS
|
|
for child in "${children[@]:-}"; do
|
|
symlink_to_dir "$child" "$target"
|
|
done
|
|
fi
|
|
}
|
|
function symlink_to_dir() {
|
|
local target="$2"
|
|
mkdir -p "$target"
|
|
if [[ -f "$1" ]]; then
|
|
# In order to be able to use `replace_in_files`, we ensure that we create copies of specfieid
|
|
# files so updating them is possible.
|
|
local input_basename="$(basename "$1")"
|
|
if [[ "$input_basename" == "libtool" || "$1" == *.pc || "$1" == *.la || "$1" == *.lai || "$1" == *-config || "$1" == *.nice || "$1" == *.mk || "$1" == *.cmake ]]; then
|
|
local dest="$target/$input_basename"
|
|
cp "$1" "$dest" && chmod +w "$dest" && touch -r "$1" "$dest"
|
|
else
|
|
ln -s -f "$1" "$target"
|
|
fi
|
|
elif [[ -L "$1" && ! -d "$1" ]]; then
|
|
cp -a "$1" "$2"
|
|
elif [[ -d "$1" ]]; then
|
|
SAVEIFS=$IFS
|
|
IFS=$'
|
|
'
|
|
local children=($(find "$1/" -maxdepth 1 -mindepth 1))
|
|
IFS=$SAVEIFS
|
|
local dirname=$(basename "$1")
|
|
mkdir -p "$target/$dirname"
|
|
for child in "${children[@]:-}"; do
|
|
if [[ "$dirname" != *.ext_build_deps ]]; then
|
|
symlink_to_dir "$child" "$target/$dirname"
|
|
fi
|
|
done
|
|
else
|
|
echo "Can not copy $1"
|
|
fi
|
|
}
|
|
symlink_contents_to_dir $SOURCE_DIR $TARGET_DIR |