man: generate link mode list dynamically

The entries are sorted by speed. Some fields are left empty when there is no
clear value to use. The table is much longer now, but I think it's better to
document the allowed values, even if some are not terribly useful.

Fixes #26256.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-05-30 13:02:57 +02:00
parent 6049ddcca2
commit c18dde32e5
6 changed files with 57 additions and 58 deletions

View file

@ -20,7 +20,9 @@ xsltproc_flags = [
'--stringparam', 'man.copyright.section.enabled', '0', '--stringparam', 'man.copyright.section.enabled', '0',
'--stringparam', 'systemd.version', '@0@'.format(meson.project_version()), '--stringparam', 'systemd.version', '@0@'.format(meson.project_version()),
'--path', '--path',
'@0@:@1@'.format(meson.current_build_dir(), meson.current_source_dir())] '@0@:@1@:@2@'.format(meson.current_build_dir(),
meson.current_source_dir(),
libshared_build_dir)]
custom_man_xsl = files('custom-man.xsl') custom_man_xsl = files('custom-man.xsl')
custom_html_xsl = files('custom-html.xsl') custom_html_xsl = files('custom-html.xsl')
@ -32,6 +34,8 @@ custom_entities_ent = custom_target(
output : 'custom-entities.ent', output : 'custom-entities.ent',
command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@']) command : [jinja2_cmdline, '@INPUT@', '@OUTPUT@'])
man_page_depends += custom_entities_ent
man_pages = [] man_pages = []
html_pages = [] html_pages = []
source_xml_files = [] source_xml_files = []
@ -68,7 +72,7 @@ foreach tuple : manpages
input : xml, input : xml,
output : [man] + manaliases, output : [man] + manaliases,
command : xslt_cmd + [custom_man_xsl, '@INPUT@'], command : xslt_cmd + [custom_man_xsl, '@INPUT@'],
depends : custom_entities_ent, depends : man_page_depends,
install : want_man, install : want_man,
install_dir : mandirn) install_dir : mandirn)
man_pages += p1 man_pages += p1
@ -93,7 +97,7 @@ foreach tuple : manpages
input : xml, input : xml,
output : html, output : html,
command : xslt_cmd + [custom_html_xsl, '@INPUT@'], command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
depends : [custom_entities_ent, p2], depends : [man_page_depends, p2],
install : want_html, install : want_html,
install_dir : docdir / 'html') install_dir : docdir / 'html')
html_pages += p3 html_pages += p3
@ -114,7 +118,7 @@ systemd_directives_xml = custom_target(
'systemd.directives.xml', 'systemd.directives.xml',
input : ['directives-template.xml', source_xml_files], input : ['directives-template.xml', source_xml_files],
output : 'systemd.directives.xml', output : 'systemd.directives.xml',
depends : custom_entities_ent, depends : man_page_depends,
command : [make_directive_index_py, '@OUTPUT@', '@INPUT@']) command : [make_directive_index_py, '@OUTPUT@', '@INPUT@'])
nonindex_xml_files = source_xml_files + [systemd_directives_xml] nonindex_xml_files = source_xml_files + [systemd_directives_xml]
@ -166,7 +170,7 @@ foreach tuple : xsltproc.found() ? [['systemd.directives', '7', systemd_directiv
input : xml, input : xml,
output : html, output : html,
command : xslt_cmd + [custom_html_xsl, '@INPUT@'], command : xslt_cmd + [custom_html_xsl, '@INPUT@'],
depends : [custom_entities_ent, p2], depends : [man_page_depends, p2],
install : want_html and have_lxml, install : want_html and have_lxml,
install_dir : docdir / 'html') install_dir : docdir / 'html')
html_pages += p3 html_pages += p3
@ -237,4 +241,4 @@ update_man_rules = custom_target(
command : [update_man_rules_py, command : [update_man_rules_py,
'@0@/man/*.xml'.format(project_source_root), '@0@/man/*.xml'.format(project_source_root),
'@0@/rules/meson.build'.format(meson.current_source_dir())], '@0@/rules/meson.build'.format(meson.current_source_dir())],
depends : custom_entities_ent) depends : man_page_depends)

View file

@ -3,7 +3,8 @@
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
<refentry id="systemd.link"> <refentry id="systemd.link"
xmlns:xi="http://www.w3.org/2001/XInclude">
<refentryinfo> <refentryinfo>
<title>systemd.link</title> <title>systemd.link</title>
<productname>systemd</productname> <productname>systemd</productname>
@ -709,49 +710,7 @@
<entry>Speed (Mbps)</entry> <entry>Speed (Mbps)</entry>
<entry>Duplex Mode</entry> <entry>Duplex Mode</entry>
</row></thead> </row></thead>
<tbody> <xi:include href="ethtool-link-mode.xml" />
<row><entry><option>10baset-half</option></entry>
<entry>10</entry><entry>half</entry></row>
<row><entry><option>10baset-full</option></entry>
<entry>10</entry><entry>full</entry></row>
<row><entry><option>100baset-half</option></entry>
<entry>100</entry><entry>half</entry></row>
<row><entry><option>100baset-full</option></entry>
<entry>100</entry><entry>full</entry></row>
<row><entry><option>1000baset-half</option></entry>
<entry>1000</entry><entry>half</entry></row>
<row><entry><option>1000baset-full</option></entry>
<entry>1000</entry><entry>full</entry></row>
<row><entry><option>10000baset-full</option></entry>
<entry>10000</entry><entry>full</entry></row>
<row><entry><option>2500basex-full</option></entry>
<entry>2500</entry><entry>full</entry></row>
<row><entry><option>1000basekx-full</option></entry>
<entry>1000</entry><entry>full</entry></row>
<row><entry><option>10000basekx4-full</option></entry>
<entry>10000</entry><entry>full</entry></row>
<row><entry><option>10000basekr-full</option></entry>
<entry>10000</entry><entry>full</entry></row>
<row><entry><option>10000baser-fec</option></entry>
<entry>10000</entry><entry>full</entry></row>
<row><entry><option>20000basemld2-full</option></entry>
<entry>20000</entry><entry>full</entry></row>
<row><entry><option>20000basekr2-full</option></entry>
<entry>20000</entry><entry>full</entry></row>
</tbody>
</tgroup> </tgroup>
</table> </table>

