]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: Be smarter about detecting the mkosi configuration directory 36954/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 2 Apr 2025 16:15:04 +0000 (18:15 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 3 Apr 2025 08:21:54 +0000 (10:21 +0200)
Instead of always looking up two directories from the
test/integration-tests/meson.build file, let's search in up to 4
parent directories from the given meson project source root. This
allows us to just pass in meson.project_source_root() to
integration-test-wrapper.py instead of having to pass in a fixed
relative offset from the current meson file.

It'll also allow us to install the integration tests and mkosi
configuration in the future without breaking the standalone
integrationt tests functionality;

test/integration-tests/integration-test-wrapper.py
test/integration-tests/meson.build

index 9956a1df0c8f1b1cc892e6213e3f7680132121dd..f0d0de359dea6c6977f263d6d214c60e51b5b925 100755 (executable)
@@ -53,7 +53,7 @@ class Summary:
             subprocess.run(
                 [
                     args.mkosi,
-                    '--directory', os.fspath(args.meson_source_dir),
+                    '--directory', os.fspath(args.mkosi_dir),
                     '--json',
                     'summary',
                 ],
@@ -329,7 +329,7 @@ def process_coverage(args: argparse.Namespace, summary: Summary, name: str, jour
                     '--quiet',
                 ],
                 check=True,
-                cwd=os.fspath(args.meson_source_dir),
+                cwd=os.fspath(args.mkosi_dir),
             )  # fmt: skip
 
             subprocess.run(
@@ -342,7 +342,7 @@ def process_coverage(args: argparse.Namespace, summary: Summary, name: str, jour
                     '--quiet',
                 ],
                 check=True,
-                cwd=os.fspath(args.meson_source_dir),
+                cwd=os.fspath(args.mkosi_dir),
             )  # fmt: skip
 
             Path(f'{output}.new').unlink()
@@ -378,6 +378,22 @@ def main() -> None:
     parser.add_argument('mkosi_args', nargs='*')
     args = parser.parse_args()
 
+    # The meson source directory can either be the top-level repository directory or the
+    # test/integration-tests/standalone subdirectory in the repository directory. The mkosi configuration
+    # will always be a parent directory of one of these directories and at most 4 levels upwards, so don't
+    # look further than that.
+    dirs = [args.meson_source_dir] + list(args.meson_source_dir.parents)
+    for p in dirs[: min(len(dirs), 4)]:
+        if (p / 'mkosi/mkosi.conf').exists():
+            setattr(args, 'mkosi_dir', p)
+            break
+    else:
+        print(
+            f'Directory with mkosi config not found in any parent directories of {args.meson_source_dir}',
+            file=sys.stderr,
+        )
+        exit(1)
+
     if not bool(int(os.getenv('SYSTEMD_INTEGRATION_TESTS', '0'))):
         print(
             f'SYSTEMD_INTEGRATION_TESTS=1 not found in environment, skipping {args.name}',
@@ -531,7 +547,7 @@ def main() -> None:
 
     cmd = [
         args.mkosi,
-        '--directory', os.fspath(args.meson_source_dir),
+        '--directory', os.fspath(args.mkosi_dir),
         '--machine', name,
         '--ephemeral=yes',
         *(['--forward-journal', journal_file] if journal_file else []),
index 1980acc10c4dbd1f3e9c6af24430c79f28ab943b..f32a3f0c0cade92ec35fe1e5e06d61f3a89debb4 100644 (file)
@@ -101,9 +101,7 @@ endforeach
 
 foreach integration_test : integration_tests
         integration_test_args = [
-                # We don't use meson.project_source_root() because that doesn't work for running the tests
-                # standalone (see standalone/meson.build).
-                '--meson-source-dir', meson.current_source_dir() / '../..',
+                '--meson-source-dir', meson.project_source_root(),
                 '--meson-build-dir', meson.project_build_root(),
                 '--name', integration_test['name'],
                 '--storage', integration_test['storage'],