From: Daan De Meyer Date: Tue, 8 Apr 2025 09:19:34 +0000 (+0200) Subject: Allow MinimumVersion to be a git sha X-Git-Tag: v26~267 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc7fb750dd3a6c0b6f0d04bfe785145799be75b6;p=thirdparty%2Fmkosi.git Allow MinimumVersion to be a git sha In systemd we very often require newer mkosi git commits which means that setting MinimumVersion=25~devel doesn't work anymore. Let's allow the MinimumVersion= to be a git sha so that we can enforce the mkosi version to be new enough. We skip git commit checks if we're in the sandbox since mkosi will be a zipapp there and we won't have access to the git repository to do the check. --- diff --git a/mkosi/config.py b/mkosi/config.py index c0613847a..15bf568f2 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -1463,22 +1463,33 @@ def config_parse_vsock_cid(value: Optional[str], old: Optional[int]) -> Optional return cid -def config_parse_minimum_version( - value: Optional[str], - old: Optional[GenericVersion], -) -> Optional[GenericVersion]: +def config_parse_minimum_version(value: Optional[str], old: Optional[str]) -> Optional[str]: if not value: return old + if len(value) == 40 and all(c.isalnum() for c in value): + if not in_sandbox(): + gitdir = Path(__file__).parent.parent + if not (gitdir / ".git").exists(): + die("Cannot check mkosi git version, not running from a git repository") + + result = run(["git", "-C", gitdir, "merge-base", "--is-ancestor", value, "HEAD"], check=False) + if result.returncode == 1: + die(f"mkosi commit {value} or newer is required by this configuration") + elif result.returncode != 0: + die(f"Failed to check if mkosi git checkout is newer than commit {value}") + + return value + new = GenericVersion(value) if new > __version__: die(f"mkosi {new} or newer is required by this configuration (found {__version__})") if not old: - return new + return value - return max(old, new) + return value if new > old else old def file_run_or_read(file: Path) -> str: @@ -1887,7 +1898,7 @@ class Config: profiles: list[str] files: list[Path] dependencies: list[str] - minimum_version: Optional[GenericVersion] + minimum_version: Optional[str] pass_environment: list[str] distribution: Distribution diff --git a/mkosi/resources/man/mkosi.1.md b/mkosi/resources/man/mkosi.1.md index ad6bfd78b..700d25882 100644 --- a/mkosi/resources/man/mkosi.1.md +++ b/mkosi/resources/man/mkosi.1.md @@ -2166,6 +2166,12 @@ config file is read: : The minimum **mkosi** version required to build this configuration. If specified multiple times, the highest specified version is used. + The minimum version can also be specified as a unabbreviated git + commit hash, in which case mkosi must be executed from a git + checkout and the specified git commit hash must be an ancestor of + the currently checked out git commit in the repository that mkosi is + being executed from. + `ConfigureScripts=`, `--configure-script=` : Takes a comma-separated list of paths to executables that are used as the configure scripts for this image. See the **Scripts** section for diff --git a/tests/test_json.py b/tests/test_json.py index 11cd2d7ef..66f561122 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -43,7 +43,6 @@ from mkosi.config import ( VsockCID, ) from mkosi.distributions import Distribution -from mkosi.versioncomp import GenericVersion @pytest.mark.parametrize("path", [None, "/baz/qux"]) @@ -509,7 +508,7 @@ def test_config() -> None: manifest_format=[ManifestFormat.json, ManifestFormat.changelog], microcode_host=True, devicetree=Path("freescale/imx8mm-verdin-nonwifi-dev.dtb"), - minimum_version=GenericVersion("123"), + minimum_version="123", mirror=None, nspawn_settings=None, openpgp_tool="gpg",