diff options
author | Quentin Schulz <quentin.schulz@theobroma-systems.com> | 2024-03-01 18:03:26 +0100 |
---|---|---|
committer | Quentin Schulz <quentin.schulz@theobroma-systems.com> | 2024-03-06 11:18:43 +0100 |
commit | 7b514e43d002bd677cdcaeaf2f46e031adad2638 (patch) | |
tree | 2f0f017c5a6edcfbb6dd59b126d7bb452a666bbc | |
parent | ff8c713452c96f2c680b0285374379e1611e4bf2 (diff) |
build.sh: migrate to individual configuration files
Instead of doing some elaborate regexp find and replace (which erased
half of the build.sh script on errors), let's use a conf file per
supported board.
Essentially UBOOT_BINARIES_URL, UBOOT_BINARIES and LINUX_BINARIES_URL
are moved to a board-specific build.conf file. This file is stored in
the directory named after the board.
The build.conf file must be formatted as it would be done for assigning
variables in POSIX shell. Note that this build.conf file is sourced by a
shell script and parsed as a TOML file in
maintainer-scripts/bump-binaries.py.
Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
-rwxr-xr-x | build.sh | 65 | ||||
-rw-r--r-- | jaguar/build.conf | 6 | ||||
-rwxr-xr-x | maintainer-scripts/bump-binaries.py | 74 | ||||
-rw-r--r-- | maintainer-scripts/requirements.txt | 1 | ||||
-rw-r--r-- | puma/build.conf | 6 | ||||
-rw-r--r-- | ringneck/build.conf | 6 | ||||
-rw-r--r-- | tiger/build.conf | 6 |
7 files changed, 87 insertions, 77 deletions
@@ -84,47 +84,30 @@ else fi # Build images -build_board=${build_board:-unset} + +if [ -z "${build_board+x}" ]; then + echo "build_board variable needs to be passed to the script, stopping..." + exit 1 +elif [ ! -d "${build_board}" ]; then + echo "No directory to match build_board variable ($build_board), stopping..." + exit 1 +elif [ ! -f "${build_board}/build.conf" ]; then + echo "Missing $build_board/build.conf or incorrect $build_board, stopping..." + exit 1 +fi + debos_variant=${debos_variant:-bookworm} debos_yaml="${build_board}-${debos_variant}.yaml" -# How to update the links: -# 1) go on the Gitlab "upstream" project page (not personal forks!) -# 2) select the appropriate branch (not merge request!) -# 3) click on the pipeline button (a green circle with a green check mark inside) -# 4) click on the Jobs tab -# 5) right-click on the download button and click on "Copy Link" -# -# The ###xxx### markers at the end of the line facilitate automatic search-replace. Do not remove them. -case "$build_board" in - puma) - UBOOT_BINARIES_URL="https://gitlab.lan/products/u-boot/-/jobs/102537/artifacts/download?file_type=archive" ###puma### - UBOOT_BINARIES="u-boot-rockchip.bin" ###puma### - LINUX_BINARIES_URL="https://gitlab.lan/products/linux/-/jobs/203166/artifacts/download?file_type=archive" ###puma### - ;; - ringneck) - UBOOT_BINARIES_URL="https://gitlab.lan/products/u-boot/-/jobs/214346/artifacts/download?file_type=archive" ###ringneck### - UBOOT_BINARIES="u-boot-rockchip.bin" ###ringneck### - LINUX_BINARIES_URL="https://gitlab.lan/products/linux/-/jobs/199415/artifacts/download?file_type=archive" ###ringneck### - ;; - tiger) - UBOOT_BINARIES_URL="https://gitlab.lan/products/u-boot/-/jobs/197416/artifacts/download?file_type=archive" ###tiger### - UBOOT_BINARIES="idbloader.img u-boot.itb" ###tiger### - LINUX_BINARIES_URL="https://gitlab.lan/products/linux/-/jobs/214482/artifacts/download?file_type=archive" ###tiger### - ;; - jaguar) - UBOOT_BINARIES_URL="https://gitlab.lan/products/u-boot/-/jobs/214475/artifacts/download?file_type=archive" ###jaguar### - UBOOT_BINARIES="u-boot-rockchip.bin" ###jaguar### - LINUX_BINARIES_URL="https://gitlab.lan/products/linux/-/jobs/203407/artifacts/download?file_type=archive" ###jaguar### - ;; - *) - print_usage - exit 1 - ;; -esac +pushd "${build_board}" +# shellcheck disable=SC1091 +. build.conf -pushd "${build_board}" +if [ -z "${UBOOT_BINARIES:-}" ]; then + echo "Fatal: $build_board/build.conf doesn't contain a UBOOT_BINARIES variable (or is empty), stopping..." + exit 1 +fi if [[ ! -f "$debos_yaml" ]] ; then echo "Fatal: config file $PWD/$debos_yaml does not exist!" @@ -155,12 +138,22 @@ esac echo "dl=$dl" if [[ $dl -eq 1 ]] ; then + if [ -z "${UBOOT_BINARIES_URL:-}" ]; then + echo "Fatal: $build_board/build.conf doesn't contain a UBOOT_BINARIES_URL (or it is empty) variable, stopping..." + exit 1 + fi + # U-Boot gets written to the raw disk image by debos ZIP_TMP_FILE=$(mktemp) wget --no-verbose "$UBOOT_BINARIES_URL" -O "$ZIP_TMP_FILE" unzip -j -o "$ZIP_TMP_FILE" -x '*.zip' rm "$ZIP_TMP_FILE" + if [ -z "${LINUX_BINARIES_URL:-}" ]; then + echo "Fatal: $build_board/build.conf doesn't contain a LINUX_BINARIES_URL (or it is empty) variable, stopping..." + exit 1 + fi + # Kernel and DTB files go into the root filesystem into /boot # Kernel modules go into the root filesystem into /lib/modules/ ZIP_TMP_FILE=$(mktemp) diff --git a/jaguar/build.conf b/jaguar/build.conf new file mode 100644 index 0000000..036fd0d --- /dev/null +++ b/jaguar/build.conf @@ -0,0 +1,6 @@ +# This file needs to be valid TOML **AND** valid shell, so only store variables in there. + +UBOOT_BINARIES="u-boot-rockchip.bin" +# DO NOT MODIFY; Use maintainer-scripts/bump-binaries.py to edit the next lines automatically +UBOOT_BINARIES_URL="https://gitlab.lan/products/u-boot/-/jobs/214475/artifacts/download?file_type=archive" +LINUX_BINARIES_URL="https://gitlab.lan/products/linux/-/jobs/203407/artifacts/download?file_type=archive" diff --git a/maintainer-scripts/bump-binaries.py b/maintainer-scripts/bump-binaries.py index 140a039..ae0ccc8 100755 --- a/maintainer-scripts/bump-binaries.py +++ b/maintainer-scripts/bump-binaries.py @@ -12,8 +12,10 @@ import os import argparse +import logging import re import sys +import tomlkit import gitlab import urllib3 @@ -109,48 +111,38 @@ def process_one(gl, todo): os.exit(1) # Update the URL - with open("../build.sh", "r") as f: - lines = f.readlines() - - search = f"^(\\s+){todo.shell_var}=\"https://gitlab\\.lan/{todo.gitlab_path}/-/jobs/(\\d+)/artifacts/download\\?file_type=archive\" ###{todo.board_name}###" # noqa: E501 - - matched = False - with open("../build.sh", "w") as f: - for line in lines: - m = re.match(search, line) - if not m: - f.write(line) - continue - - if matched: - raise Exception(f"BUG: already have a match for todo={todo}") - else: - matched = True - - old_job_id = int(m.group(2)) - if not old_job_id: - raise Exception("BUG: old_job_id is zero") - - replace = f"{m.group(1)}{todo.shell_var}=\"https://gitlab.lan/{todo.gitlab_path}/-/jobs/{job.id}/artifacts/download?file_type=archive\" ###{todo.board_name}###\n" # noqa: E501 - if line == replace: - f.write(line) - continue - - done.changed = True - # We need the "commit" and "job" objects later for generating - # the commit message - done.project = project - done.new_commit_id = commit.id - done.new_commit_short_id = commit.short_id - done.new_job = job - old_job = project.jobs.get(old_job_id) - done.old_commit_id = old_job.commit['id'] - done.old_commit = project.commits.get(done.old_commit_id) - - f.write(replace) - - if not matched: + + try: + conf = tomlkit.load(open(f"../{todo.board_name}/build.conf")) + except Exception: + logging.exception(f"Parsing ../{todo.board_name}/build.conf failed:") + return done + + search = r'jobs/(\d+)/artifacts' + + m = re.search(search, conf.get(todo.shell_var, "")) + if not m: print(f"Warning: no matching line for todo={todo}") + return done + + old_job_id = int(m.group(1)) + if not old_job_id: + raise Exception("BUG: old_job_id is zero") + + done.changed = True + # We need the "commit" and "job" objects later for generating + # the commit message + done.project = project + done.new_commit_id = commit.id + done.new_commit_short_id = commit.short_id + done.new_job = job + old_job = project.jobs.get(old_job_id) + done.old_commit_id = old_job.commit['id'] + done.old_commit = project.commits.get(done.old_commit_id) + + conf[todo.shell_var] = \ + f"{job.web_url}/artifacts/download?file_type=archive" + tomlkit.dump(conf, open(f"../{todo.board_name}/build.conf", "w")) return done diff --git a/maintainer-scripts/requirements.txt b/maintainer-scripts/requirements.txt index e266646..226e2b5 100644 --- a/maintainer-scripts/requirements.txt +++ b/maintainer-scripts/requirements.txt @@ -4,4 +4,5 @@ idna==3.6 python-gitlab==4.2.0 requests==2.31.0 requests-toolbelt==1.0.0 +tomlkit==0.12.0 urllib3==2.1.0 diff --git a/puma/build.conf b/puma/build.conf new file mode 100644 index 0000000..c346107 --- /dev/null +++ b/puma/build.conf @@ -0,0 +1,6 @@ +# This file needs to be valid TOML **AND** valid shell, so only store variables in there. + +UBOOT_BINARIES="u-boot-rockchip.bin" +# DO NOT MODIFY; Use maintainer-scripts/bump-binaries.py to edit the next lines automatically +UBOOT_BINARIES_URL="https://gitlab.lan/products/u-boot/-/jobs/102537/artifacts/download?file_type=archive" +LINUX_BINARIES_URL="https://gitlab.lan/products/linux/-/jobs/221844/artifacts/download?file_type=archive" diff --git a/ringneck/build.conf b/ringneck/build.conf new file mode 100644 index 0000000..ea21c68 --- /dev/null +++ b/ringneck/build.conf @@ -0,0 +1,6 @@ +# This file needs to be valid TOML **AND** valid shell, so only store variables in there. + +UBOOT_BINARIES="u-boot-rockchip.bin" +# DO NOT MODIFY; Use maintainer-scripts/bump-binaries.py to edit the next lines automatically +UBOOT_BINARIES_URL="https://gitlab.lan/products/u-boot/-/jobs/214346/artifacts/download?file_type=archive" +LINUX_BINARIES_URL="https://gitlab.lan/products/linux/-/jobs/221842/artifacts/download?file_type=archive" diff --git a/tiger/build.conf b/tiger/build.conf new file mode 100644 index 0000000..01ede2c --- /dev/null +++ b/tiger/build.conf @@ -0,0 +1,6 @@ +# This file needs to be valid TOML **AND** valid shell, so only store variables in there. + +UBOOT_BINARIES="idbloader.img u-boot.itb" +# DO NOT MODIFY; Use maintainer-scripts/bump-binaries.py to edit the next lines automatically +UBOOT_BINARIES_URL="https://gitlab.lan/products/u-boot/-/jobs/216858/artifacts/download?file_type=archive" +LINUX_BINARIES_URL="https://gitlab.lan/products/linux/-/jobs/223018/artifacts/download?file_type=archive" |