[PATCH net-next 01/11] tools: ynl-gen: allow overriding name-prefix for constants

Asbjørn Sloth Tønnesen posted 11 patches 4 weeks ago
There is a newer version of this series
[PATCH net-next 01/11] tools: ynl-gen: allow overriding name-prefix for constants
Posted by Asbjørn Sloth Tønnesen 4 weeks ago
Allow using custom name-prefix with constants,
just like it is for enum and flags declarations.

This is needed for generating WG_KEY_LEN in
include/uapi/linux/wireguard.h from a spec.

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
---
 tools/net/ynl/pyynl/ynl_gen_c.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index fb7e03805a11..1543d4911bf5 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -3211,8 +3211,9 @@ def render_uapi(family, cw):
             cw.block_end(line=';')
             cw.nl()
         elif const['type'] == 'const':
+            name_pfx = const.get('name-prefix', f"{family.ident_name}-")
             defines.append([c_upper(family.get('c-define-name',
-                                               f"{family.ident_name}-{const['name']}")),
+                                               f"{name_pfx}{const['name']}")),
                             const['value']])
 
     if defines:
-- 
2.51.0

Re: [PATCH net-next 01/11] tools: ynl-gen: allow overriding name-prefix for constants
Posted by Jacob Keller 3 weeks, 6 days ago

On 9/4/2025 3:01 PM, Asbjørn Sloth Tønnesen wrote:
> Allow using custom name-prefix with constants,
> just like it is for enum and flags declarations.
> 
> This is needed for generating WG_KEY_LEN in
> include/uapi/linux/wireguard.h from a spec.
> 
> Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
> ---
>  tools/net/ynl/pyynl/ynl_gen_c.py | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
> index fb7e03805a11..1543d4911bf5 100755
> --- a/tools/net/ynl/pyynl/ynl_gen_c.py
> +++ b/tools/net/ynl/pyynl/ynl_gen_c.py
> @@ -3211,8 +3211,9 @@ def render_uapi(family, cw):
>              cw.block_end(line=';')
>              cw.nl()
>          elif const['type'] == 'const':
> +            name_pfx = const.get('name-prefix', f"{family.ident_name}-")

Previously we always used "{family.ident_name}-", but now we get the
name-prefix and use that, falling back to the default if it doesn't
exist. Good.

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>

>              defines.append([c_upper(family.get('c-define-name',
> -                                               f"{family.ident_name}-{const['name']}")),
> +                                               f"{name_pfx}{const['name']}")),
>                              const['value']])
>  
>      if defines:

Re: [PATCH net-next 01/11] tools: ynl-gen: allow overriding name-prefix for constants
Posted by Jakub Kicinski 3 weeks, 6 days ago
On Thu,  4 Sep 2025 22:01:24 +0000 Asbjørn Sloth Tønnesen wrote:
> Allow using custom name-prefix with constants,
> just like it is for enum and flags declarations.
> 
> This is needed for generating WG_KEY_LEN in
> include/uapi/linux/wireguard.h from a spec.

Reviewed-by: Jakub Kicinski <kuba@kernel.org>
Re: [PATCH net-next 01/11] tools: ynl-gen: allow overriding name-prefix for constants
Posted by Donald Hunter 3 weeks, 6 days ago
Asbjørn Sloth Tønnesen <ast@fiberby.net> writes:

> Allow using custom name-prefix with constants,
> just like it is for enum and flags declarations.
>
> This is needed for generating WG_KEY_LEN in
> include/uapi/linux/wireguard.h from a spec.
>
> Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>

Reviewed-by: Donald Hunter <donald.hunter@gmail.com>