-
Notifications
You must be signed in to change notification settings - Fork 6
/
update_mozc_deps
executable file
·113 lines (90 loc) · 3.1 KB
/
update_mozc_deps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
cleanup() {
pkill -P $$ || true
}
check_bazel_binary() {
yq -r '.sources[] | select(.url | contains("'$1'")) | "\(.sha256) 'bazel-$1'"' "$SCRIPT_DIRECTORY/modules/bazel.yaml" | sha256sum --check -
return $?
}
check_and_download_bazel() {
# Extract bazel information from modules/bazel.yaml
local BAZEL_URL=`yq -r '.sources[].url | select(contains("'$1'"))' "$SCRIPT_DIRECTORY/modules/bazel.yaml"`
FILENAME="$(basename "$BAZEL_URL")"
if [ -f "bazel-$1" ]; then
chmod +x bazel-$1
if check_bazel_binary $1 ; then
return 0
else
rm -f "bazel-$1"
fi
fi
wget -nv -O bazel-$1 ${BAZEL_URL}
chmod +x bazel-$1
check_bazel_binary $1
return $?
}
run_bazel() {
echo $1 clean --expunge
$1 clean --expunge
echo $1 build --nobuild --experimental_downloader_config="$SCRIPT_DIRECTORY/downloader.cfg" --registry=file://$BASE/bcr --repository_cache="$_MOZC_BAZEL_CACHE" --config oss_linux --config release_build $2
$1 build --noshow_progress --nobuild --experimental_downloader_config="$SCRIPT_DIRECTORY/downloader.cfg" --registry=file://$BASE/bcr --repository_cache="$_MOZC_BAZEL_CACHE" --config oss_linux --config release_build $2
}
trap cleanup EXIT
SCRIPT_PATH="$(realpath "${BASH_SOURCE[-1]}")"
SCRIPT_DIRECTORY="$(dirname "$SCRIPT_PATH")"
BAZEL_VERSION=7.3.2
set -e
# TMPDIR
[[ -z $TMPDIR ]] && TMPDIR=$PWD/tmp
BASE="$TMPDIR/update_mozc"
mkdir -p "$BASE"
cd "$BASE"
[[ ! -d mozc ]] && git clone --recursive -q --filter=tree:0 https://github.com/fcitx/mozc/
[[ ! -d bcr ]] && git clone -q --filter=tree:0 https://github.com/bazelbuild/bazel-central-registry bcr
# Always use downloaded bazel
check_and_download_bazel arm64
check_and_download_bazel x86_64
pushd .
cd bcr
git fetch --all
git checkout origin/main
popd
pushd .
cd mozc/src/
git fetch --all
git checkout origin/fcitx
git submodule update --init
popd
_MOZC_BAZEL_CACHE="$BASE/mozc_cache"
_DOWNLOADER_CACHE="$BASE/downloader_cache"
BAZEL_MIRROR="$SCRIPT_DIRECTORY/bazel_mirror.py"
pushd .
mkdir -p "$_DOWNLOADER_CACHE"
cd "$_DOWNLOADER_CACHE"
python3 "$BAZEL_MIRROR" &
PROXY_PID=$!
popd
[[ -z $PROXY_PID ]] && exit 1
cd mozc/src/
BUILD_TARGET_SERVER="server:mozc_server"
BUILD_TARGET="unix/fcitx5:fcitx5-mozc.so ${BUILD_TARGET_SERVER} gui/tool:mozc_tool"
run_bazel "$BASE/bazel-x86_64" "$BUILD_TARGET"
# Only run aarch64 against server target, as with flatpak we have no external dependencies
# TODO: apply only tag for deps
run_bazel "flatpak run --arch=aarch64 --filesystem=$SCRIPT_DIRECTORY --filesystem=home --share=network --filesystem=xdg-cache --command=$BASE/bazel-arm64 org.freedesktop.Sdk/aarch64/23.08" "$BUILD_TARGET_SERVER"
kill $PROXY_PID
pushd .
cd $_DOWNLOADER_CACHE
for f in `find -type f` ; do
if [[ ! "$f" =~ "./bcr.bazel.build/" ]];then
url="https://${f#*/}"
echo "- type: file"
echo " url: $url"
echo " dest: bazel-deps"
sha=`sha256sum $f|cut -f1 -d" "`
echo " sha256: $sha"
fi
done > $SCRIPT_DIRECTORY/mozc-deps.yaml
popd
yq -y -i 'sort_by(.url)' "$SCRIPT_DIRECTORY/mozc-deps.yaml"
rm -rf "$BASE"