Added support for specifying a COPYRIGHT.txt file for modules.

This commit is contained in:
Relintai 2022-12-31 18:12:06 +01:00
parent 0a31a3b594
commit f70e207741
3 changed files with 38 additions and 21 deletions

View File

@ -610,11 +610,13 @@ if selected_platform in platform_list:
modules_enabled = OrderedDict() modules_enabled = OrderedDict()
env.module_dependencies = {} env.module_dependencies = {}
env.module_icons_paths = [] env.module_icons_paths = []
env.module_license_files = []
env.doc_class_path = {} env.doc_class_path = {}
for name, path in modules_detected.items(): for name, path in modules_detected.items():
if not env["module_" + name + "_enabled"]: if not env["module_" + name + "_enabled"]:
continue continue
sys.path.insert(0, path) sys.path.insert(0, path)
env.current_module = name env.current_module = name
import config import config
@ -625,6 +627,7 @@ if selected_platform in platform_list:
continue continue
config.configure(env) config.configure(env)
# Get doc classes paths (if present) # Get doc classes paths (if present)
try: try:
doc_classes = config.get_doc_classes() doc_classes = config.get_doc_classes()
@ -633,6 +636,7 @@ if selected_platform in platform_list:
env.doc_class_path[c] = path + "/" + doc_path env.doc_class_path[c] = path + "/" + doc_path
except Exception: except Exception:
pass pass
# Get icon paths (if present) # Get icon paths (if present)
try: try:
icons_path = config.get_icons_path() icons_path = config.get_icons_path()
@ -640,6 +644,14 @@ if selected_platform in platform_list:
except Exception: except Exception:
# Default path for module icons # Default path for module icons
env.module_icons_paths.append(path + "/" + "icons") env.module_icons_paths.append(path + "/" + "icons")
# Get license path (if present)
try:
license_file = config.get_license_file()
env.module_license_files.append("#" + path + "/" + license_file)
except Exception:
pass
modules_enabled[name] = path modules_enabled[name] = path
else: else:
env["module_" + name + "_enabled"] = False env["module_" + name + "_enabled"] = False

View File

@ -177,10 +177,13 @@ env.CommandNoCache("#core/authors.gen.h", "../AUTHORS.md", run_in_subprocess(cor
env.Depends("#core/donors.gen.h", "../DONORS.md") env.Depends("#core/donors.gen.h", "../DONORS.md")
env.CommandNoCache("#core/donors.gen.h", "../DONORS.md", run_in_subprocess(core_builders.make_donors_header)) env.CommandNoCache("#core/donors.gen.h", "../DONORS.md", run_in_subprocess(core_builders.make_donors_header))
license_files = [ "../LICENSE.txt", "../COPYRIGHT.txt" ]
license_files.extend(env.module_license_files)
# License # License
env.Depends("#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"]) env.Depends("#core/license.gen.h", license_files)
env.CommandNoCache( env.CommandNoCache(
"#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"], run_in_subprocess(core_builders.make_license_header) "#core/license.gen.h", license_files, run_in_subprocess(core_builders.make_license_header)
) )
# Chain load SCsubs # Chain load SCsubs

View File

@ -148,8 +148,7 @@ def make_donors_header(target, source, env):
def make_license_header(target, source, env): def make_license_header(target, source, env):
src_copyright = source[0] src_license = source[0]
src_license = source[1]
dst = target[0] dst = target[0]
class LicenseReader: class LicenseReader:
@ -181,24 +180,27 @@ def make_license_header(target, source, env):
projects = OrderedDict() projects = OrderedDict()
license_list = [] license_list = []
with open_utf8(src_copyright, "r") as copyright_file: for i in range(1, len(source)):
reader = LicenseReader(copyright_file) src_copyright = source[i]
part = {}
while reader.current: with open_utf8(src_copyright, "r") as copyright_file:
tag, content = reader.next_tag() reader = LicenseReader(copyright_file)
if tag in ("Files", "Copyright", "License"): part = {}
part[tag] = content[:] while reader.current:
elif tag == "Comment": tag, content = reader.next_tag()
# attach part to named project if tag in ("Files", "Copyright", "License"):
projects[content[0]] = projects.get(content[0], []) + [part] part[tag] = content[:]
elif tag == "Comment":
# attach part to named project
projects[content[0]] = projects.get(content[0], []) + [part]
if not tag or not reader.current: if not tag or not reader.current:
# end of a paragraph start a new part # end of a paragraph start a new part
if "License" in part and not "Files" in part: if "License" in part and not "Files" in part:
# no Files tag in this one, so assume standalone license # no Files tag in this one, so assume standalone license
license_list.append(part["License"]) license_list.append(part["License"])
part = {} part = {}
reader.next_line() reader.next_line()
data_list = [] data_list = []
for project in itervalues(projects): for project in itervalues(projects):