]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mkosi: Rework how the pkgenv environment variables are set
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 1 Sep 2025 15:29:54 +0000 (17:29 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 25 Nov 2025 10:02:34 +0000 (11:02 +0100)
Instead of including distribution specific files in the subimages,
let's have one common mkosi.pkgenv/ directory that handles all the
matching which is then included in the subimages.

This gives us more control on exactly how we do the matching.

17 files changed:
.packit.yml
mkosi/mkosi.conf
mkosi/mkosi.images/build/mkosi.conf
mkosi/mkosi.images/build/mkosi.conf.d/arch/mkosi.conf
mkosi/mkosi.images/build/mkosi.conf.d/centos-fedora/mkosi.conf
mkosi/mkosi.images/build/mkosi.conf.d/debian-ubuntu/mkosi.conf
mkosi/mkosi.images/build/mkosi.conf.d/opensuse/mkosi.conf
mkosi/mkosi.pkgenv/mkosi.conf.d/arch.conf [moved from mkosi/mkosi.conf.d/arch/mkosi.conf.d/pkgenv.conf with 90% similarity]
mkosi/mkosi.pkgenv/mkosi.conf.d/centos-fedora.conf [moved from mkosi/mkosi.conf.d/centos-fedora/mkosi.conf.d/pkgenv.conf with 82% similarity]
mkosi/mkosi.pkgenv/mkosi.conf.d/debian-ubuntu.conf [moved from mkosi/mkosi.conf.d/debian-ubuntu/mkosi.conf.d/pkgenv.conf with 84% similarity]
mkosi/mkosi.pkgenv/mkosi.conf.d/opensuse.conf [moved from mkosi/mkosi.conf.d/opensuse/mkosi.conf.d/pkgenv.conf with 89% similarity]
mkosi/mkosi.tools.conf/mkosi.conf
mkosi/mkosi.tools.conf/mkosi.conf.d/arch.conf
mkosi/mkosi.tools.conf/mkosi.conf.d/centos-fedora.conf
mkosi/mkosi.tools.conf/mkosi.conf.d/debian-ubuntu.conf
mkosi/mkosi.tools.conf/mkosi.conf.d/opensuse.conf
tools/fetch-distro.py

index d9c7bc41c475ddce18488f48c3dab536f5d822d6..c2a719a212c2a16d87f7cf1043d46ad74b93ba9e 100644 (file)
@@ -19,7 +19,7 @@ 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.conf.d/centos-fedora/mkosi.conf.d/pkgenv.conf | cut -d= -f2)"'
+    - bash -c 'git -C .packit_rpm checkout "$(grep GIT_COMMIT= mkosi/mkosi.pkgenv/mkosi.conf.d/centos-fedora.conf | cut -d= -f2)"'
     - 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'
index 2cdb79f9cabc7f6f5548432b47d91ce74e79176b..8c1a08abab83f302f8b467a9bda6a0df8e560dbc 100644 (file)
@@ -156,3 +156,4 @@ KVM=yes
 [Include]
 Include=%D/mkosi/mkosi.sanitizers
         %D/mkosi/mkosi.coverage
+        %D/mkosi/mkosi.pkgenv
index b710f801ee8d100e8b44ad7dff1806e9bf6f2a9b..2870a4e32cd0538009b449034279470e4e36008e 100644 (file)
@@ -1,5 +1,8 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
+[Include]
+Include=%D/mkosi/mkosi.pkgenv
+
 [Content]
 Packages=
         clang
index 9809fbc252218251d6182443e03f4d64ddddfa3f..d7a79d11c1051244a46508d84e9b15de3eac643f 100644 (file)
@@ -3,9 +3,6 @@
 [Match]
 Distribution=arch
 
-[Include]
-Include=%D/mkosi/mkosi.conf.d/arch/mkosi.conf.d/pkgenv.conf
-
 [Content]
 Packages=
         base
index 438c0ab4ef8a10789f83f30b1bac411b9979387f..4d0ca8917d83fd40d0921b3d8f7a6ef71334ca33 100644 (file)
@@ -4,9 +4,6 @@
 Distribution=|centos
 Distribution=|fedora
 
-[Include]
-Include=%D/mkosi/mkosi.conf.d/centos-fedora/mkosi.conf.d/pkgenv.conf
-
 [Content]
 Packages=
         clang-devel
index 240f357b989d90ccc0b1277405c101d98ee6ffdf..55d7b1d9045dbe0072e4ce45ce642676c1dea98b 100644 (file)
@@ -4,9 +4,6 @@
 Distribution=|debian
 Distribution=|ubuntu
 
-[Include]
-Include=%D/mkosi/mkosi.conf.d/debian-ubuntu/mkosi.conf.d/pkgenv.conf
-
 [Content]
 Packages=
         apt
index 68ae1b33f0627e40f7a68fa16a722b1cc4fef0c2..70a1b31b641964740337434db5bb8483a0a72841 100644 (file)
@@ -3,9 +3,6 @@
 [Match]
 Distribution=opensuse
 
-[Include]
-Include=%D/mkosi/mkosi.conf.d/opensuse/mkosi.conf.d/pkgenv.conf
-
 [Content]
 Packages=
         clang
similarity index 90%
rename from mkosi/mkosi.conf.d/arch/mkosi.conf.d/pkgenv.conf
rename to mkosi/mkosi.pkgenv/mkosi.conf.d/arch.conf
index 07e4f48d3b04dc17c006d77b78ad51d7f65b0a1e..ba8508925e35447cb4b140b95c8b140849ad07ed 100644 (file)
@@ -1,5 +1,8 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
+[Match]
+Distribution=arch
+
 [Build]
 Environment=
         GIT_URL=https://gitlab.archlinux.org/archlinux/packaging/packages/systemd.git
similarity index 82%
rename from mkosi/mkosi.conf.d/centos-fedora/mkosi.conf.d/pkgenv.conf
rename to mkosi/mkosi.pkgenv/mkosi.conf.d/centos-fedora.conf
index 75d3d4daa2ee1c5a850d15e5d14950d9005fa61a..58d27fb34edfb98e2380ada818f3531d652ed04d 100644 (file)
@@ -1,5 +1,9 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
+[Match]
+Distribution=|fedora
+Distribution=|centos
+
 [Build]
 Environment=
         GIT_URL=https://src.fedoraproject.org/rpms/systemd.git
similarity index 84%
rename from mkosi/mkosi.conf.d/debian-ubuntu/mkosi.conf.d/pkgenv.conf
rename to mkosi/mkosi.pkgenv/mkosi.conf.d/debian-ubuntu.conf
index 532d1b8f91a84b3fc76b6ee73d3e6d29c41e30ec..38607c9818b50cd161b701728512a04635ba5dcc 100644 (file)
@@ -1,5 +1,9 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
+[Match]
+Distribution=|debian
+Distribution=|ubuntu
+
 [Build]
 Environment=
         GIT_URL=https://salsa.debian.org/systemd-team/systemd.git
similarity index 89%
rename from mkosi/mkosi.conf.d/opensuse/mkosi.conf.d/pkgenv.conf
rename to mkosi/mkosi.pkgenv/mkosi.conf.d/opensuse.conf
index dedcb4b2b7924b950028498bea48bb905dd4bd2f..6a2c8868f05474c19d966fac8cb578925e82fcf9 100644 (file)
@@ -1,5 +1,8 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
+[Match]
+Distribution=opensuse
+
 [Build]
 Environment=
         GIT_URL=https://github.com/bmwiedemann/openSUSE
index 4befc518b17bbb7fd2079387e786907675dfff5d..1ec5a3ef0778bbac963b262cfc6cdbe0d8479924 100644 (file)
@@ -1,5 +1,8 @@
 # SPDX-License-Identifier: LGPL-2.1-or-later
 
+[Include]
+Include=%D/mkosi/mkosi.pkgenv
+
 [Content]
 SyncScripts=%D/mkosi/mkosi.sync
 Packages=
index 382391ca706cc877ef810e3dd3d3fce53f5342b6..2348d30286827c80ac220e69b98499f7740cedf2 100644 (file)
@@ -3,9 +3,6 @@
 [Match]
 Distribution=arch
 
-[Include]
-Include=%D/mkosi/mkosi.conf.d/arch/mkosi.conf.d/pkgenv.conf
-
 [Content]
 PrepareScripts=%D/mkosi/mkosi.images/build/mkosi.conf.d/arch/mkosi.prepare
 Packages=
index f75f83723f2afb20330c566011e2b389dda2096b..7c61681117263ea4bfa526d08e85954a17c206c9 100644 (file)
@@ -4,9 +4,6 @@
 Distribution=|fedora
 Distribution=|centos
 
-[Include]
-Include=%D/mkosi/mkosi.conf.d/centos-fedora/mkosi.conf.d/pkgenv.conf
-
 [Content]
 PrepareScripts=%D/mkosi/mkosi.images/build/mkosi.conf.d/centos-fedora/mkosi.prepare
 Packages=
index c62ed1c4ddb3b34764592bd3cd65e7be351fc6d6..9fdf89bfb592e5ddd36ad585a4e3dc9e39889ff1 100644 (file)
@@ -4,9 +4,6 @@
 Distribution=|debian
 Distribution=|ubuntu
 
-[Include]
-Include=%D/mkosi/mkosi.conf.d/debian-ubuntu/mkosi.conf.d/pkgenv.conf
-
 [Content]
 PrepareScripts=%D/mkosi/mkosi.images/build/mkosi.conf.d/debian-ubuntu/mkosi.prepare
 Packages=
