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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2023-06-06 09:54:20 +02:00
parent c18dde32e5
commit 1e473c2ebb
2 changed files with 12 additions and 6 deletions

View File

@@ -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,

View File

@@ -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