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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
#!/bin/sh
# Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -eu
# cleanup of http.server; pass server_pid as arg
server_cleanup() {
echo "Shut down HTTP server(s)"
while [ -n "${1:-}" ]; do
# send SIGTERM
kill ${1} & res=$!
wait ${res}
echo "done ${1}"
shift
done
}
readonly ROOT=`pwd`
readonly WRKDIR="${TEST_TMPDIR}/wrkdir"
readonly JUST_MR_CPP="${ROOT}/bin/mr-tool-under-test"
# set paths
readonly SERVER_ROOT="${TEST_TMPDIR}/server-root"
readonly GIT_ROOT="${TEST_TMPDIR}/git-root"
readonly TEST_ROOT="${TEST_TMPDIR}/test-root"
# move to where server will be posted
mkdir -p "${SERVER_ROOT}"
cd "${SERVER_ROOT}"
echo "Setup archive repos"
# create the archives in current dir
${ROOT}/src/create_test_archives
# store zip repo info
readonly ZIP_REPO_CONTENT=$(git hash-object zip_repo.zip)
readonly ZIP_REPO_SHA256=$(sha256sum zip_repo.zip | awk '{print $1}')
readonly ZIP_REPO_SHA512=$(sha512sum zip_repo.zip | awk '{print $1}')
# store tar.gz repo info
readonly TGZ_REPO_CONTENT=$(git hash-object tgz_repo.tar.gz)
readonly TGZ_REPO_SHA256=$(sha256sum tgz_repo.tar.gz | awk '{print $1}')
readonly TGZ_REPO_SHA512=$(sha512sum tgz_repo.tar.gz | awk '{print $1}')
echo "Set up local git repo"
# NOTE: Libgit2 has no support for Git bundles yet
mkdir -p "${GIT_ROOT}"
mkdir -p bin
cat > bin/git_dir_setup.sh <<EOF
mkdir -p foo/bar
echo foo > foo.txt
echo bar > foo/bar.txt
echo baz > foo/bar/baz.txt
ln -s dummy foo/link
EOF
# set up git repo
(
cd "${GIT_ROOT}" \
&& sh "${SERVER_ROOT}/bin/git_dir_setup.sh" \
&& git init \
&& git checkout -q -b test \
&& git config user.email "nobody@example.org" \
&& git config user.name "Nobody" \
&& git add . \
&& git commit -m "test" --date="1970-01-01T00:00Z"
)
readonly GIT_REPO_COMMIT="$(cd "${GIT_ROOT}" && git rev-parse HEAD)"
echo "Publish remote repos to HTTP server"
# start Python server as remote repos location
port_file="$(mktemp -t port_XXXXXX -p "${TEST_TMPDIR}")"
python3 -u "${ROOT}/utils/run_test_server.py" "${port_file}" & server_pid=$!
# set up cleanup of http server
trap "server_cleanup ${server_pid}" INT TERM EXIT
# wait for the server to be available
tries=0
while [ -z "$(cat "${port_file}")" ] && [ $tries -lt 10 ]
do
tries=$((${tries}+1))
sleep 1s
done
# get port number as variable
port_num="$(cat ${port_file})"
if [ -z "${port_num}" ]; then
exit 1
fi
echo "Create local build env"
# the build root
readonly BUILDROOT=${WRKDIR}/.cache/just
mkdir -p ${BUILDROOT}
# a distdir
readonly DISTFILES=${WRKDIR}/.distfiles
mkdir -p ${DISTFILES}
readonly DISTDIR_ARGS="--distdir ${DISTFILES}"
### Using "mirrors" config field
echo "Create repos.json"
mkdir -p "${TEST_ROOT}"
cd "${TEST_ROOT}"
cat > test-repos.json <<EOF
{ "repositories":
{ "zip_repo":
{ "repository":
{ "type": "zip"
, "content": "${ZIP_REPO_CONTENT}"
, "distfile": "zip_repo.zip"
, "fetch": "http://non-existent.example.org/zip_repo.zip"
, "mirrors":
[ "http://non-existent.example.org/zip_repo.zip"
, "http://127.0.0.1:${port_num}/zip_repo.zip"
]
, "sha256": "${ZIP_REPO_SHA256}"
, "sha512": "${ZIP_REPO_SHA512}"
, "subdir": "root"
, "pragma": {"special": "resolve-partially"}
}
}
, "tgz_repo":
{ "repository":
{ "type": "archive"
, "content": "${TGZ_REPO_CONTENT}"
, "distfile": "tgz_repo.tar.gz"
, "fetch": "http://non-existent.example.org/tgz_repo.tar.gz"
, "mirrors":
[ "http://non-existent.example.org/tgz_repo.tar.gz"
, "http://127.0.0.1:${port_num}/tgz_repo.tar.gz"
]
, "sha256": "${TGZ_REPO_SHA256}"
, "sha512": "${TGZ_REPO_SHA512}"
, "subdir": "root/baz"
, "pragma": {"special": "ignore"}
}
}
, "git_repo":
{ "repository":
{ "type": "git"
, "repository": "http://non-existent.example.org/dummy.git"
, "mirrors":
[ "http://non-existent.example.org/dummy.git"
, "${GIT_ROOT}"
]
, "branch": "test"
, "commit": "${GIT_REPO_COMMIT}"
, "subdir": "foo"
}
}
, "distdir_repo":
{ "repository":
{ "type": "distdir"
, "repositories": ["zip_repo", "tgz_repo", "git_repo"]
}
}
}
}
EOF
echo "Test mirrors fetch"
rm -rf ${BUILDROOT} ${DISTFILES}/*
${JUST_MR_CPP} -C test-repos.json --norc --local-build-root ${BUILDROOT} ${DISTDIR_ARGS} -j 32 fetch --all -o ${DISTFILES}
echo "Test mirrors setup"
rm -rf ${BUILDROOT} ${DISTFILES}/*
CONFIG_CPP=$(${JUST_MR_CPP} -C test-repos.json --norc --local-build-root ${BUILDROOT} ${DISTDIR_ARGS} -j 32 setup --all)
if [ ! -s "${CONFIG_CPP}" ]; then
exit 1
fi
### Using .just-local specifications
cat > test-repos.json <<EOF
{ "repositories":
{ "git_repo_1":
{ "repository":
{ "type": "git"
, "repository": "http://non-existent.example.org/dummy.git"
, "branch": "test"
, "commit": "${GIT_REPO_COMMIT}"
, "subdir": "foo"
}
}
, "git_repo_2":
{ "repository":
{ "type": "git"
, "repository": "http://non-existent.example.org/dummy.git"
, "branch": "test"
, "commit": "${GIT_REPO_COMMIT}"
, "subdir": "."
}
}
, "zip_repo":
{ "repository":
{ "type": "zip"
, "content": "${ZIP_REPO_CONTENT}"
, "distfile": "zip_repo.zip"
, "fetch": "http://non-existent.example.org/zip_repo.zip"
, "sha256": "${ZIP_REPO_SHA256}"
, "sha512": "${ZIP_REPO_SHA512}"
, "subdir": "root"
, "pragma": {"special": "resolve-partially"}
}
}
, "tgz_repo":
{ "repository":
{ "type": "archive"
, "content": "${TGZ_REPO_CONTENT}"
, "distfile": "tgz_repo.tar.gz"
, "fetch": "http://non-existent.example.org:${port_num}/tgz_repo.tar.gz"
, "sha256": "${TGZ_REPO_SHA256}"
, "sha512": "${TGZ_REPO_SHA512}"
, "subdir": "root/baz"
, "pragma": {"special": "ignore"}
}
}
}
}
EOF
cat > just-local.json <<EOF
{ "local mirrors":
{ "http://non-existent.example.org/dummy.git":
[ "http://non-existent.example.org/dummy.git"
, "${GIT_ROOT}"
]
, "http://non-existent.example.org/zip_repo.zip":
[ "http://non-existent.example.org/zip_repo.zip"
, "http://127.0.0.1:${port_num}/zip_repo.zip"
]
, "http://non-existent.example.org:${port_num}/tgz_repo.tar.gz":
[ "http://non-existent.example.org/tgz_repo.tar.gz"
, "http://127.0.0.1:${port_num}/tgz_repo.tar.gz"
]
}
}
EOF
echo "Test 'local mirrors' fetch"
rm -rf ${BUILDROOT} ${DISTFILES}/*
${JUST_MR_CPP} -C test-repos.json --norc --local-build-root ${BUILDROOT} --checkout-locations just-local.json -j 32 fetch --all -o ${DISTFILES}
echo "Test 'local mirrors' setup"
rm -rf ${BUILDROOT} ${DISTFILES}/*
CONFIG_CPP=$(${JUST_MR_CPP} -C test-repos.json --norc --local-build-root ${BUILDROOT} --checkout-locations just-local.json -j 32 setup --all)
if [ ! -s "${CONFIG_CPP}" ]; then
exit 1
fi
### Create second "state server" that writes access file if used
readonly STATE_SERVER="${ROOT}/utils/null-server"
readonly STATE_SERVER_ROOT="${TEST_TMPDIR}/state-server-root"
mkdir -p "${STATE_SERVER_ROOT}"
"${STATE_SERVER}" "${STATE_SERVER_ROOT}/port" "${STATE_SERVER_ROOT}/access" & state_server_pid=$!
trap "kill $server_pid" INT TERM EXIT
trap "server_cleanup ${server_pid} ${state_server_pid}" INT TERM EXIT
while [ '!' -f "${STATE_SERVER_ROOT}/port" ]
do
sleep 1s
done
# get port of "state server"
state_port_num="$(cat ${STATE_SERVER_ROOT}/port)"
if [ -z "${state_port_num}" ]; then
exit 1
fi
### Use .just-local with 'preferred hostnames' favoring host '127.0.0.1' over
### 'localhost' aka the "state server".
cat > test-repos.json <<EOF
{ "repositories":
{ "git_repo_1":
{ "repository":
{ "type": "git"
, "repository": "http://localhost:${state_port_num}/dummy.git"
, "branch": "test"
, "commit": "${GIT_REPO_COMMIT}"
, "subdir": "foo"
}
}
, "git_repo_2":
{ "repository":
{ "type": "git"
, "repository": "http://localhost:${state_port_num}/dummy.git"
, "branch": "test"
, "commit": "${GIT_REPO_COMMIT}"
, "subdir": "."
}
}
, "zip_repo":
{ "repository":
{ "type": "zip"
, "content": "${ZIP_REPO_CONTENT}"
, "distfile": "zip_repo.zip"
, "fetch": "http://localhost:${state_port_num}/zip_repo.zip"
, "mirrors": ["http://127.0.0.1:${port_num}/zip_repo.zip"]
, "sha256": "${ZIP_REPO_SHA256}"
, "sha512": "${ZIP_REPO_SHA512}"
, "subdir": "root"
, "pragma": {"special": "resolve-partially"}
}
}
, "tgz_repo":
{ "repository":
{ "type": "archive"
, "content": "${TGZ_REPO_CONTENT}"
, "distfile": "tgz_repo.tar.gz"
, "fetch": "http://localhost:${state_port_num}/tgz_repo.tar.gz"
, "mirrors": ["http://127.0.0.1:${port_num}/tgz_repo.tar.gz"]
, "sha256": "${TGZ_REPO_SHA256}"
, "sha512": "${TGZ_REPO_SHA512}"
, "subdir": "root/baz"
, "pragma": {"special": "ignore"}
}
}
}
}
EOF
cat > just-local.json <<EOF
{ "local mirrors":
{"http://localhost:${state_port_num}/dummy.git": ["${GIT_ROOT}"]}
, "preferred hostnames": ["127.0.0.1", "localhost"]
}
EOF
echo "Test 'preferred hostnames' fetch"
rm -rf ${BUILDROOT} ${DISTFILES}/*
${JUST_MR_CPP} -C test-repos.json --norc --local-build-root ${BUILDROOT} --checkout-locations just-local.json -j 32 fetch --all -o ${DISTFILES}
if [ -f "${STATE_SERVER_ROOT}/access" ]; then
cat "${STATE_SERVER_ROOT}/access"
exit 1
fi
echo OK
|