index 844a3254b5863defe314f1fa7ae70514cab465bc..b698094618733a20b617ede7be69ad9e8e92ffc1 100644 (file)
@@ -3,9 +3,6 @@
 [Match]
 Distribution=opensuse
 
-[Include]
-Include=%D/mkosi/mkosi.conf.d/opensuse/mkosi.conf.d/pkgenv.conf
-
 [Content]
 PrepareScripts=%D/mkosi/mkosi.images/build/mkosi.conf.d/opensuse/mkosi.prepare
 Packages=
index fa60e60db7df8ca03d7ffac6c7ae4703dae1b1d9..2dad51be24cf6f098f9a6cbdebbb0e9d8e607676 100755 (executable)
@@ -31,10 +31,13 @@ def parse_args():
         action='store_true',
         default=False,
     )
+    p.add_argument('--profile')
     return p.parse_args()
 
 def read_config(distro: str):
     cmd = ['mkosi', '--json', '-d', distro, 'summary']
+    if args.profile:
+        cmd += ['--profile', args.profile]
     print(f"+ {shlex.join(cmd)}")
     text = subprocess.check_output(cmd, text=True)
 
@@ -53,14 +56,15 @@ def commit_file(distro: str, files: list[Path], commit: str, changes: str):
     subprocess.check_call(cmd)
 
 def checkout_distro(args, distro: str, config: dict):
-    dest = Path(f'pkg/{distro}')
-    if dest.exists():
-        print(f'{dest} already exists.')
-        return
-
     url = config['Environment']['GIT_URL']
     branch = config['Environment']['GIT_BRANCH']
     subdir = config['Environment'].get('GIT_SUBDIR')
+    pkg_subdir = config['Environment']['PKG_SUBDIR']
+
+    dest = Path(f'pkg/{pkg_subdir}')
+    if dest.exists():
+        print(f'{dest} already exists.')
+        return
 
     # Do not checkout the full sources if the package is in a subdirectory,
     # a sparse checkout will be done after
@@ -81,12 +85,12 @@ def checkout_distro(args, distro: str, config: dict):
 
     # Sparse checkout if the package is in a subdirectory
     if subdir is not None:
-        cmd = ['git', '-C', f'pkg/{distro}', 'sparse-checkout', 'set',
+        cmd = ['git', '-C', f'pkg/{pkg_subdir}', 'sparse-checkout', 'set',
                '--no-cone', f'{subdir}']
         print(f"+ {shlex.join(cmd)}")
         subprocess.check_call(cmd)
 
-        cmd = ['git', '-C', f'pkg/{distro}', 'checkout', 'HEAD']
+        cmd = ['git', '-C', f'pkg/{pkg_subdir}', 'checkout', 'HEAD']
         print(f"+ {shlex.join(cmd)}")
         subprocess.check_call(cmd)
 
@@ -96,18 +100,19 @@ 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']
 
     if args.fetch:
-        cmd = ['git', '-C', f'pkg/{distro}', 'fetch', 'origin', '-v',
+        cmd = ['git', '-C', f'pkg/{pkg_subdir}', 'fetch', 'origin', '-v',
                f'{branch}:remotes/origin/{branch}']
         print(f"+ {shlex.join(cmd)}")
         subprocess.check_call(cmd)
 
-    cmd = ['git', '-C', f'pkg/{distro}', 'switch', branch]
+    cmd = ['git', '-C', f'pkg/{pkg_subdir}', 'switch', branch]
     print(f"+ {shlex.join(cmd)}")
     subprocess.check_call(cmd)
 
-    cmd = ['git', '-C', f'pkg/{distro}', 'log', '-n1', '--format=%H',
+    cmd = ['git', '-C', f'pkg/{pkg_subdir}', 'log', '-n1', '--format=%H',
            f'refs/remotes/origin/{branch}']
     if subdir is not None:
         cmd += [f'{subdir}']
@@ -115,10 +120,10 @@ def update_distro(args, distro: str, config: dict):
     new_commit = subprocess.check_output(cmd, text=True).strip()
 
     if old_commit == new_commit:
-        print(f'{distro}: commit {new_commit!s} is still fresh')
+        print(f'{pkg_subdir}: commit {new_commit!s} is still fresh')
         return
 
-    cmd = ['git', '-C', f'pkg/{distro}', 'log', '--graph', '--first-parent',
+    cmd = ['git', '-C', f'pkg/{pkg_subdir}', 'log', '--graph', '--first-parent',
            '--pretty=oneline', '--no-decorate', '--abbrev-commit', '--abbrev=10',
            f'{old_commit}..{new_commit}']
     if subdir is not None:
@@ -126,8 +131,8 @@ 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.conf.d')
-    files = conf_dir.glob('**/pkgenv.conf')
+    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: