#!/usr/bin/env python3 """Junta os textos de licenca dos modulos Go que entram no .wasm (go list -deps) e o da biblioteca padrao do Go. python3 -I licenses.py < lista A lista (stdin) tem uma linha "caminho|versao|pasta" por modulo, que o go_licenses de common.sh tira do `go list -deps`. Para cada modulo, todo arquivo LICENSE*/COPYING*/NOTICE*/PATENTS* da raiz do modulo entra, com cabecalho e sem mudanca. Modulo sem nenhum desses arquivos e avisado (a build falha, para alguem olhar). Ordem alfabetica: a saida e igual a cada execucao. """ import os import re import sys goroot, out, title = sys.argv[1:4] mods = sorted({tuple(l.rstrip("\n").split("|")) for l in sys.stdin if l.strip()}) pat = re.compile(r"^(LICEN[SC]E|COPYING|NOTICE|PATENTS)([-._].*)?$", re.I) parts = [title + " - licences of the Go libraries compiled into the WebAssembly module\n" + "=" * 70 + "\n\n" "Generated by Builds/go-ebiten/licenses.py from `go list -deps` of the build (GOOS=js GOARCH=wasm): the Go runtime and standard\n" "library, then every Go module that has a package in the binary, each with the licence files at the root of the module, unchanged.\n"] missing = [] def add(name, version, files): parts.append("\n" + "=" * 78 + "\n" + name + (" " + version if version else "") + "\n" + "=" * 78 + "\n") for path in files: parts.append("\n--- " + os.path.basename(path) + " ---\n\n") with open(path, encoding="utf-8", errors="replace") as f: parts.append(f.read().rstrip("\n") + "\n") add("Go runtime and standard library", "", [os.path.join(goroot, "LICENSE"), os.path.join(goroot, "PATENTS")]) for name, version, d in mods: files = sorted(os.path.join(d, f) for f in os.listdir(d) if pat.match(f) and os.path.isfile(os.path.join(d, f))) if not files: missing.append(name) continue add(name, version, files) if missing: print("Sem arquivo de licenca na raiz do modulo: " + ", ".join(missing), file=sys.stderr) with open(out, "w", encoding="utf-8") as f: f.write("".join(parts)) print(f"{len(mods)} modulos, {len(missing)} sem licenca na raiz") if missing and os.environ.get("ALLOW_MISSING_LICENSES") != "1": sys.exit(1)