#56180: build: generate LICENSES.chromium.html without patching licenses.py
Merged
Part of #56164.
Replaces patches/chromium/add_electron_deps_to_license_credits_file.patch with an Electron-owned metadata file (build/licenses/README.chromium) and a small wrapper script (script/generate-credits.py) that //electron:chromium_licenses runs from BUILD.gn.
Summary of Changes
- Add
build/licenses/README.chromium: Describes the shipped ElectronDEPScheckouts that have no metadata file of their own (Node.js,Squirrel,Mantle,ReactiveObjC,Sparkle), usinglicenses.py's multi-dependency format (DEPENDENCY DIVIDER) and//-rootedLicense Filepaths.licenses.pyreservesSPECIAL_CASESfor historical directories and asks new cases to useREADME.chromium. - Add
script/generate-credits.py: Checks that file withlicenses.ParseDirand fails on any error, then runslicenses.main()with the file's directory added through--extra-third-party-dirs, the hook Chromium's ownabout_creditsaction offers downstream projects. It overrides none oflicenses.py's globals. The check is needed becauselicenses.py creditssilently drops an entry it can't parse or whose license file is missing. - Fix latent omission of
Mantle,ReactiveObjC, andSparkle:- Under the old patch,
squirrel.mac/vendor/{Mantle,ReactiveObjC,Sparkle}lived undervendor/(notthird_party/) and were never added toADDITIONAL_PATHS, soFindThirdPartyDirsnever visited them and all three were silently omitted fromLICENSES.chromium.html. - In addition,
Mantleused lowercasevendor/mantle(failing on case-sensitive Linux filesystems whereDEPSchecks outvendor/Mantle), had astr-typed"License File"instead of alist, and the entries omitted"Shipped": "yes".
- Under the old patch,
- Update
BUILD.gn: Replacecopy("chromium_licenses")depending on//components/resources:about_creditswith agenerate_chromium_licenses = is_official_buildGN arg:- When
true,action("chromium_licenses")runs//electron/script/generate-credits.pywith--target-os=$target_osand--depfileto produce$root_build_dir/LICENSES.chromium.html.build/licenses/README.chromiumis one of itsinputs. - When
false(default developer/testing builds),copy("chromium_licenses")copies//components/resources/sample_credits.htmlso non-official builds stay fast.
- When
- Set
generate_about_credits = falseinbuild/args/all.gn: Electron has nochrome://creditspage, so this prevents official builds from running a redundant, unpatchedlicenses.pyfilesystem scan inside//components/resources:about_credits.IDR_ABOUT_UI_CREDITS_HTMLstill ships incomponents_resources.pak, now holding the sample page. - Remove
patches/chromium/add_electron_deps_to_license_credits_file.patchand its entry inpatches/chromium/.patches. - Siso hygiene: Verified in
build/config/siso/denylist.starandmain.starthat Pythonaction()scripts run locally unless-config=default-remoteis enabled (which Electron does not use), matching Electron's existing//electron/script/*.pyactions.
Verification
PR CI doesn't run this action: PR builds use testing.gn, where generate_chromium_licenses is false. Everything below was run locally on main (Chromium 160.0.8193.0).
- Full-tree run: Ran
script/generate-credits.py credits --target-os=linux --depfile <file> <output>, the argumentsBUILD.gnpasses. It wrote a 5,828,899-byteLICENSES.chromium.htmlwith 499 entries, includingNode.js,Squirrel,Mantle,ReactiveObjC, andSparklewith their full license texts. The output is byte-identical to that of the previous,SPECIAL_CASES-based revision of the script (7025b45). - Compared with the old patch: Diffed
LICENSES.chromium.htmlbefore vs. after (against unpatched Chromium160.0.8193.0tools/licenses/licenses.py): zero removed lines; all upstream Chromium licenses plusNode.jsandSquirrelare byte-for-byte identical, andMantle,ReactiveObjC, andSparklenow appear with their full license texts. - GN and Siso: Generated a scratch out dir from
release.gn(is_official_build = true, sogenerate_chromium_licensesdefaults totrue) and builtelectron:chromium_licenseswithsiso -offline. The action succeeded, and its output matched the direct run byte for byte. - Incremental builds, in the same out dir:
- A rebuild with no changes runs 0 steps.
- Touching
build/licenses/README.chromium(aninputsentry) reruns the action.licenses.pydoesn't rewrite unchanged output, so the file's mtime stays put and nothing downstream rebuilds. - Touching
third_party/squirrel.mac/vendor/Sparkle/LICENSE, which is tracked only through the depfile, reruns the action.
- Error handling, with the tree walk stubbed out: pointing a
README.chromiumentry'sLicense Fileat a missing file makes the script fail before it writes anything. TheSPECIAL_CASESrevision passed the same test and renderedSparklewith an empty license, becauselicenses.pykeepsSPECIAL_CASESentries whose license file is missing. - Build modes:
testing.gn(is_official_build = false)://electron:chromium_licensesand//components/resources:about_creditsboth resolve tocopy(sample_credits.html).release.gn(is_official_build = true)://electron:chromium_licensesresolves toaction(script/generate-credits.py), and//components/resources:about_creditsstayscopy(sample_credits.html).
- Lint:
pylint,gn format, andgn checkpass on every commit (pre-commit hooks).check-patch-diff.mtspassed on the first commit; the later commits don't touchpatches/.
Notes: none
Backports
Semver Impact
Major
Breaking changes
Minor
New features
Patch
Bug fixes
None
Docs, tests, etc.
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron