summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-10-31 17:09:43 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-14 13:35:01 +0100
commit180abedbc498bd8b5efc19ad068bc0a5704559b2 (patch)
treeb88785dff5f34a08cdde353dbf0568a0ac7a5d6e
parentbc84005095bab7c62faf0ddf08763bd96892e478 (diff)
downloadjustbuild-180abedbc498bd8b5efc19ad068bc0a5704559b2.tar.gz
test: Add check for 'mirrors' field in just-mr repositories
-rwxr-xr-xbin/just-import-git.py3
-rw-r--r--test/end-to-end/just-mr/TARGETS11
-rw-r--r--test/end-to-end/just-mr/just-mr-mirrors.test.sh171
3 files changed, 183 insertions, 2 deletions
diff --git a/bin/just-import-git.py b/bin/just-import-git.py
index f77efb8e..3be9b0ef 100755
--- a/bin/just-import-git.py
+++ b/bin/just-import-git.py
@@ -287,8 +287,7 @@ def handle_import(args: Namespace) -> Json:
import_map: Json = {}
for theirs, ours in args.import_map:
import_map[theirs] = ours
- main_repos = repos_to_import(foreign_repos, foreign_name,
- import_map.keys())
+ main_repos = repos_to_import(foreign_repos, foreign_name, import_map.keys())
extra_repos = sorted([x for x in main_repos if x != foreign_name])
extra_imports = sorted(extra_layers_to_import(foreign_repos, main_repos))
ordered_imports: List[str] = [foreign_name] + extra_repos + extra_imports
diff --git a/test/end-to-end/just-mr/TARGETS b/test/end-to-end/just-mr/TARGETS
index 101f9ec9..99d2d7b8 100644
--- a/test/end-to-end/just-mr/TARGETS
+++ b/test/end-to-end/just-mr/TARGETS
@@ -41,6 +41,16 @@
, ["end-to-end", "mr-tool-under-test"]
]
}
+, "just_mr_mirrors":
+ { "type": ["@", "rules", "shell/test", "script"]
+ , "name": ["just_mr_mirrors"]
+ , "test": ["just-mr-mirrors.test.sh"]
+ , "deps":
+ [ "create_test_archives"
+ , ["utils", "test_utils_install"]
+ , ["end-to-end", "mr-tool-under-test"]
+ ]
+ }
, "git-tree-verbosity":
{ "type": ["@", "rules", "shell/test", "script"]
, "name": ["git-tree-verbosity"]
@@ -159,6 +169,7 @@
, "$1":
[ [ "install-roots-symlinks"
, "just_mr_mp"
+ , "just_mr_mirrors"
, "git-tree-verbosity"
, "git-tree-env"
, "defaults"
diff --git a/test/end-to-end/just-mr/just-mr-mirrors.test.sh b/test/end-to-end/just-mr/just-mr-mirrors.test.sh
new file mode 100644
index 00000000..c9015373
--- /dev/null
+++ b/test/end-to-end/just-mr/just-mr-mirrors.test.sh
@@ -0,0 +1,171 @@
+#!/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"
+ # send SIGTERM
+ kill ${1} & res=$!
+ wait ${res}
+ echo "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}"
+
+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
+
+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
+
+echo OK