From 2b912d20669fb572ee24d986478e8e738306580c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 8 Jul 2025 13:07:32 +0900 Subject: [PATCH] tree-wide: several cleanups for generating symbol lists and gperf files - pass our system include directories to make generators use our libc wrappers and latest kernel headers, - include relevant headers in generated gperf file, - use files() rather than find_program(), as the result of find_program() cannot be passed to 'input' of custom_target(), - move generate-bpf-delegate-configs.py to src/core/, as it is only used by libcore. --- .github/workflows/linter.yml | 10 ++-- man/meson.build | 16 +---- meson.build | 9 +++ src/basic/generate-af-list.sh | 5 +- src/basic/generate-arphrd-list.sh | 5 +- src/basic/generate-cap-list.sh | 5 +- src/basic/generate-errno-list.sh | 5 +- src/basic/meson.build | 60 ++++++------------- .../generate-bpf-delegate-configs.py | 0 src/core/meson.build | 25 +++++++- src/include/meson.build | 38 ++++++++++++ .../sd-journal/generate-audit_type-list.sh | 10 ++-- src/libsystemd/sd-journal/meson.build | 5 +- src/shared/ethtool-link-mode.py | 6 +- src/shared/generate-ip-protocol-list.sh | 5 +- src/shared/meson.build | 14 +++-- src/udev/generate-keyboard-keys-gperf.sh | 1 + src/udev/generate-keyboard-keys-list.sh | 5 +- src/udev/meson.build | 12 ++-- tools/xml_helper.py | 2 +- 20 files changed, 147 insertions(+), 91 deletions(-) rename src/{basic => core}/generate-bpf-delegate-configs.py (100%) create mode 100644 src/include/meson.build diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index a489b556615..8c0ec63d403 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -41,7 +41,7 @@ jobs: - uses: systemd/mkosi@184472f0f1f831ca29953546ec01fd941ff763a6 - name: Check that tabs are not used in Python code - run: sh -c '! git grep -P "\\t" -- src/basic/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py' + run: sh -c '! git grep -P "\\t" -- src/core/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py' - name: Build tools tree run: | @@ -56,20 +56,20 @@ jobs: - name: Run mypy run: | mkosi box -- mypy --version - mkosi box -- mypy src/basic/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py + mkosi box -- mypy src/core/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py - name: Run ruff check run: | mkosi box -- ruff --version - mkosi box -- ruff check src/basic/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py + mkosi box -- ruff check src/core/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py - name: Run ruff format run: | mkosi box -- ruff --version - if ! mkosi box -- ruff format --check src/basic/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py + if ! mkosi box -- ruff format --check src/core/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py then echo "Please run 'ruff format' on the above files or apply the diffs below manually" - mkosi box -- ruff format --check --quiet --diff src/basic/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py + mkosi box -- ruff format --check --quiet --diff src/core/generate-bpf-delegate-configs.py src/boot/generate-hwids-section.py src/test/generate-sym-test.py src/ukify/ukify.py test/integration-tests/integration-test-wrapper.py fi - name: Configure meson diff --git a/man/meson.build b/man/meson.build index 4aa9ed237c3..89e813ee321 100644 --- a/man/meson.build +++ b/man/meson.build @@ -20,9 +20,10 @@ xsltproc_flags = [ '--stringparam', 'man.copyright.section.enabled', '0', '--stringparam', 'systemd.version', '@0@'.format(meson.project_version()), '--path', - '@0@:@1@:@2@'.format(meson.current_build_dir(), + '@0@:@1@:@2@:@3@'.format(meson.current_build_dir(), meson.current_source_dir(), - libshared_build_dir)] + libshared_build_dir, + libcore_build_dir)] custom_man_xsl = files('custom-man.xsl') custom_html_xsl = files('custom-html.xsl') @@ -35,17 +36,6 @@ custom_entities_ent = custom_target( man_page_depends += custom_entities_ent -generate_bpf_delegate_configs = find_program('../src/basic/generate-bpf-delegate-configs.py') - -bpf_delegate_xml = custom_target( - input : files('../src/include/uapi/linux/bpf.h'), - output : 'bpf-delegate.xml', - command : [generate_bpf_delegate_configs, - 'doc', - '@INPUT@'], - capture : true) -man_page_depends += bpf_delegate_xml - man_pages = [] html_pages = [] source_xml_files = [] diff --git a/meson.build b/meson.build index 8b7809043db..b97fe3aa414 100644 --- a/meson.build +++ b/meson.build @@ -2008,6 +2008,14 @@ dbus_programs = [] # A list of boot stubs. Required for testing of ukify. boot_stubs = [] +# This is similar to system_includes below, but for passing custom_target(). +system_include_args = [ + '-isystem', meson.project_build_root() / 'src/include/override', + '-isystem', meson.project_source_root() / 'src/include/override', + '-isystem', meson.project_build_root() / 'src/include/uapi', + '-isystem', meson.project_source_root() / 'src/include/uapi', +] + system_includes = [ include_directories( # gcc(1) says @@ -2048,6 +2056,7 @@ includes = [libsystemd_includes, include_directories('src/shared')] subdir('po') subdir('catalog') +subdir('src/include') subdir('src/fundamental') subdir('src/basic') subdir('src/libsystemd') diff --git a/src/basic/generate-af-list.sh b/src/basic/generate-af-list.sh index 4fec46a2ef7..d7c777507b5 100755 --- a/src/basic/generate-af-list.sh +++ b/src/basic/generate-af-list.sh @@ -3,6 +3,9 @@ set -eu set -o pipefail -${1:?} -E -dM -include sys/socket.h -include "${2:?}" - ']], - ['arphrd', arphrd_list_txt, 'arphrd', 'ARPHRD_', []], - ['cap', cap_list_txt, 'capability', '', []], - ['errno', errno_list_txt, 'errno', '', []]] +foreach item : [ + # name, source, struct name, prefix, headers + ['af', af_sources, 'af', '', [''], ], + ['arphrd', arphrd_sources, 'arphrd', 'ARPHRD_', [''], ], + ['cap', cap_sources, 'capability', '', [''], ], + ['errno', [], 'errno', '', [''], ], +] + + fname = '@0@-list.txt'.format(item[0]) + generate_list = files('generate-@0@-list.sh'.format(item[0])) + list_txt = custom_target( + input : [generate_list, item[1]], + output : fname, + command : [env, 'bash', generate_list, cpp, system_include_args], + capture : true) fname = '@0@-from-name.gperf'.format(item[0]) gperf_file = custom_target( - input : item[1], + input : list_txt, output : fname, command : [generate_gperfs, item[2], item[3], '@INPUT@'] + item[4], capture : true) @@ -176,7 +163,7 @@ foreach item : [['af', af_list_txt, 'af', '', ['= 15\n\ _Pragma(\"GCC diagnostic ignored \\\"-Wzero-as-null-pointer-constant\\\"\")\n\ #endif\n\ +#include \n\ %}" print "struct key_name { const char* name; unsigned short id; };" print "%null-strings" diff --git a/src/udev/generate-keyboard-keys-list.sh b/src/udev/generate-keyboard-keys-list.sh index 4cac5073220..58091192248 100755 --- a/src/udev/generate-keyboard-keys-list.sh +++ b/src/udev/generate-keyboard-keys-list.sh @@ -3,7 +3,10 @@ set -eu set -o pipefail -${1:?} -dM -include "${2:?}" - / { next } /^#define[ \t]+(KEY|BTN)_[^ ]+[ \t]+[0-9BK]/ { print $2 } ' diff --git a/src/udev/meson.build b/src/udev/meson.build index 6b37b669d0a..7e49959bc5d 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -61,19 +61,19 @@ endif ############################################################ -generate_keyboard_keys_list = find_program('generate-keyboard-keys-list.sh') +generate_keyboard_keys_list = files('generate-keyboard-keys-list.sh') keyboard_keys_list_txt = custom_target( - input : files('../include/uapi/linux/input.h'), + input : [generate_keyboard_keys_list, keyboard_sources], output : 'keyboard-keys-list.txt', - command : [generate_keyboard_keys_list, cpp, '@INPUT@'], + command : [env, 'bash', generate_keyboard_keys_list, cpp, system_include_args], capture : true) -generate_keyboard_keys_gperf = find_program('generate-keyboard-keys-gperf.sh') +generate_keyboard_keys_gperf = files('generate-keyboard-keys-gperf.sh') fname = 'keyboard-keys-from-name.gperf' gperf_file = custom_target( - input : keyboard_keys_list_txt, + input : [generate_keyboard_keys_gperf, keyboard_keys_list_txt], output : fname, - command : [generate_keyboard_keys_gperf, '@INPUT@'], + command : [env, 'bash', '@INPUT@'], capture : true) fname = 'keyboard-keys-from-name.inc' diff --git a/tools/xml_helper.py b/tools/xml_helper.py index 294630ded15..0383ef71879 100755 --- a/tools/xml_helper.py +++ b/tools/xml_helper.py @@ -11,7 +11,7 @@ class CustomResolver(tree.Resolver): if 'ethtool-link-mode' in url: return self.resolve_filename('src/shared/ethtool-link-mode.xml', context) if 'bpf-delegate' in url: - return self.resolve_filename('man/bpf-delegate.xml', context) + return self.resolve_filename('src/core/bpf-delegate.xml', context) return None -- 2.47.3