]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
meson: reuse f strings where possible
authorEmil Velikov <emil.l.velikov@gmail.com>
Sun, 9 Nov 2025 22:21:44 +0000 (22:21 +0000)
committerLucas De Marchi <demarchi@kernel.org>
Tue, 3 Feb 2026 04:59:03 +0000 (22:59 -0600)
With meson 0.61 we can use f strings, over the explicit .format().
Multi-line f-strings are introduced with meson 0.63, which we don't
require yet, plus it's not like we have many instances.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lucas De Marchi <demarchi@kernel.org>
Link: https://github.com/kmod-project/kmod/pull/pull/400
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
libkmod/docs/meson.build
man/meson.build
meson.build
testsuite/meson.build

index b4d41cc36ad7dd653e1a5facd28cf0265c19c28c..eefec18d7f0732b88f367d9eb943ef6e68adff1b 100644 (file)
@@ -10,12 +10,12 @@ built_docs = gnome.gtkdoc(
   'libkmod',
   content_files : version_file,
   ignore_headers : [
-    '@0@/libkmod/libkmod-index.h'.format(meson.project_source_root()),
-    '@0@/libkmod/libkmod-internal-file.h'.format(meson.project_source_root()),
-    '@0@/libkmod/libkmod-internal.h'.format(meson.project_source_root()),
+    f'@project_source_root@/libkmod/libkmod-index.h',
+    f'@project_source_root@/libkmod/libkmod-internal-file.h',
+    f'@project_source_root@/libkmod/libkmod-internal.h',
   ],
   scan_args : '--ignore-decorators="KMOD_EXPORT"',
-  src_dir : '@0@/libkmod/'.format(meson.project_source_root()),
+  src_dir : f'@project_source_root@/libkmod/',
   namespace : 'kmod',
   module_version : '3',
   main_xml : 'libkmod-docs.xml',
index 605510eac43c49ff544145ccc3b95172f438a611..6731417c4d5da0da096c342b36e45359ace89af5 100644 (file)
@@ -17,7 +17,7 @@ foreach tuple : _man_pages
   man = tuple[1]
 
   custom_target(
-    'man_@0@_@1@'.format(section, man),
+    f'man_@section@_@man@',
     command : [
       build_scdoc,
       scdoc,
@@ -26,11 +26,11 @@ foreach tuple : _man_pages
       's|@DISTCONFDIR@|@0@|g;'.format(distconfdir) +
       's|@MODULE_DIRECTORY@|@0@|g;'.format(moduledir),
     ],
-    input : '@0@.@1@.scd'.format(man, section),
-    output : '@0@.@1@'.format(man, section),
+    input : f'@man@.@section@.scd',
+    output : f'@man@.@section@',
     capture : true,
     install : true,
-    install_dir : get_option('mandir') / 'man@0@'.format(section)
+    install_dir : get_option('mandir') / f'man@section@',
   )
 endforeach
 
@@ -45,11 +45,11 @@ foreach tuple : _man_aliases
   dest = tuple[2]
 
   custom_target(
-    'man_@0@_@1@'.format(section, man),
-    command : ['echo', '.so @0@'.format(dest)],
-    output : '@0@.@1@'.format(man, section),
+    f'man_@section@_@man@',
+    command : ['echo', f'.so @dest@'],
+    output : f'@man@.@section@',
     capture : true,
     install : true,
-    install_dir : get_option('mandir') / 'man@0@'.format(section)
+    install_dir : get_option('mandir') / f'man@section@',
   )
 endforeach
index f5dc4e59ebafc6c591a2b72aa2ddda3073a5033a..5b914b74a114036a5847e145bbf82520ee39ff9f 100644 (file)
@@ -36,7 +36,8 @@ _funcs = [
   'secure_getenv',
 ]
 foreach func : _funcs
-  cdata.set10('HAVE_@0@'.format(func.to_upper()), cc.has_function(func, args : '-D_GNU_SOURCE'))
+  func_to_upper = func.to_upper()
+  cdata.set10(f'HAVE_@func_to_upper@', cc.has_function(func, args : '-D_GNU_SOURCE'))
 endforeach
 
 # Meson has some amount of support for finding builtins by passing the symbol
@@ -57,12 +58,13 @@ foreach tuple : _builtins
   args = tuple[1]
   required = tuple[2]
   # XXX: meson 1.5.0 has links(... required ) flag
-  have = cc.links('int main(void){@0@(@1@);return 0;}'.format(builtin, args))
+  have = cc.links(f'int main(void){@builtin@(@args@);return 0;}')
   if required and not have
-    error('required builtin function not found: @0@'.format(builtin))
+    error(f'required builtin function not found: @builtin@')
   endif
 
-  cdata.set10('HAVE_@0@'.format(builtin.to_upper()), have)
+  builtin_to_upper = builtin.to_upper()
+  cdata.set10(f'HAVE_@builtin_to_upper@', have)
 endforeach
 
 # basename may be only available in libgen.h with the POSIX behavior,
@@ -75,7 +77,8 @@ foreach tuple : _decls
   decl = tuple[0]
   header = tuple[1]
   have  = cc.has_header_symbol(header, decl, args : '-D_GNU_SOURCE')
-  cdata.set10('HAVE_DECL_@0@'.format(decl.to_upper()), have)
+  decl_to_upper = decl.to_upper()
+  cdata.set10(f'HAVE_DECL_@decl_to_upper@', have)
 endforeach
 
 cdata.set10('HAVE_STATIC_ASSERT', cc.compiles('_Static_assert(1, "Test");', name : '_Static_assert'))
@@ -158,6 +161,9 @@ dlopen_all = get_option('dlopen').contains('all')
 # Directories
 #-------------------------------------------------------------------------------
 
+project_source_root = meson.project_source_root()
+project_build_root = meson.project_build_root()
+
 prefixdir = get_option('prefix')
 sysconfdir = get_option('sysconfdir')
 bindir = prefixdir / get_option('bindir')
@@ -191,8 +197,7 @@ foreach tuple : _customdirs
     customdir = def_path
   else
     if not customdir.startswith('/')
-      error('User provided @0@, \'@1@\' is not an absolute path.'
-          .format(dir_option, customdir))
+      error(f'User provided @dir_option@, \'@customdir@\' is not an absolute path.')
     endif
     # Strip all leading/trailing and re-add only the leading one.
     customdir = '/' / customdir.strip('/')
@@ -224,10 +229,8 @@ foreach tuple : _completiondirs
     if completion.found()
       completion_prefix = completion.get_variable(pkgconfig : 'prefix')
       if completion_prefix != prefixdir
-        warning('User provided prefix \'@0@\' differs from @1@ one \'@2@\'.'
-                .format(prefixdir, pkg_dep, completion_prefix))
-        warning('Not installing completion. To re-enable, manually set @0@.'
-                .format(dir_option))
+        warning(f'User provided prefix \'@prefixdir@\' differs from @pkg_dep@ one \'@completion_prefix@\'.')
+        warning(f'Not installing completion. To re-enable, manually set @dir_option@.')
         completiondir = 'no'
       else
         completiondir = completion.get_variable(pkgconfig : 'completionsdir')
@@ -279,7 +282,7 @@ foreach tuple : _compression
 
   dlopen = dlopen_all or get_option('dlopen').contains(opt)
   if not dlopen_all and dlopen and get_option(opt).disabled()
-    error('Incompatiable options: dlopen=@0@ for disabled @0@'.format(opt))
+    error(f'Incompatiable options: dlopen=@opt@ for disabled @opt@')
   endif
 
   dep = dependency(pkg_dep, version : pkg_dep_version, required : get_option(opt))
@@ -292,7 +295,7 @@ foreach tuple : _compression
   cdata.set10('ENABLE_' + opt.to_upper() + '_DLOPEN', have and dlopen)
 
   if have
-    module_compressions += '@0@ '.format(opt)
+    module_compressions += f'@opt@ '
   endif
 
   features += ['@0@@1@'.format(have ? '+' : '-', opt.to_upper())]
index 5985ae0d6b724e43a578fb5e3e9861a626f2148b..a359c2c497c16881c194058a36df77bb41b1683f 100644 (file)
@@ -6,7 +6,7 @@ build_module_playground = custom_target(
   'build-module-playground',
   command : [
     setup_modules,
-    meson.project_source_root(),
+    project_source_root,
     'testsuite/module-playground', # do not prepend source/build root
   ],
   # The command ensures we don't do extra work, so the missing output token file
@@ -21,10 +21,10 @@ create_rootfs = custom_target(
   'create-rootfs',
   command : [
     setup_rootfs,
-    meson.project_source_root() / 'testsuite/rootfs-pristine',
-    meson.project_build_root() / 'testsuite/rootfs',
-    meson.project_build_root() / 'testsuite/module-playground',
-    meson.project_build_root() / 'config.h',
+    f'@project_source_root@/testsuite/rootfs-pristine',
+    f'@project_build_root@/testsuite/rootfs',
+    f'@project_build_root@/testsuite/module-playground',
+    f'@project_build_root@/config.h',
     sysconfdir,
     moduledir,
   ],
@@ -48,9 +48,9 @@ test_override_mods = []
 foreach mod : _test_override_mods
   test_override_mods += shared_module(
     mod,
-    files('@0@.c'.format(mod)),
+    files(f'@mod@.c'),
     include_directories : top_include,
-    c_args : '-DABS_TOP_BUILDDIR="@0@"'.format(meson.project_build_root()),
+    c_args : f'-DABS_TOP_BUILDDIR="@project_build_root@"',
     dependencies : libdl,
     link_with : [libshared, libkmod_internal],
     gnu_symbol_visibility : 'hidden',
@@ -62,9 +62,9 @@ endforeach
 
 testsuite_c_args = [
   '-UNDEBUG',
-  '-DTESTSUITE_ROOTFS="@0@/testsuite/rootfs/"'.format(meson.project_build_root()),
-  '-DTOOLS_DIR="@0@/"'.format(meson.project_build_root()),
-  '-DOVERRIDE_LIBDIR="@0@/testsuite/"'.format(meson.project_build_root()),
+  f'-DTESTSUITE_ROOTFS="@project_build_root@/testsuite/rootfs/"',
+  f'-DTOOLS_DIR="@project_build_root@/"',
+  f'-DOVERRIDE_LIBDIR="@project_build_root@/testsuite/"',
 ]
 
 libtestsuite = static_library(
@@ -106,7 +106,7 @@ endif
 foreach input : _testsuite
   exec = executable(
     input,
-    files('@0@.c'.format(input)),
+    files(f'@input@.c'),
     include_directories : top_include,
     c_args : testsuite_c_args,
     link_with : [libshared, libkmod_internal, libtestsuite],