From 12d8bb84b16f06d09228f08dc1ed7d45438f71e3 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Thu, 29 Oct 2026 13:26:58 +0100 Subject: [PATCH] mkosi: share packaging pins with other build tools The packaging references are part of mkosi's configuration, so tine can't build a checkout with the same pinned spec. Let's share the pins in one JSON file keyed by distro and keep mkosi, the packaging updater and Packit using it. --- .packit.yml | 8 ++- docs/HACKING.md | 3 + docs/RELEASE.md | 2 +- mkosi/mkosi.pkgenv/mkosi.conf.d/arch.conf | 6 +- .../mkosi.conf.d/centos-fedora.conf | 6 +- .../mkosi.conf.d/debian-ubuntu.conf | 3 - .../mkosi.pkgenv/mkosi.conf.d/hyperscale.conf | 6 +- mkosi/mkosi.pkgenv/mkosi.conf.d/nura.conf | 3 - mkosi/mkosi.pkgenv/mkosi.conf.d/opensuse.conf | 3 - mkosi/mkosi.sync | 4 ++ tools/fetch-distro.py | 57 +++++++++---------- tools/packaging.json | 32 +++++++++++ 12 files changed, 75 insertions(+), 58 deletions(-) create mode 100644 tools/packaging.json diff --git a/.packit.yml b/.packit.yml index 482997c3769..34e1a81fab4 100644 --- a/.packit.yml +++ b/.packit.yml @@ -10,7 +10,7 @@ files_to_sync: # `git describe` returns in systemd's case 'v245-xxx' which breaks RPM version # detection (that expects 245-xxxx'). Let's tweak the version string accordingly upstream_tag_template: "v{version}" -srpm_build_deps: [] +srpm_build_deps: [jq] actions: get-current-version: @@ -18,8 +18,10 @@ actions: post-upstream-clone: # Use the Fedora Rawhide specfile - - git clone https://src.fedoraproject.org/rpms/systemd .packit_rpm - - bash -c 'git -C .packit_rpm checkout "$(grep GIT_COMMIT= mkosi/mkosi.pkgenv/mkosi.conf.d/centos-fedora.conf | cut -d= -f2)"' + - >- + bash -ec 'read -r url branch commit < <(jq -r ".fedora // empty | [.url, .branch, .commit] | @tsv" tools/packaging.json); + git clone --branch "$branch" "$url" .packit_rpm; + git -C .packit_rpm checkout "$commit"' - bash -c 'echo "%bcond upstream 1" > .packit_rpm/systemd.spec.new' - bash -c 'echo "%define meson_extra_configure_options --werror" >> .packit_rpm/systemd.spec.new' - bash -c 'cat .packit_rpm/systemd.spec >> .packit_rpm/systemd.spec.new' diff --git a/docs/HACKING.md b/docs/HACKING.md index 5777392142a..2c504a22d6b 100644 --- a/docs/HACKING.md +++ b/docs/HACKING.md @@ -36,6 +36,9 @@ or via your distribution's package manager. Note that systemd regularly adopts newer mkosi features that are not in an official release yet so there's a good chance that your distribution's packaged version of mkosi will be too old. +Install `jq` on the host as well. The packaging sync script runs before the +mkosi tools tree is available. + Make sure to read the "Unprivileged User Namespaces" section in the mkosi documentation (run `mkosi documentation` to view the mkosi docs) and apply any necessary instructions to make sure unprivileged user namespaces work on your system. diff --git a/docs/RELEASE.md b/docs/RELEASE.md index 8d3a5130702..846ba396dce 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -29,7 +29,7 @@ SPDX-License-Identifier: LGPL-2.1-or-later 20. [FINAL] Edit in the new -stable branch `.obs/workflows.yml`, changing `project` from `system:systemd` to `system:systemd:stable` and the branch from `main` to `v${version}-stable`. This should be backported to older active stable branches too. 21. [FINAL] Build and upload the documentation (on the -stable branch): `ninja -C build doc-sync` 22. [FINAL] Create a new `ci/v${version}-stable` branch for deb package builds on https://github.com/systemd/systemd-deb -23. [FINAL] Switch `.semaphore/semaphore-runner.sh` and `mkosi/mkosi.pkgenv/mkosi.conf.d/debian-ubuntu.conf` +23. [FINAL] Switch `.semaphore/semaphore-runner.sh` and the `debian.branch` field in `tools/packaging.json` to the new `ci/v${version}-stable` branch on the -stable branch 24. [FINAL] Switch `versionrewrite-pattern` and `versionrewrite-replacement` to release mode in https://build.opensuse.org/projects/system:systemd/packages/systemd/files/_service?expand=1 25. [FINAL] Change the Github Pages branch to the newly created branch (https://github.com/systemd/systemd/settings/pages) and set the 'Custom domain' to 'systemd.io' diff --git a/mkosi/mkosi.pkgenv/mkosi.conf.d/arch.conf b/mkosi/mkosi.pkgenv/mkosi.conf.d/arch.conf index a1278564a3f..9d20a652fe7 100644 --- a/mkosi/mkosi.pkgenv/mkosi.conf.d/arch.conf +++ b/mkosi/mkosi.pkgenv/mkosi.conf.d/arch.conf @@ -4,8 +4,4 @@ Distribution=arch [Build] -Environment= - GIT_URL=https://gitlab.archlinux.org/archlinux/packaging/packages/systemd.git - GIT_BRANCH=main - GIT_COMMIT=1a366822100fc46edec7308b8cb2424fde7f037f - PKG_SUBDIR=arch +Environment=PKG_SUBDIR=arch diff --git a/mkosi/mkosi.pkgenv/mkosi.conf.d/centos-fedora.conf b/mkosi/mkosi.pkgenv/mkosi.conf.d/centos-fedora.conf index 1f919d56766..50a030290f3 100644 --- a/mkosi/mkosi.pkgenv/mkosi.conf.d/centos-fedora.conf +++ b/mkosi/mkosi.pkgenv/mkosi.conf.d/centos-fedora.conf @@ -6,8 +6,4 @@ Distribution=|centos Profiles=!hyperscale [Build] -Environment= - GIT_URL=https://src.fedoraproject.org/rpms/systemd.git - GIT_BRANCH=rawhide - GIT_COMMIT=57cbcf979ce2dd872a871c59e87d2c65dfa996e6 - PKG_SUBDIR=fedora +Environment=PKG_SUBDIR=fedora diff --git a/mkosi/mkosi.pkgenv/mkosi.conf.d/debian-ubuntu.conf b/mkosi/mkosi.pkgenv/mkosi.conf.d/debian-ubuntu.conf index d4aaa912aab..ceb9046d3cc 100644 --- a/mkosi/mkosi.pkgenv/mkosi.conf.d/debian-ubuntu.conf +++ b/mkosi/mkosi.pkgenv/mkosi.conf.d/debian-ubuntu.conf @@ -6,8 +6,5 @@ Distribution=|ubuntu [Build] Environment= - GIT_URL=https://github.com/systemd/systemd-deb.git GIT_SUBDIR=debian - GIT_BRANCH=deb/main - GIT_COMMIT=23cf74c5cde1e6c8b17b2157c7660a6a97c7a092 PKG_SUBDIR=debian diff --git a/mkosi/mkosi.pkgenv/mkosi.conf.d/hyperscale.conf b/mkosi/mkosi.pkgenv/mkosi.conf.d/hyperscale.conf index 5059d861611..87fafaf3683 100644 --- a/mkosi/mkosi.pkgenv/mkosi.conf.d/hyperscale.conf +++ b/mkosi/mkosi.pkgenv/mkosi.conf.d/hyperscale.conf @@ -7,8 +7,4 @@ Profiles=hyperscale Distribution=centos [Build] -Environment= - GIT_URL=https://gitlab.com/CentOS/Hyperscale/rpms/systemd.git - GIT_BRANCH=c10s-sig-hyperscale - GIT_COMMIT=417b671b173ea6271c00a3c605215b5f68795a3a - PKG_SUBDIR=hyperscale +Environment=PKG_SUBDIR=hyperscale diff --git a/mkosi/mkosi.pkgenv/mkosi.conf.d/nura.conf b/mkosi/mkosi.pkgenv/mkosi.conf.d/nura.conf index cb5bfa74616..7da8ee07fbf 100644 --- a/mkosi/mkosi.pkgenv/mkosi.conf.d/nura.conf +++ b/mkosi/mkosi.pkgenv/mkosi.conf.d/nura.conf @@ -5,8 +5,5 @@ Distribution=nura [Build] Environment= - GIT_URL=https://gitlab.postmarketos.org/postmarketOS/pmaports GIT_SUBDIR=extra-repos/systemd/systemd - GIT_BRANCH=main - GIT_COMMIT=7a6b81a4f1a7a510d088a5874bebcf2b200b69b3 PKG_SUBDIR=nura diff --git a/mkosi/mkosi.pkgenv/mkosi.conf.d/opensuse.conf b/mkosi/mkosi.pkgenv/mkosi.conf.d/opensuse.conf index c9203286d8c..4ca6100e254 100644 --- a/mkosi/mkosi.pkgenv/mkosi.conf.d/opensuse.conf +++ b/mkosi/mkosi.pkgenv/mkosi.conf.d/opensuse.conf @@ -5,8 +5,5 @@ Distribution=opensuse [Build] Environment= - GIT_URL=https://github.com/bmwiedemann/openSUSE GIT_SUBDIR=packages/s/systemd - GIT_BRANCH=master - GIT_COMMIT=60fbc2d95581a933f9dcdfdb8d7e27d2a7d13e35 PKG_SUBDIR=opensuse diff --git a/mkosi/mkosi.sync b/mkosi/mkosi.sync index 8bac44f4abe..7862e6c2486 100755 --- a/mkosi/mkosi.sync +++ b/mkosi/mkosi.sync @@ -13,6 +13,10 @@ if [[ -z "${PKG_SUBDIR:-}" ]]; then exit 0 fi +read -r GIT_URL GIT_BRANCH GIT_COMMIT < <( + jq -r --arg distro "$PKG_SUBDIR" '.[$distro] // empty | [.url, .branch, .commit] | @tsv' tools/packaging.json +) + if [[ -d "pkg/$PKG_SUBDIR/.git" ]]; then if [[ "$(git -C "pkg/$PKG_SUBDIR" rev-parse HEAD 2>/dev/null)" == "$GIT_COMMIT" ]]; then exit 0 diff --git a/tools/fetch-distro.py b/tools/fetch-distro.py index a94b8071868..518e3d09791 100755 --- a/tools/fetch-distro.py +++ b/tools/fetch-distro.py @@ -12,6 +12,8 @@ import shlex import subprocess from pathlib import Path +PACKAGING = Path('tools/packaging.json') + def parse_args(): p = argparse.ArgumentParser( @@ -46,7 +48,11 @@ def read_config(distro: str): data = json.loads(text) images = {image['Image']: image for image in data['Images']} - return images['build'] + environment = images['build']['Environment'] + return json.loads(PACKAGING.read_text())[environment['PKG_SUBDIR']] | { + 'subdir': environment.get('GIT_SUBDIR'), + 'pkg_subdir': environment['PKG_SUBDIR'], + } def commit_file(distro: str, files: list[Path], commit: str, changes: str): @@ -58,10 +64,10 @@ def commit_file(distro: str, files: list[Path], commit: str, changes: str): def checkout_distro(args, distro: str, config: dict): - url = config['Environment']['GIT_URL'] - branch = config['Environment']['GIT_BRANCH'] - subdir = config['Environment'].get('GIT_SUBDIR') - pkg_subdir = config['Environment']['PKG_SUBDIR'] + url = config['url'] + branch = config['branch'] + subdir = config['subdir'] + pkg_subdir = config['pkg_subdir'] dest = Path(f'pkg/{pkg_subdir}') if dest.exists(): @@ -101,10 +107,10 @@ def checkout_distro(args, distro: str, config: dict): def update_distro(args, distro: str, config: dict): - branch = config['Environment']['GIT_BRANCH'] - subdir = config['Environment'].get('GIT_SUBDIR') - old_commit = config['Environment']['GIT_COMMIT'] - pkg_subdir = config['Environment']['PKG_SUBDIR'] + branch = config['branch'] + subdir = config['subdir'] + old_commit = config['commit'] + pkg_subdir = config['pkg_subdir'] if args.fetch: cmd = [ @@ -149,29 +155,20 @@ def update_distro(args, distro: str, config: dict): print(f'+ {shlex.join(cmd)}') changes = subprocess.check_output(cmd, text=True).strip() - conf_dir = Path('mkosi/mkosi.pkgenv/mkosi.conf.d') - files = conf_dir.glob('*.conf') - for file in files: - s = file.read_text() - if old_commit in s: - print(f'{distro}: {file}: found old hash, updating…') - new = s.replace(old_commit, new_commit) - assert new != s - file.write_text(new) - tocommit = [file] + pins = json.loads(PACKAGING.read_text()) + pins[pkg_subdir]['commit'] = new_commit + PACKAGING.write_text(json.dumps(pins, indent=2) + '\n') + tocommit = [PACKAGING] - if distro == 'fedora': - packit = Path('.packit.yml') - s = packit.read_text() - assert old_commit in s - new = s.replace(old_commit, new_commit) - packit.write_text(new) - tocommit += [packit] + if pkg_subdir == 'fedora': + packit = Path('.packit.yml') + s = packit.read_text() + assert old_commit in s + new = s.replace(old_commit, new_commit) + packit.write_text(new) + tocommit += [packit] - commit_file(distro, tocommit, new_commit, changes) - break - else: - raise ValueError(f'{distro}: hash {new_commit} not found under {conf_dir}') + commit_file(distro, tocommit, new_commit, changes) if __name__ == '__main__': diff --git a/tools/packaging.json b/tools/packaging.json new file mode 100644 index 00000000000..3785d038b30 --- /dev/null +++ b/tools/packaging.json @@ -0,0 +1,32 @@ +{ + "arch": { + "url": "https://gitlab.archlinux.org/archlinux/packaging/packages/systemd.git", + "branch": "main", + "commit": "1a366822100fc46edec7308b8cb2424fde7f037f" + }, + "debian": { + "url": "https://github.com/systemd/systemd-deb.git", + "branch": "deb/main", + "commit": "23cf74c5cde1e6c8b17b2157c7660a6a97c7a092" + }, + "fedora": { + "url": "https://src.fedoraproject.org/rpms/systemd.git", + "branch": "rawhide", + "commit": "57cbcf979ce2dd872a871c59e87d2c65dfa996e6" + }, + "hyperscale": { + "url": "https://gitlab.com/CentOS/Hyperscale/rpms/systemd.git", + "branch": "c10s-sig-hyperscale", + "commit": "417b671b173ea6271c00a3c605215b5f68795a3a" + }, + "nura": { + "url": "https://gitlab.postmarketos.org/postmarketOS/pmaports", + "branch": "main", + "commit": "7a6b81a4f1a7a510d088a5874bebcf2b200b69b3" + }, + "opensuse": { + "url": "https://github.com/bmwiedemann/openSUSE", + "branch": "master", + "commit": "60fbc2d95581a933f9dcdfdb8d7e27d2a7d13e35" + } +}