View file

@ -2172,6 +2172,8 @@ userspace = declare_dependency(
link_args : userspace_c_ld_args, link_args : userspace_c_ld_args,
) )
man_page_depends = []
############################################################ ############################################################
# binaries that have --help and are intended for use by humans, # binaries that have --help and are intended for use by humans,

View file

@ -7,27 +7,49 @@ import sys
OVERRIDES = { OVERRIDES = {
'autoneg' : 'autonegotiation', 'autoneg' : 'autonegotiation',
} }
count = 0
f = open(sys.argv[1]) xml = sys.argv[1] == '--xml'
f = open(sys.argv[-1])
for line in f: for line in f:
if line.startswith('enum ethtool_link_mode_bit_indices {'): if line.startswith('enum ethtool_link_mode_bit_indices {'):
break break
entries = []
for line in f: for line in f:
if line.startswith('}'): if line.startswith('}'):
break break
# ETHTOOL_LINK_MODE_10baseT_Half_BIT = 0, # ETHTOOL_LINK_MODE_10baseT_Half_BIT = 0,
m = re.match(r'^\s*(ETHTOOL_LINK_MODE_(.*)_BIT)\s*=\s*(\d+),', line) m = re.match(r'^\s*(ETHTOOL_LINK_MODE_((\d*).*)_BIT)\s*=\s*(\d+),', line)
if not m: if not m:
continue continue
enum, name, value = m.groups() enum, name, speed, value = m.groups()
name = name.lower().replace('_', '-') name = name.lower().replace('_', '-')
name = OVERRIDES.get(name, name) name = OVERRIDES.get(name, name)
enum = f'[{enum}]' duplex = name.split('-')[-1].lower()
if duplex not in {'half', 'full'}:
duplex = ''
print(f' {enum:50} = "{name}",') entries += [(enum, name, speed, value, duplex)]
count += 1
assert count >= 99 if xml:
print(' <tbody>')
entries.sort(key=lambda entry: (int(entry[2]) if entry[2] else 1e20, entry[4], entry[1], entry[3]))
for enum, name, speed, value, duplex in entries:
if xml:
print(f'''\
<row><entry><option>{name}</option></entry>
<entry>{speed}</entry><entry>{duplex}</entry></row>
''')
else:
enum = f'[{enum}]'
print(f' {enum:50} = "{name}",')
if xml:
print(' </tbody>')
assert len(entries) >= 99

View file

@ -279,6 +279,15 @@ ethtool_link_mode_h = custom_target(
capture : true) capture : true)
shared_sources += ethtool_link_mode_h shared_sources += ethtool_link_mode_h
fname = 'ethtool-link-mode.xml'
ethtool_link_mode_xml = custom_target(
fname,
input : ['ethtool-link-mode.py', 'linux/ethtool.h'],
output : fname,
command : [python, '@INPUT0@', '--xml', '@INPUT1@'],
capture : true)
man_page_depends += ethtool_link_mode_xml
libshared_name = 'systemd-shared-@0@'.format(shared_lib_tag) libshared_name = 'systemd-shared-@0@'.format(shared_lib_tag)
libshared_deps = [threads, libshared_deps = [threads,
@ -304,6 +313,7 @@ libshared_deps = [threads,
versiondep] versiondep]
libshared_sym_path = '@0@/libshared.sym'.format(meson.current_source_dir()) libshared_sym_path = '@0@/libshared.sym'.format(meson.current_source_dir())
libshared_build_dir = meson.current_build_dir()
libshared_static = static_library( libshared_static = static_library(
libshared_name, libshared_name,

View file

@ -7,6 +7,8 @@ class CustomResolver(tree.Resolver):
def resolve(self, url, id, context): def resolve(self, url, id, context):
if 'custom-entities.ent' in url: if 'custom-entities.ent' in url:
return self.resolve_filename('man/custom-entities.ent', context) return self.resolve_filename('man/custom-entities.ent', context)
if 'ethtool-link-mode' in url:
return self.resolve_filename('src/shared/ethtool-link-mode.xml', context)
_parser = tree.XMLParser() _parser = tree.XMLParser()
_parser.resolvers.add(CustomResolver()) _parser.resolvers.add(CustomResolver())