2020-10-04 09:37:37 +00:00
|
|
|
#!/usr/bin/env bash
|
2019-02-02 10:19:11 +00:00
|
|
|
set -euo pipefail
|
2018-04-30 13:41:30 +00:00
|
|
|
|
2018-05-16 19:22:16 +00:00
|
|
|
ASSET_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2019-10-04 18:43:36 +00:00
|
|
|
REPO_DIR="$ASSET_DIR/.."
|
2018-04-30 13:41:30 +00:00
|
|
|
|
2019-09-27 19:43:11 +00:00
|
|
|
# Ensure submodules are initialized.
|
2021-08-21 10:19:11 +00:00
|
|
|
update_submodules() {
|
2019-10-04 18:43:36 +00:00
|
|
|
local submodule
|
|
|
|
local submodule_prompt=unspecified
|
|
|
|
local submodule_path
|
|
|
|
|
|
|
|
{
|
|
|
|
while { read -r submodule && read -r submodule_path; } <&3; do
|
|
|
|
if ! [[ -d "${REPO_DIR}/.git/modules/${submodule}" ]] && [[ -d "${REPO_DIR}/${submodule_path}" ]]; then
|
|
|
|
if [[ "$submodule_prompt" = "unspecified" ]]; then
|
|
|
|
echo "One or more submodules were found to be uninitialized."
|
|
|
|
printf "Initialize and update them? [Y/n] "
|
|
|
|
read -r submodule_prompt
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$submodule_prompt" in
|
|
|
|
y|yes|'') {
|
|
|
|
git -C "$REPO_DIR" submodule update --init "$submodule_path"
|
|
|
|
};;
|
|
|
|
n|no) {
|
|
|
|
return
|
|
|
|
};;
|
|
|
|
*) {
|
|
|
|
echo "Unknown answer. Not updating submodules."
|
|
|
|
};;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
} 3< <(git config --file "${REPO_DIR}/.gitmodules" --null --get-regexp path | xargs -0 printf "%s\n" | sed 's/^submodule.//;s/.path$//')
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -t 0 ]; then
|
|
|
|
update_submodules
|
|
|
|
fi
|
2019-09-27 19:43:11 +00:00
|
|
|
|
2018-10-10 19:49:03 +00:00
|
|
|
# Always remove the local cache to avoid any confusion
|
|
|
|
bat cache --clear
|
|
|
|
|
2020-04-11 20:50:02 +00:00
|
|
|
# TODO:
|
|
|
|
# - Remove the JavaDoc patch once https://github.com/trishume/syntect/issues/222 has been fixed
|
|
|
|
# - Remove the C# patch once https://github.com/sublimehq/Packages/pull/2331 has been merged
|
|
|
|
|
2021-12-11 12:55:11 +00:00
|
|
|
# Apply patches
|
2020-04-11 20:50:02 +00:00
|
|
|
(
|
|
|
|
cd "$ASSET_DIR"
|
|
|
|
for patch in patches/*.patch; do
|
|
|
|
patch --strip=0 < "$patch"
|
|
|
|
done
|
|
|
|
)
|
2018-10-04 08:16:53 +00:00
|
|
|
|
2021-12-11 12:55:11 +00:00
|
|
|
reverse_patches() {
|
|
|
|
(
|
|
|
|
cd "$ASSET_DIR"
|
|
|
|
for patch in patches/*.patch; do
|
|
|
|
patch --strip=0 --reverse <"$patch"
|
|
|
|
done
|
|
|
|
)
|
|
|
|
}
|
2018-10-04 08:16:53 +00:00
|
|
|
|
2021-12-11 12:55:11 +00:00
|
|
|
# Make sure to always reverse patches, even if the `bat cache` command fails or aborts
|
|
|
|
trap reverse_patches EXIT
|
|
|
|
|
|
|
|
bat cache --build --blank --acknowledgements --source="$ASSET_DIR" --target="$ASSET_DIR"
|