Files
systemd/tools/fetch-mkosi.py
Daan De Meyer c7113f6b3c ci: run the musl build & test under mkosi with a postmarketOS tools tree
Drop the standalone Unit-tests (musl) workflow that ran on an Alpine sandbox
spun up by jirutka/setup-alpine, and merge it into unit-tests.yml as a new
build-musl job that provisions a postmarketOS tools tree via mkosi and runs
the meson build + test suite through 'mkosi box'. postmarketOS is musl-native,
so the musl-gcc / -idirafter /usr/include wrappers the Fedora tools tree
needed are gone; the linter.yml's own musl build step also goes away since
the unit-tests workflow now covers it (and tests it).

postmarketOS doesn't ship a downstream systemd packaging spec, so the new
tools tree config in mkosi.tools.conf/mkosi.conf.d/postmarketos.conf does not
set PrepareScripts and lists build deps manually. mkosi.sync now early-exits
when PKG_SUBDIR is unset so the missing pkgenv entry doesn't trip set -u.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-20 17:22:35 +00:00

116 lines
2.8 KiB
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
"""
Check out mkosi into specified location.
With -u, if changed, commit the latest hash.
"""
import argparse
import re
import shlex
import subprocess
from pathlib import Path
URL = 'https://github.com/systemd/mkosi'
BRANCH = 'main' # We only want to ever use commits on upstream 'main' branch
CONFIG = Path('mkosi/mkosi.conf')
WORKFLOWS = [
Path('.github/workflows') / f for f in ['mkosi.yml', 'coverage.yml', 'linter.yml', 'unit-tests.yml']
]
def parse_args():
p = argparse.ArgumentParser(
description=__doc__,
)
p.add_argument(
'dir',
type=Path,
)
p.add_argument(
'--update',
'-u',
action='store_true',
default=False,
)
return p.parse_args()
def read_config():
print(f'Reading {CONFIG}…')
c = CONFIG.read_text()
matches = [
m.group(1) for m in re.finditer('^\s*MinimumVersion=commit:([a-z0-9]{40})\s*$', c, re.MULTILINE)
]
assert len(matches) == 1
return matches[0]
def commit_file(files: list[Path], commit: str, changes: str):
message = '\n'.join((f'mkosi: update mkosi ref to {commit}', '', changes))
cmd = ['git', 'commit', '-m', message, *(str(file) for file in files)]
print(f'+ {shlex.join(cmd)}')
subprocess.check_call(cmd)
def checkout_mkosi(args):
if args.dir.exists():
print(f'{args.dir} already exists.')
return
cmd = [
'git',
'clone',
URL,
f'--branch={BRANCH}',
args.dir.as_posix(),
]
print(f'+ {shlex.join(cmd)}')
subprocess.check_call(cmd)
def update_mkosi(args):
old_commit = read_config()
cmd = ['git', '-C', args.dir.as_posix(), 'rev-parse', f'refs/remotes/origin/{BRANCH}']
print(f'+ {shlex.join(cmd)}')
new_commit = subprocess.check_output(cmd, text=True).strip()
if old_commit == new_commit:
print(f'mkosi: commit {new_commit!s} is still fresh')
return
cmd = [
'git',
'-C', args.dir.as_posix(),
'log',
'--graph',
'--no-merges',
'--pretty=oneline',
'--no-decorate',
'--abbrev-commit',
'--abbrev=10',
f'{old_commit}..{new_commit}',
] # fmt: skip
print(f'+ {shlex.join(cmd)}')
changes = subprocess.check_output(cmd, text=True).strip()
for f in [CONFIG, *WORKFLOWS]:
s = f.read_text()
assert old_commit in s
print(f'mkosi: {f}: found old hash, updating…')
new = s.replace(old_commit, new_commit)
assert new != s
f.write_text(new)
commit_file([CONFIG, *WORKFLOWS], new_commit, changes)
if __name__ == '__main__':
args = parse_args()
checkout_mkosi(args)
if args.update:
update_mkosi(args)