Commit cfab77c0 authored by Jakub Kicinski's avatar Jakub Kicinski

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: 37d9df22 ("ynl: re-license uniformly under GPL-2.0 OR BSD-3-Clause")
Reviewed-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 4e16b6a7
...@@ -274,6 +274,7 @@ class SpecFamily(SpecElement): ...@@ -274,6 +274,7 @@ class SpecFamily(SpecElement):
Attributes: Attributes:
proto protocol type (e.g. genetlink) proto protocol type (e.g. genetlink)
license spec license (loaded from an SPDX tag on the spec)
attr_sets dict of attribute sets attr_sets dict of attribute sets
msgs dict of all messages (index by name) msgs dict of all messages (index by name)
...@@ -283,6 +284,13 @@ class SpecFamily(SpecElement): ...@@ -283,6 +284,13 @@ class SpecFamily(SpecElement):
""" """
def __init__(self, spec_path, schema_path=None): def __init__(self, spec_path, schema_path=None):
with open(spec_path, "r") as stream: with open(spec_path, "r") as stream:
prefix = '# SPDX-License-Identifier: '
first = stream.readline().strip()
if not first.startswith(prefix):
raise Exception('SPDX license tag required in the spec')
self.license = first[len(prefix):]
stream.seek(0)
spec = yaml.safe_load(stream) spec = yaml.safe_load(stream)
self._resolution_list = [] self._resolution_list = []
......
...@@ -2059,6 +2059,10 @@ def main(): ...@@ -2059,6 +2059,10 @@ def main():
try: try:
parsed = Family(args.spec) parsed = Family(args.spec)
if parsed.license != '((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)':
print('Spec license:', parsed.license)
print('License must be: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)')
os.sys.exit(1)
except yaml.YAMLError as exc: except yaml.YAMLError as exc:
print(exc) print(exc)
os.sys.exit(1) os.sys.exit(1)
...@@ -2067,13 +2071,10 @@ def main(): ...@@ -2067,13 +2071,10 @@ def main():
cw = CodeWriter(BaseNlLib(), out_file) cw = CodeWriter(BaseNlLib(), out_file)
_, spec_kernel = find_kernel_root(args.spec) _, spec_kernel = find_kernel_root(args.spec)
if args.mode == 'uapi': if args.mode == 'uapi' or args.header:
cw.p('/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */') cw.p(f'/* SPDX-License-Identifier: {parsed.license} */')
else:
if args.header:
cw.p('/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */')
else: else:
cw.p('// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)') cw.p(f'// SPDX-License-Identifier: {parsed.license}')
cw.p("/* Do not edit directly, auto-generated from: */") cw.p("/* Do not edit directly, auto-generated from: */")
cw.p(f"/*\t{spec_kernel} */") cw.p(f"/*\t{spec_kernel} */")
cw.p(f"/* YNL-GEN {args.mode} {'header' if args.header else 'source'} */") cw.p(f"/* YNL-GEN {args.mode} {'header' if args.header else 'source'} */")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment