forked from RedisBloom/RedisBloom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack.sh
executable file
·224 lines (168 loc) · 5.44 KB
/
pack.sh
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/bin/bash
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT=$HERE
export READIES=$ROOT/deps/readies
. $READIES/shibumi/defs
cd $ROOT
export PYTHONWARNINGS=ignore
export LC_CTYPE=en_US.UTF-8
#----------------------------------------------------------------------------------------------
if [[ $1 == --help || $1 == help ]]; then
cat <<-END
[ARGVARS...] pack.sh [--help|help]
Argument variables:
VERBOSE=1 Print commands
IGNERR=1 Do not abort on error
RAMP=1 Build RAMP file
DEPS=1 Build dependencies file
PACKAGE_NAME=name Package stem name
VARIANT=name Build variant (empty for standard packages)
BRANCH=name Branch name for snapshot packages
GITSHA=1 Append Git SHA to shapshot package names
BINDIR=dir Directory in which packages are created
INSTALL_DIR=dir Directory in which artifacts are found
END
exit 0
fi
#----------------------------------------------------------------------------------------------
[[ $IGNERR == 1 ]] || set -e
[[ $V == 1 || $VERBOSE == 1 ]] && set -x
RAMP=${RAMP:-1}
DEPS=${DEPS:-1}
[[ -z $INSTALL_DIR ]] && INSTALL_DIR=src
INSTALL_DIR=$(cd $INSTALL_DIR && pwd)
[[ -z $BINDIR ]] && BINDIR=bin/artifacts
mkdir -p $BINDIR
BINDIR=$(cd $BINDIR && pwd)
. $READIES/bin/enable-utf8
export ARCH=$($READIES/bin/platform --arch)
[[ $ARCH == x64 ]] && ARCH=x86_64
export OS=$($READIES/bin/platform --os)
[[ $OS == linux ]] && OS=Linux
export OSNICK=$($READIES/bin/platform --osnick)
[[ $OSNICK == trusty ]] && OSNICK=ubuntu14.04
[[ $OSNICK == xenial ]] && OSNICK=ubuntu16.04
[[ $OSNICK == bionic ]] && OSNICK=ubuntu18.04
[[ $OSNICK == focal ]] && OSNICK=ubuntu20.04
[[ $OSNICK == centos7 ]] && OSNICK=rhel7
[[ $OSNICK == centos8 ]] && OSNICK=rhel8
[[ $OSNICK == ol8 ]] && OSNICK=rhel8
[[ $OSNICK == rocky8 ]] && OSNICK=rhel8
export PRODUCT=redisbloom
export PRODUCT_LIB=$PRODUCT.so
export DEPNAMES=""
export PACKAGE_NAME=${PACKAGE_NAME:-${PRODUCT}}
RAMP_PROG="python3 -m RAMP.ramp"
#----------------------------------------------------------------------------------------------
pack_ramp() {
cd $ROOT
local platform="$OS-$OSNICK-$ARCH"
local stem=${PACKAGE_NAME}.${platform}
local verspec=${SEMVER}${_VARIANT}
local fq_package=$stem.${verspec}.zip
[[ ! -d $BINDIR ]] && mkdir -p $BINDIR
local packfile="$BINDIR/$fq_package"
local product_so="$PRODUCT.so"
local xtx_vars=""
local dep_fname=${PACKAGE_NAME}.${platform}.${verspec}.tgz
if [[ -z $RAMP_YAML ]]; then
RAMP_YAML=$ROOT/ramp.yml
fi
python3 $READIES/bin/xtx \
$xtx_vars \
-e NUMVER -e SEMVER \
$RAMP_YAML > /tmp/ramp.yml
rm -f /tmp/ramp.fname $packfile
$RAMP_PROG pack -m /tmp/ramp.yml --packname-file /tmp/ramp.fname --verbose --debug \
-o $packfile $product_so >/tmp/ramp.err 2>&1 || true
if [[ ! -e $packfile ]]; then
eprint "Error generating RAMP file:"
>&2 cat /tmp/ramp.err
exit 1
fi
mkdir -p $BINDIR/snapshots
cd $BINDIR/snapshots
if [[ ! -z $BRANCH ]]; then
local snap_package=$stem.${BRANCH}${_VARIANT}.zip
ln -sf ../$fq_package $snap_package
fi
cd $ROOT
}
#----------------------------------------------------------------------------------------------
pack_deps() {
local dep="$1"
local platform="$OS-$OSNICK-$ARCH"
local verspec=${SEMVER}${_VARIANT}
local stem=${PACKAGE_NAME}-${dep}.${platform}
local artdir=$BINDIR
local depdir=$(cat $artdir/$dep.dir)
local fq_dep=$stem.${verspec}.tgz
local tar_path=$artdir/$fq_dep
local dep_prefix_dir=$(cat $artdir/$dep.prefix)
{ cd $depdir ;\
cat $artdir/$dep.files | \
xargs tar -c --sort=name --owner=root:0 --group=root:0 --mtime='UTC 1970-01-01' \
--transform "s,^,$dep_prefix_dir," 2>> /tmp/pack.err | \
gzip -n - > $tar_path ; E=$?; } || true
rm -f $artdir/$dep.prefix $artdir/$dep.files $artdir/$dep.dir
cd $ROOT
if [[ $E != 0 ]]; then
eprint "Error creating $tar_path:"
cat /tmp/pack.err >&2
exit 1
fi
sha256sum $tar_path | awk '{print $1}' > $tar_path.sha256
mkdir -p $BINDIR/snapshots
cd $BINDIR/snapshots
if [[ ! -z $BRANCH ]]; then
local snap_dep=$stem.${BRANCH}${_VARIANT}.tgz
ln -sf ../$fq_dep $snap_dep
ln -sf ../$fq_dep.sha256 $snap_dep.sha256
fi
cd $ROOT
}
#----------------------------------------------------------------------------------------------
prepare_symbols_dep() {
echo "Preparing debug symbols dependencies ..."
echo $INSTALL_DIR > $BINDIR/debug.dir
echo $PRODUCT.so.debug > $BINDIR/debug.files
echo "" > $BINDIR/debug.prefix
pack_deps debug
echo "Done."
}
#----------------------------------------------------------------------------------------------
export NUMVER=$(NUMERIC=1 $ROOT/getver)
export SEMVER=$($ROOT/getver)
_VARIANT=
if [[ -n $VARIANT ]]; then
_VARIANT=-${VARIANT}
fi
[[ -z $BRANCH ]] && BRANCH=${CIRCLE_BRANCH:-`git rev-parse --abbrev-ref HEAD`}
BRANCH=${BRANCH//[^A-Za-z0-9._-]/_}
if [[ $GITSHA == 1 ]]; then
GIT_COMMIT=$(git describe --always --abbrev=7 --dirty="+" 2>/dev/null || git rev-parse --short HEAD)
BRANCH="${BRANCH}-${GIT_COMMIT}"
fi
export BRANCH
if [[ $DEPS == 1 ]]; then
echo "Building dependencies ..."
prepare_symbols_dep
for dep in $DEPNAMES; do
echo "$dep ..."
pack_deps $dep
done
fi
if [[ $RAMP == 1 ]]; then
if ! command -v redis-server > /dev/null; then
eprint "$0: Cannot find redis-server. Aborting."
exit 1
fi
echo "Building RAMP files ..."
pack_ramp
echo "Done."
fi
if [[ $VERBOSE == 1 ]]; then
echo "Artifacts:"
du -ah --apparent-size $BINDIR
fi
exit 0