From: Zbigniew Jędrzejewski-Szmek Date: Tue, 6 Jun 2023 07:54:20 +0000 (+0200) Subject: meson: use "cpp -E -dM" to process header file X-Git-Tag: v254-rc1~215^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1e473c2ebbcfd510238ea9d031ca7d73a9591a75;p=thirdparty%2Fsystemd.git meson: use "cpp -E -dM" to process header file This was requested in review: https://github.com/systemd/systemd/pull/27846#discussion_r1210383265 I kept this as separate commit because the change would impact both of the previous commits and splitting it up seems like unnecessary work. The result is unchanged. v2: - use universal_newlines=True to keep compat with Python 3.6 on C8S. --- diff --git a/src/shared/ethtool-link-mode.py b/src/shared/ethtool-link-mode.py index 03ea1b1fd88..aac1576145e 100644 --- a/src/shared/ethtool-link-mode.py +++ b/src/shared/ethtool-link-mode.py @@ -2,21 +2,27 @@ # SPDX-License-Identifier: LGPL-2.1-or-later import re +import shlex +import subprocess import sys OVERRIDES = { 'autoneg' : 'autonegotiation', } -xml = sys.argv[1] == '--xml' +mode, cpp, header = sys.argv[1:] +xml = mode == '--xml' -f = open(sys.argv[-1]) -for line in f: +command = [*shlex.split(cpp), '-include', header, '-'] +out = subprocess.check_output(command, stdin=subprocess.DEVNULL, universal_newlines=True) + +lines = iter(out.splitlines()) +for line in lines: if line.startswith('enum ethtool_link_mode_bit_indices {'): break entries = [] -for line in f: +for line in lines: if line.startswith('}'): break # ETHTOOL_LINK_MODE_10baseT_Half_BIT = 0, diff --git a/src/shared/meson.build b/src/shared/meson.build index d78b9176c0c..f2ed6b17743 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -275,7 +275,7 @@ ethtool_link_mode_h = custom_target( fname, input : ['ethtool-link-mode.py', 'linux/ethtool.h'], output : fname, - command : [python, '@INPUT0@', '@INPUT1@'], + command : [python, '@INPUT0@', '--header', cpp, '@INPUT1@'], capture : true) shared_sources += ethtool_link_mode_h @@ -284,7 +284,7 @@ ethtool_link_mode_xml = custom_target( fname, input : ['ethtool-link-mode.py', 'linux/ethtool.h'], output : fname, - command : [python, '@INPUT0@', '--xml', '@INPUT1@'], + command : [python, '@INPUT0@', '--xml', cpp, '@INPUT1@'], capture : true) man_page_depends += ethtool_link_mode_xml