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()
env.module_dependencies = {}
env.module_icons_paths = []
env.module_license_files = []
env.doc_class_path = {}
for name, path in modules_detected.items():
if not env["module_" + name + "_enabled"]:
continue
sys.path.insert(0, path)
env.current_module = name
import config
@ -625,6 +627,7 @@ if selected_platform in platform_list:
continue
config.configure(env)
# Get doc classes paths (if present)
try:
doc_classes = config.get_doc_classes()
@ -633,6 +636,7 @@ if selected_platform in platform_list:
env.doc_class_path[c] = path + "/" + doc_path
except Exception:
pass
# Get icon paths (if present)
try:
icons_path = config.get_icons_path()
@ -640,6 +644,14 @@ if selected_platform in platform_list:
except Exception:
# Default path for module 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
else:
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.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
env.Depends("#core/license.gen.h", ["../COPYRIGHT.txt", "../LICENSE.txt"])
env.Depends("#core/license.gen.h", license_files)
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

View File

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