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.
This commit is contained in:
Yu Watanabe
2025-07-11 13:05:42 +09:00
parent 1a60b97524
commit 2b912d2066
20 changed files with 147 additions and 91 deletions
+4 -1
View File
@@ -3,6 +3,9 @@
set -eu
set -o pipefail
${1:?} -E -dM -include sys/socket.h -include "${2:?}" - </dev/null | \
CC=${1:?}
shift
$CC -E -dM -include sys/socket.h "$@" - </dev/null | \
grep -Ev 'AF_UNSPEC|AF_MAX' | \
awk '/^#define[ \t]+AF_[^ \t]+[ \t]+[AP]F_[^ \t]/ { print $2; }'
+4 -1
View File
@@ -3,6 +3,9 @@
set -eu
set -o pipefail
${1:?} -dM -include "${2:?}" - </dev/null | \
CC=${1:?}
shift
$CC -dM -include linux/if_arp.h "$@" - </dev/null | \
awk '/^#define[ \t]+ARPHRD_[^ \t]+[ \t]+[^ \t]/ { print $2; }' | \
sed -e 's/ARPHRD_//'
@@ -1,79 +0,0 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1-or-later
# Convert the bpf_{cmd,map_type,prog_type,attach_type} enums into a string
# array to be used as configuration options
import re
import sys
import typing
def print_usage_and_exit() -> None:
print(f'Usage: {sys.argv[0]} <code|doc> <header>')
sys.exit(1)
if len(sys.argv) != 3:
print_usage_and_exit()
output = sys.argv[1]
header = sys.argv[2]
if output not in ['code', 'doc']:
print(f'Invalid format: {format}')
print_usage_and_exit()
with open(header) as file:
inEnum = False
enumValues: typing.List[str] = []
enumName = ''
if output == 'doc':
print("""\
<?xml version="1.0"?>
<!DOCTYPE bpf-delegates PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<para>
""")
for line in file:
line = line.strip()
if inEnum:
# Inside an enum definition
if re.match(r'^\s*}', line):
# End of an enum definition
inEnum = False
# Print the enum values as a static const char* array
if output == 'code':
print(f'static const char* const {enumName}_table[] = {{')
else:
print(f'<para id="{enumName}">')
for enumValue in enumValues:
words = enumValue.split('_')
enumValue = words[0] + ''.join(word.capitalize() for word in words[1:])
if output == 'code':
print(f'\t"{enumValue}",')
else:
print(f'<constant>{enumValue}</constant>')
if output == 'code':
print('};')
else:
print('</para>')
enumValues = []
else:
# Collect enum values
match = re.fullmatch(r'(\w+)\b,', line)
if match and len(match.groups()) > 0 and not match[1].startswith('__'):
enumValues.append(match[1])
else:
match = re.match(r'^\s*enum\s+bpf_(cmd|map_type|prog_type|attach_type)+\s*{', line)
if match:
# Start of a new enum
inEnum = True
enumName = 'bpf_delegate_' + match[1]
if output == 'doc':
print('</para>')
+4 -1
View File
@@ -3,6 +3,9 @@
set -eu
set -o pipefail
${1:?} -dM -include "${2:?}" - </dev/null | \
CC=${1:?}
shift
$CC -dM -include linux/capability.h "$@" - </dev/null | \
awk '/^#define[ \t]+CAP_[A-Z_]+[ \t]+/ { print $2; }' | \
grep -v CAP_LAST_CAP
+4 -1
View File
@@ -6,6 +6,9 @@ set -o pipefail
# In kernel's arch/parisc/include/uapi/asm/errno.h, ECANCELLED and EREFUSED are defined as aliases of
# ECANCELED and ECONNREFUSED, respectively. Let's drop them.
${1:?} -dM -include errno.h - </dev/null | \
CC=${1:?}
shift
$CC -dM -include errno.h "$@" - </dev/null | \
grep -Ev '^#define[[:space:]]+(ECANCELLED|EREFUSED)' | \
awk '/^#define[ \t]+E[^ _]+[ \t]+/ { print $2; }'
+19 -41
View File
@@ -124,39 +124,26 @@ missing_audit_h = files('missing_audit.h')
missing_syscall_def_h = files('missing_syscall_def.h')
basic_sources += missing_syscall_def_h
generate_af_list = find_program('generate-af-list.sh')
af_list_txt = custom_target(
output : 'af-list.txt',
command : [generate_af_list, cpp, files('../include/override/sys/socket.h')],
capture : true)
generate_arphrd_list = find_program('generate-arphrd-list.sh')
arphrd_list_txt = custom_target(
output : 'arphrd-list.txt',
command : [generate_arphrd_list, cpp, files('../include/uapi/linux/if_arp.h')],
capture : true)
generate_cap_list = find_program('generate-cap-list.sh')
cap_list_txt = custom_target(
output : 'cap-list.txt',
command : [generate_cap_list, cpp, files('../include/uapi/linux/capability.h')],
capture : true)
generate_errno_list = find_program('generate-errno-list.sh')
errno_list_txt = custom_target(
output : 'errno-list.txt',
command : [generate_errno_list, cpp],
capture : true)
generated_gperf_headers = []
foreach item : [['af', af_list_txt, 'af', '', ['<sys/socket.h>']],
['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', '', ['<sys/socket.h>'], ],
['arphrd', arphrd_sources, 'arphrd', 'ARPHRD_', ['<linux/if_arp.h>'], ],
['cap', cap_sources, 'capability', '', ['<linux/capability.h>'], ],
['errno', [], 'errno', '', ['<errno.h>'], ],
]
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', '', ['<sys/sock
fname = '@0@-to-name.inc'.format(item[0])
awkscript = '@0@-to-name.awk'.format(item[0])
target2 = custom_target(
input : [awkscript, item[1]],
input : [awkscript, list_txt],
output : fname,
command : [awk, '-f', '@INPUT0@', '@INPUT1@'],
capture : true)
@@ -273,17 +260,8 @@ filesystem_switch_case_inc = custom_target(
'@INPUT@'],
capture : true)
generate_bpf_delegate_configs = find_program('generate-bpf-delegate-configs.py')
bpf_delegate_configs_inc = custom_target(
input : files('../include/uapi/linux/bpf.h'),
output : 'bpf-delegate-configs.inc',
command : [generate_bpf_delegate_configs,
'code',
'@INPUT@'],
capture : true)
generated_sources += [filesystem_list_inc, filesystem_switch_case_inc, filesystems_gperf_h, bpf_delegate_configs_inc]
basic_sources += [filesystem_list_inc, filesystem_switch_case_inc, filesystems_gperf_h, bpf_delegate_configs_inc]
generated_sources += [filesystem_list_inc, filesystem_switch_case_inc, filesystems_gperf_h]
basic_sources += [filesystem_list_inc, filesystem_switch_case_inc, filesystems_gperf_h]
libbasic_static = static_library(
'basic',