]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: use "cpp -E -dM" to process header file 27846/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 6 Jun 2023 07:54:20 +0000 (09:54 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 7 Jun 2023 08:48:36 +0000 (10:48 +0200)
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.

src/shared/ethtool-link-mode.py
src/shared/meson.build

index 03ea1b1fd88c2e873af164af60c4984e0d354ba0..aac1576145e93f5ae964e08e7f64c14ecc021299 100644 (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,
index d78b9176c0c1d5b5791df2b0746ac2ec1b711613..f2ed6b17743f57df372140164dee5750974e31be 100644 (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