]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson,ukify: hook up ukify, add --version option
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 Nov 2022 14:52:47 +0000 (15:52 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 7 Dec 2022 14:32:13 +0000 (15:32 +0100)
The option is added because we have a similar one for kernel-install. This
program requires python, and some people might want to skip it because of this.

The tool is installed in /usr/lib/systemd for now, since the interface might
change.

A template file is used, but there is no .in suffix.
The problem is that we'll later want to import the file as a module
for tests, but recent Python versions make it annoyingly hard to import
a module from a file without a .py suffix. imp.load_sources() works, but it
is deprecated and throws warnings.
importlib.machinery.SourceFileLoader().load_module() works, but is also
deprecated. And the documented replacements are a maze of twisted little
callbacks that result in an empty module.
So let's take the easy way out, and skip the suffix which makes it easy
to import the template as a module after adding the directory to sys.path.

meson.build
meson_options.txt
src/ukify/ukify.py

index 2fb510297124b95f2ad5de7ec907da55757a48f6..84b2a22ebeb6693a23f6acc561036dc5d91fddac 100644 (file)
@@ -712,6 +712,17 @@ if run_command(python, '-c', 'import jinja2', check : false).returncode() != 0
         error('python3 jinja2 missing')
 endif
 
+python_310 = run_command(python, '-c',
+                         'import sys; sys.exit(0 if sys.version_info >= (3,10) else 1)',
+                         check : false).returncode() == 0
+if get_option('ukify') == 'auto'
+    want_ukify = python_310
+elif get_option('ukify') == 'true' and not python310
+    error('ukify requires Python >= 3.10')
+else
+    want_ukify = get_option('ukify') == 'true'
+endif
+
 ############################################################
 
 gperf = find_program('gperf')
@@ -3991,6 +4002,18 @@ if want_tests != 'false' and want_kernel_install
              args : [exe.full_path(), loaderentry_install])
 endif
 
+if want_ukify
+   exe = custom_target(
+        'ukify',
+        input : 'src/ukify/ukify.py',
+        output : 'ukify',
+        command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'],
+        install : true,
+        install_mode : 'rwxr-xr-x',
+        install_dir : rootlibexecdir)
+   public_programs += exe
+endif
+
 ############################################################
 
 runtest_env = custom_target(
index 19e9c2d990949feffd9a5c954a278c6195f85a51..6a95955dd9254c00446e6be81d0995cbf7729c8d 100644 (file)
@@ -501,6 +501,8 @@ option('llvm-fuzz', type : 'boolean', value : false,
        description : 'build against LLVM libFuzzer')
 option('kernel-install', type: 'boolean', value: true,
        description : 'install kernel-install and associated files')
+option('ukify', type : 'combo', choices : ['auto', 'true', 'false'],
+       description : 'install ukify')
 option('analyze', type: 'boolean', value: true,
        description : 'install systemd-analyze')
 
index 4041cefc9d058af673903eacecc9934d36ccd444..d4afd88290e7e596589021f52dd1fb60a413d298 100755 (executable)
@@ -22,6 +22,8 @@ import typing
 
 import pefile
 
+__version__ = '{{GIT_VERSION}}'
+
 EFI_ARCH_MAP = {
         # host_arch glob : [efi_arch, 32_bit_efi_arch if mixed mode is supported]
         'x86_64'       : ['x64', 'ia32'],
@@ -519,6 +521,10 @@ usage: ukify [options…] linux initrd
                    action=argparse.BooleanOptionalAction,
                    help='print systemd-measure output for the UKI')
 
+    p.add_argument('--version',
+                   action='version',
+                   version=f'ukify {__version__}')
+
     opts = p.parse_args(args)
 
     if opts.cmdline and opts.cmdline.startswith('@'):