Truly independent web browser
Meta: List the bundled modules of the Flatpak in its LICENSES.txt
Jelle Raaijmakers6241feefb52c
diff --git a/Documentation/AdvancedBuildInstructions.md b/Documentation/AdvancedBuildInstructions.mdindex 35b20bf4d3c..469476d6d9a 100644--- a/Documentation/AdvancedBuildInstructions.md+++ b/Documentation/AdvancedBuildInstructions.md@@ -136,6 +136,9 @@ This command will build the Flatpak bundle and install it into the local Flatpakto take a long time, as it will download and build all the dependencies of Ladybird as well. `flatpak-builder` will dropcaches and build files in `.flatpak-builder`, as well as in the two subfolders `Build/repo` and `Build/flatpak`.+`flatpak-builder` 1.4.5 and newer record the license files of the dependencies, which the `LICENSES.txt` of the+Flatpak reproduces. With an older version, `LICENSES.txt` only names the dependencies.+The Flatpak can be run with the following command:```bashdiff --git a/Meta/CMake/flatpak/angle/angle-install.sh b/Meta/CMake/flatpak/angle/angle-install.shindex 62e512ec004..4c043b0eb85 100755--- a/Meta/CMake/flatpak/angle/angle-install.sh+++ b/Meta/CMake/flatpak/angle/angle-install.sh@@ -23,6 +23,19 @@ for lib in "${libs[@]}"; doinstall -D -m644 out/"$lib" "$FLATPAK_DEST/lib/$lib"done+# Licenses: flatpak-builder only records those at the top of a module's source, and ANGLE is checked out below it,+# with the third-party code that it builds in.+licenses="$FLATPAK_DEST/share/licenses/$FLATPAK_ID/angle"+install -D -m644 LICENSE "$licenses/LICENSE"+shopt -s nullglob+# Some keep their license texts in a LICENSES directory.+for license in {,src/,src/common/}third_party/*/{LICENSE,COPYING}* third_party/*/{src,source}/{LICENSE,COPYING}*; do+ for file in "$license" "$license"/*; do+ [[ -f "$file" ]] && install -D -m644 "$file" "$licenses/${file//\//_}"+ done+done+shopt -u nullglob+# Pkg-configmkdir -p "$FLATPAK_DEST/lib/pkgconfig"cat > "$FLATPAK_DEST/lib/pkgconfig/angle.pc" <<EOFdiff --git a/Meta/CMake/flatpak/org.ladybird.Ladybird.json b/Meta/CMake/flatpak/org.ladybird.Ladybird.jsonindex 95810383cbd..40a61e377af 100644--- a/Meta/CMake/flatpak/org.ladybird.Ladybird.json+++ b/Meta/CMake/flatpak/org.ladybird.Ladybird.json@@ -478,6 +478,12 @@"tag": "v2.3.3"}],+ "license-files": [+ "COPYING",+ "src/lib/libdwarf/COPYING",+ "src/lib/libdwarf/LGPL.txt",+ "src/lib/libdwarf/LIBDWARFCOPYRIGHT"+ ],"config-opts": ["-DCMAKE_BUILD_TYPE=Release","-DCMAKE_PREFIX_PATH=/app",diff --git a/Meta/CMake/licenses.cmake b/Meta/CMake/licenses.cmakeindex ce40aca89eb..57de6c942c8 100644--- a/Meta/CMake/licenses.cmake+++ b/Meta/CMake/licenses.cmake@@ -28,8 +28,21 @@ if (NOT ENABLE_NETWORK_DOWNLOADS)list(APPEND licenses_arguments --offline)endif()-# Build Release publishes the source archives of the LGPL ports of a distribution build, so LICENSES.txt points to them.-if (LADYBIRD_VCPKG_TYPE STREQUAL "distribution" AND NOT LADYBIRD_VERSION STREQUAL "")+# flatpak-builder builds the other modules of the Flatpak, and records their license files for the app.+set(building_flatpak OFF)+if (DEFINED ENV{FLATPAK_ID} AND DEFINED ENV{FLATPAK_DEST})+ set(building_flatpak ON)+ set(flatpak_manifest "${LADYBIRD_SOURCE_DIR}/Meta/CMake/flatpak/org.ladybird.Ladybird.json")+ list(APPEND licenses_arguments+ --flatpak-manifest "${flatpak_manifest}"+ --flatpak-licenses-dir "$ENV{FLATPAK_DEST}/share/licenses/$ENV{FLATPAK_ID}"+ )+ list(APPEND licenses_dependencies "${flatpak_manifest}")+endif()++# Build Release publishes the source archives of the LGPL libraries of a distribution build and of the Flatpak, so+# LICENSES.txt points to them.+if ((LADYBIRD_VCPKG_TYPE STREQUAL "distribution" OR building_flatpak) AND NOT LADYBIRD_VERSION STREQUAL "")list(APPEND licenses_arguments --release)endif()diff --git a/Meta/generate-licenses.py b/Meta/generate-licenses.pyindex 12fdd5b5349..d5f8af558eb 100755--- a/Meta/generate-licenses.py+++ b/Meta/generate-licenses.py@@ -73,6 +73,15 @@ class Port:spdx_path: pathlib.Path+@dataclass+class FlatpakModule:+ name: str+ version: str+ copyright: str+ definition: dict[str, Any]+ manifest_dir: pathlib.Path++@dataclassclass SourceDownload:file_name: str@@ -448,11 +457,61 @@ def flatpak_archive_name(module: dict[str, Any], manifest_dir: pathlib.Path) ->path = flatpak_patch(module, source, manifest_dir)lines.append(f"patch {source['path']} {hashlib.sha256(path.read_bytes()).hexdigest()}")digest = hashlib.sha256("\n".join(lines).encode()).hexdigest()- git = next((source for source in module["sources"] if source.get("type") == "git"), {})- version = git.get("tag") or git.get("commit", "")[:12] or "source"+ version = flatpak_module_version(module) or "source"return UNSAFE_NAME_CHARACTERS.sub("_", f"{module['name']}-{version}-{digest[:12]}") + ".tar"+def flatpak_module_version(module: dict[str, Any]) -> str:+ for source in module.get("sources", []):+ if isinstance(source, dict) and source.get("type") == "git":+ return source.get("tag") or source.get("commit", "")[:12]+ if isinstance(source, dict) and source.get("type") == "archive":+ name = urllib.parse.urlparse(source["url"]).path.rpartition("/")[2]+ version = re.sub(r"\.tar(\.[a-z0-9]+)?$|\.zip$", "", name).removeprefix(f"{module['name']}-")+ return version[:12] if re.fullmatch(r"[0-9a-f]{40}", version) else version+ return ""+++# flatpak-builder 1.4.5 and newer record the license files of every module that they build in a directory of the+# module's name. A release needs them, while other builds may use an older flatpak-builder. A module that cleans up all+# of its files, such as a build tool, ships nothing.+def collect_flatpak_modules(+ manifest_path: pathlib.Path, licenses_dir: pathlib.Path, release: bool+) -> list[FlatpakModule]:+ manifest_dir = manifest_path.resolve().parent+ modules = []+ pending = list(json.loads(read_text(manifest_path))["modules"])+ while pending:+ module = pending.pop(0)+ if isinstance(module, str):+ raise RuntimeError(f"The Flatpak manifest includes the module file {module}, which this script cannot read")+ pending += module.get("modules", [])+ if module["name"] == "Ladybird" or module.get("cleanup") == ["*"]:+ continue+ directory = licenses_dir / module["name"]+ files = sorted(path for path in directory.iterdir() if path.is_file()) if directory.is_dir() else []+ if not files:+ message = (+ f"The Flatpak module {module['name']} ships files, but has no license files in {directory}, where "+ "flatpak-builder 1.4.5 and newer record them"+ )+ if release:+ raise RuntimeError(message)+ print(f"warning: {message}", file=sys.stderr)+ modules.append(+ FlatpakModule(+ module["name"],+ flatpak_module_version(module),+ "\n\n".join(read_text(path).strip() for path in files) + "\n"+ if files+ else "flatpak-builder recorded no license files of this module.\n",+ module,+ manifest_dir,+ )+ )+ return sorted(modules, key=lambda module: module.name.lower())++def fetch_git_source(source: dict[str, Any], work_dir: pathlib.Path) -> tuple[str, bytes]:reference = source.get("commit") or f"refs/tags/{source['tag']}"repository = work_dir / "git"@@ -644,39 +703,61 @@ def generate(args: argparse.Namespace) -> str:crates = linked_third_party_crates(metadata)crate_licenses = collect_crate_licenses(crates)+ modules = []+ if args.flatpak_manifest:+ if not args.flatpak_licenses_dir:+ raise RuntimeError(+ "The licenses of a Flatpak build need the directory that flatpak-builder records them in"+ )+ modules = collect_flatpak_modules(args.flatpak_manifest, args.flatpak_licenses_dir, args.release)+lgpl_ports = [port for port in ports if LGPL_MARKER in port.copyright]lgpl_libraries = read_lgpl_libraries(args.source_dir)- if unlisted_lgpl_ports := [port.name for port in lgpl_ports if port.name not in lgpl_libraries]:- raise RuntimeError(f"LGPL ports missing from {LGPL_LIBRARIES_PATH}: {', '.join(unlisted_lgpl_ports)}")+ unlisted = [port.name for port in lgpl_ports if port.name not in lgpl_libraries]+ unlisted += [+ module.name for module in modules if LGPL_MARKER in module.copyright and module.name not in lgpl_libraries+ ]+ if unlisted:+ raise RuntimeError(f"LGPL libraries missing from {LGPL_LIBRARIES_PATH}: {', '.join(unlisted)}")++ # Each with the archive that release-tools publishes its source code in.+ lgpl = [+ (f"{port.name} {port.version}", lambda port=port: read_port_source(port).archive_name()) for port in lgpl_ports+ ]+ lgpl += [+ (+ f"{module.name} {module.version}",+ lambda module=module: flatpak_archive_name(module.definition, module.manifest_dir),+ )+ for module in modules+ if module.name in lgpl_libraries+ ]introduction = ["Ladybird is distributed under the BSD 2-Clause License below. It includes the third-party software listed","after that, under the licenses reproduced with each of them.",]- if lgpl_ports and args.release:+ if lgpl and args.release:introduction += ["","This release of Ladybird uses the following libraries under the GNU Lesser General Public License. The","source code of each, with our patches and build scripts, is at the address below it:","",]- for port in lgpl_ports:- introduction += [- f" {port.name} {port.version}",- f" {THIRD_PARTY_SOURCES_URL}/{read_port_source(port).archive_name()}",- ]+ for library, archive_name in lgpl:+ introduction += [f" {library}", f" {THIRD_PARTY_SOURCES_URL}/{archive_name()}"]introduction += ["","The source code of Ladybird at https://github.com/LadybirdBrowser/ladybird contains everything needed to","build it against modified versions of these libraries.",]- elif lgpl_ports:+ elif lgpl:introduction += ["","This build of Ladybird uses the following libraries under the GNU Lesser General Public License:","",- *[f" {port.name} {port.version}" for port in lgpl_ports],+ *[f" {library}" for library, _ in lgpl],"","The source code of Ladybird at https://github.com/LadybirdBrowser/ladybird contains everything needed to","build it against modified versions of these libraries, and the build downloads the source code of each",@@ -689,6 +770,9 @@ def generate(args: argparse.Namespace) -> str:for port in ports:output.append(section(f"{port.name} {port.version}", port.copyright))+ for module in modules:+ output.append(section(f"{module.name} {module.version}".strip(), module.copyright))+for crate_license in crate_licenses:title = "\n".join(f"{crate} (Rust crate)" for crate in crate_license.crates)output.append(section(title, crate_license.text))@@ -719,7 +803,10 @@ def main() -> int:parser.add_argument("--flatpak-manifest",type=pathlib.Path,- help="with --third-party-sources, package the LGPL modules of this Flatpak manifest instead of vcpkg ports",+ help="list the modules of this Flatpak manifest, or with --third-party-sources, package its LGPL modules",+ )+ parser.add_argument(+ "--flatpak-licenses-dir", type=pathlib.Path, help="where flatpak-builder records the license files of modules")args = parser.parse_args()