]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: replace sh+find with an internal glob in the python helper
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 22 Mar 2022 20:51:33 +0000 (21:51 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Mar 2022 02:37:35 +0000 (11:37 +0900)
As suggested in https://github.com/systemd/systemd/pull/22810#discussion_r831708052

This makes the whole thing simpler. A glob is passed to helper which then resolves
it on its own. This way it's trivial to call the helper with a different
set of files for testing.

man/meson.build
meson.build
tools/update-man-rules.py

index 069772467eb782caadd8963c7da7c3f2b2abe158..83b368115b4b552a67669c9ed237520b426abf2c 100644 (file)
@@ -233,8 +233,7 @@ endif
 update_man_rules = custom_target(
         'update-man-rules',
         output : 'update-man-rules',
-        command : [sh, '-c',
-                   'cd @0@ && '.format(project_build_root) +
-                   'python3 @0@/tools/update-man-rules.py $(find @0@ -wholename "*/man/*.xml") >t && '.format(project_source_root) +
-                   'mv t @0@/rules/meson.build'.format(meson.current_source_dir())],
+        command : [update_man_rules_py,
+                   '@0@/man/*.xml'.format(project_source_root),
+                   '@0@/rules/meson.build'.format(meson.current_source_dir())],
         depends : custom_entities_ent)
index 05dcc79cfa815e6a00e43dfdf53ceada1538f06c..7de1baaf70a95d571d1c9a406f1ae02f252e72ea 100644 (file)
@@ -1803,6 +1803,7 @@ make_directive_index_py = find_program('tools/make-directive-index.py')
 make_man_index_py = find_program('tools/make-man-index.py')
 meson_render_jinja2 = find_program('tools/meson-render-jinja2.py')
 update_dbus_docs_py = find_program('tools/update-dbus-docs.py')
+update_man_rules_py = find_program('tools/update-man-rules.py')
 update_hwdb_sh = find_program('tools/update-hwdb.sh')
 update_hwdb_autosuspend_sh = find_program('tools/update-hwdb-autosuspend.sh')
 update_syscall_tables_sh = find_program('tools/update-syscall-tables.sh')
index 31ed91c432edd5790ca86dd03c7a99bf15b67bcd..3a8c31dc358ab241c9a4a4c98ac6cc985fccf254 100755 (executable)
@@ -3,9 +3,10 @@
 
 from __future__ import print_function
 import collections
+import glob
 import sys
+from pathlib import Path
 import pprint
-from os.path import basename
 from xml_helper import xml_parse
 
 def man(page, number):
@@ -56,7 +57,8 @@ manpages = ['''
 
 MESON_FOOTER = '''\
 ]
-# Really, do not edit.'''
+# Really, do not edit.
+'''
 
 def make_mesonfile(rules, dist_files):
     # reformat rules as
@@ -76,13 +78,20 @@ def make_mesonfile(rules, dist_files):
     return '\n'.join((MESON_HEADER, pprint.pformat(lines)[1:-1], MESON_FOOTER))
 
 if __name__ == '__main__':
-    pages = sys.argv[1:]
+    source_glob = sys.argv[1]
+    target = Path(sys.argv[2])
+
+    pages = glob.glob(source_glob)
     pages = (p for p in pages
-             if basename(p) not in {
+             if Path(p).name not in {
                      'systemd.directives.xml',
                      'systemd.index.xml',
                      'directives-template.xml'})
 
     rules = create_rules(pages)
-    dist_files = (basename(p) for p in pages)
-    print(make_mesonfile(rules, dist_files))
+    dist_files = (Path(p).name for p in pages)
+    text = make_mesonfile(rules, dist_files)
+
+    tmp = target.with_suffix('.tmp')
+    tmp.write_text(text)
+    tmp.rename(target)