Skip to content

Commit cfab77c

Browse files
committed
ynl: make the tooling check the license
The (only recently documented) expectation is that all specs are under a certain license, but we don't actually enforce it. What's worse we then go ahead and assume the license was right, outputting the expected license into generated files. Fixes: 37d9df2 ("ynl: re-license uniformly under GPL-2.0 OR BSD-3-Clause") Reviewed-by: Chuck Lever <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4e16b6a commit cfab77c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

tools/net/ynl/lib/nlspec.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ class SpecFamily(SpecElement):
274274
275275
Attributes:
276276
proto protocol type (e.g. genetlink)
277+
license spec license (loaded from an SPDX tag on the spec)
277278
278279
attr_sets dict of attribute sets
279280
msgs dict of all messages (index by name)
@@ -283,6 +284,13 @@ class SpecFamily(SpecElement):
283284
"""
284285
def __init__(self, spec_path, schema_path=None):
285286
with open(spec_path, "r") as stream:
287+
prefix = '# SPDX-License-Identifier: '
288+
first = stream.readline().strip()
289+
if not first.startswith(prefix):
290+
raise Exception('SPDX license tag required in the spec')
291+
self.license = first[len(prefix):]
292+
293+
stream.seek(0)
286294
spec = yaml.safe_load(stream)
287295

288296
self._resolution_list = []

tools/net/ynl/ynl-gen-c.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,10 @@ def main():
20592059

20602060
try:
20612061
parsed = Family(args.spec)
2062+
if parsed.license != '((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)':
2063+
print('Spec license:', parsed.license)
2064+
print('License must be: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)')
2065+
os.sys.exit(1)
20622066
except yaml.YAMLError as exc:
20632067
print(exc)
20642068
os.sys.exit(1)
@@ -2067,13 +2071,10 @@ def main():
20672071
cw = CodeWriter(BaseNlLib(), out_file)
20682072

20692073
_, spec_kernel = find_kernel_root(args.spec)
2070-
if args.mode == 'uapi':
2071-
cw.p('/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */')
2074+
if args.mode == 'uapi' or args.header:
2075+
cw.p(f'/* SPDX-License-Identifier: {parsed.license} */')
20722076
else:
2073-
if args.header:
2074-
cw.p('/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */')
2075-
else:
2076-
cw.p('// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)')
2077+
cw.p(f'// SPDX-License-Identifier: {parsed.license}')
20772078
cw.p("/* Do not edit directly, auto-generated from: */")
20782079
cw.p(f"/*\t{spec_kernel} */")
20792080
cw.p(f"/* YNL-GEN {args.mode} {'header' if args.header else 'source'} */")

0 commit comments

Comments
 (0)