make-sbom.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #!/usr/bin/env bash
  2. # Writes an SPDX 2.3 JSON software bill of materials of LYNX SHARE's third-party components (round 190nr, 0.1.31).
  3. #
  4. # scripts/make-sbom.sh <version label, e.g. 0.1.31-alpha> <output .spdx.json> [licenses folder]
  5. #
  6. # Sources: the component table of THIRD_PARTY.md (name, link, version, licence) and the licence texts the packages
  7. # carry in licenses/ (scripts/collect-licenses.sh; run into a temporary folder when no folder is given). The SPDX
  8. # licence expression, version and third_party/ folder of each row come from the COMPONENTS table below, keyed by the
  9. # row's first link text: a THIRD_PARTY.md row without an entry there, or a licences folder entry that no component
  10. # claims, stops the script, so the SBOM can't silently fall behind THIRD_PARTY.md. Plain bash + python3.
  11. set -euo pipefail
  12. LABEL="${1:?usage: scripts/make-sbom.sh <version label> <output .spdx.json> [licenses folder]}"
  13. OUT="${2:?usage: scripts/make-sbom.sh <version label> <output .spdx.json> [licenses folder]}"
  14. LIC="${3:-}"
  15. case "$OUT" in /*) ;; *) OUT="$PWD/$OUT" ;; esac
  16. case "$LIC" in /*|"") ;; *) LIC="$PWD/$LIC" ;; esac
  17. cd "$(dirname "$0")/.."
  18. TMP=""
  19. if [ -z "$LIC" ]; then
  20. TMP="$(mktemp -d)"; trap 'rm -rf "$TMP"' EXIT
  21. scripts/collect-licenses.sh "$TMP/licenses" > /dev/null
  22. LIC="$TMP/licenses"
  23. fi
  24. COMMIT="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
  25. python3 - "$LABEL" "$OUT" "$LIC" "$COMMIT" <<'PY'
  26. import datetime, json, os, re, sys, uuid
  27. label, out, lic_dir, commit = sys.argv[1:5]
  28. # key (first link text of the THIRD_PARTY.md row, or the row's plain text start) ->
  29. # version (None: the one in the key), SPDX licence LYNX uses it under (concluded), declared licence,
  30. # third_party/ folders whose licence files belong to it, shipped (False: reference only, not in the SBOM).
  31. NOA = "NOASSERTION"
  32. COMPONENTS = {
  33. "JUCE 8": dict(version="8.0.4", concluded="AGPL-3.0-only", declared="AGPL-3.0-only OR LicenseRef-JUCE-Commercial",
  34. folders=[]),
  35. "CLAP": dict(version="1.2.2", concluded="MIT", folders=["clap"]),
  36. "WavPack": dict(version="5.7.0", concluded="BSD-3-Clause", folders=["wavpack"]),
  37. "libogg 1.3.5 and libvorbis 1.3.7": dict(split=[("libogg", "1.3.5"), ("libvorbis", "1.3.7")],
  38. concluded="BSD-3-Clause", folders=["vorbis"]),
  39. "LAME 3.100": dict(concluded="LGPL-2.0-or-later", folders=["lame"]),
  40. "TinySoundFont 0.9": dict(concluded="MIT", folders=["tinysoundfont"]),
  41. "File-format references": dict(shipped=False),
  42. "stb_vorbis 1.22": dict(concluded="MIT", declared="MIT OR Unlicense", folders=["stb_vorbis"]),
  43. "minimp3": dict(version="ea99364f61c14656440e8d77e9c233ccf3124633", concluded="CC0-1.0", folders=["minimp3"]),
  44. "mda ePiano sample data": dict(version="mda-vst-src-2015-06-18", concluded="MIT", declared="MIT OR GPL-2.0-or-later", folders=["mda-epiano"]),
  45. "VCSL \"Upright Piano, Yamaha\"": dict(version="VCSL master (2026-11-29)", name="VCSL Upright Piano, Yamaha (samples)", concluded="CC0-1.0", folders=["vcsl-upright"]),
  46. "Signalsmith Stretch 1.4": dict(concluded="MIT", folders=["signalsmith"]),
  47. "Signalsmith Linear 0.6.6": dict(concluded="MIT", folders=["signalsmith"]),
  48. "pocketpy 2.2.0": dict(concluded="MIT", folders=["pocketpy"]),
  49. "Monocypher 4.0.2": dict(concluded="BSD-2-Clause", declared="BSD-2-Clause OR CC0-1.0", folders=["monocypher"]),
  50. "Faust Libraries": dict(version="1.6.2", name="Faust Libraries reverbs.lib (re.valhallaSupermassive, ported)",
  51. concluded="MIT", folders=[]),
  52. "PipeWire 1.6.2": dict(name="PipeWire headers", concluded="MIT", folders=["pipewire"]),
  53. "Ableton Link 4.1.1": dict(concluded="GPL-2.0-or-later", folders=["link"], exclude=["link-asio"]),
  54. "Asio 1.38.2": dict(concluded="BSL-1.0", folders=["link-asio"]),
  55. "VST 3 SDK": dict(version="3.7.12 (bundled with JUCE 8.0.4)", concluded="GPL-3.0-only",
  56. declared="GPL-3.0-only OR LicenseRef-Steinberg-Proprietary", folders=[], extra=["GPL-3.0.txt"]),
  57. "ARA SDK 2.1.0": dict(concluded="Apache-2.0", folders=["ara"]),
  58. "ASIO SDK 2.3.4": dict(concluded="GPL-3.0-only", declared="GPL-3.0-only OR LicenseRef-Steinberg-Proprietary",
  59. folders=["asiosdk"], extra=["GPL-3.0.txt"]),
  60. "ONNX Runtime 1.23.2": dict(concluded="MIT", folders=["onnxruntime"]),
  61. "Basic Pitch": dict(version="fa5997a", concluded="Apache-2.0", folders=["basic-pitch"]),
  62. "PitchNet": dict(version="121b330", name="PitchNet polyphonic engine", concluded="AGPL-3.0-only",
  63. folders=["pitchnet-poly"]),
  64. "Libraries bundled inside JUCE's modules": dict(split_libs=[
  65. ("HarfBuzz", "MIT", "https://github.com/harfbuzz/harfbuzz"),
  66. ("SheenBidi", "Apache-2.0", "https://github.com/Tehreer/SheenBidi"),
  67. ("FLAC", "BSD-3-Clause", "https://xiph.org/flac/"),
  68. ("Ogg/Vorbis (JUCE copy)", "BSD-3-Clause", "https://xiph.org/vorbis/"),
  69. ("libpng", "Libpng", "http://www.libpng.org/pub/png/libpng.html"),
  70. ("IJG libjpeg", "IJG", "https://ijg.org"),
  71. ("zlib", "Zlib", "https://zlib.net")]),
  72. "sse2neon": dict(version=NOA, concluded="MIT", folders=["sse2neon"]),
  73. # round 190qd (0.1.31): the tracker module reader, the JSFX host and the bundled JSFX pack
  74. "libxmp-lite 4.7.4": dict(concluded="MIT", folders=["libxmp-lite"]),
  75. "ysfx 0.0.47": dict(name="ysfx (with Cockos WDL / EEL2, the EEL2 GAS port and dr_libs)",
  76. concluded="Apache-2.0 AND Zlib AND (Unlicense OR MIT-0)", folders=["ysfx"]),
  77. "chokehold JSFX": dict(version="f6d175d8", concluded="MIT", folders=["jsfx-chokehold"]),
  78. "Open Sans": dict(concluded="OFL-1.1", folders=[], extra=["open-sans-OFL.txt"]),
  79. "Open Sans Condensed": dict(concluded="OFL-1.1", folders=[], extra=["open-sans-OFL.txt"]),
  80. }
  81. # Components that have a licence file in licenses/ but no row of their own in THIRD_PARTY.md's table.
  82. EXTRA_ROWS = {}
  83. LICENSE_REFS = {
  84. "LicenseRef-JUCE-Commercial": ("JUCE commercial licence",
  85. "JUCE 8 is also offered under a commercial licence by Raw Material Software; LYNX uses JUCE under the AGPL-3.0."),
  86. "LicenseRef-Steinberg-Proprietary": ("Steinberg proprietary SDK licence",
  87. "Steinberg offers the VST 3 and ASIO SDKs under a proprietary licence or the GPLv3; LYNX takes the GPLv3 option."),
  88. }
  89. rows = []
  90. for line in open("THIRD_PARTY.md", encoding="utf-8"):
  91. if not line.startswith("| ") or line.startswith("| Component") or line.startswith("|---"):
  92. continue
  93. cells = [c.strip() for c in line.strip().strip("|").split(" | ")]
  94. rows.append(cells)
  95. if not rows:
  96. sys.exit("make-sbom: no component table in THIRD_PARTY.md")
  97. def spdx_id(name):
  98. return "SPDXRef-" + re.sub(r"[^A-Za-z0-9.-]+", "-", name).strip("-")
  99. packages, claimed, errors = [], set(), []
  100. lic_files = sorted(f for f in os.listdir(lic_dir) if f != "README.txt")
  101. def files_for(spec):
  102. names = []
  103. for folder in spec.get("folders", []):
  104. for f in lic_files:
  105. if f.startswith(folder + "-") and not any(f.startswith(x + "-") for x in spec.get("exclude", [])):
  106. names.append(f)
  107. names += [f for f in spec.get("extra", []) if f in lic_files]
  108. claimed.update(names)
  109. return names
  110. def add(name, version, url, concluded, declared, used_for, licence_files):
  111. comment = "Used for: " + re.sub(r"\s+", " ", re.sub(r"[`*]", "", used_for)).strip()
  112. if licence_files:
  113. comment += ". Licence texts in the package's licenses folder: " + ", ".join(licence_files)
  114. packages.append({
  115. "name": name, "SPDXID": spdx_id(name), "versionInfo": version or NOA,
  116. "downloadLocation": url or NOA, "filesAnalyzed": False,
  117. "licenseConcluded": concluded, "licenseDeclared": declared or concluded,
  118. "copyrightText": NOA, "supplier": NOA, "comment": comment,
  119. })
  120. for cells in rows:
  121. first, used_for = cells[0], cells[1] if len(cells) > 1 else ""
  122. links = re.findall(r"\[([^\]]+)\]\(([^)]+)\)", first)
  123. key = links[0][0] if links else first
  124. spec = COMPONENTS.get(key) or next((v for k, v in COMPONENTS.items() if first.startswith(k)), None)
  125. if spec is None:
  126. errors.append(f"THIRD_PARTY.md row '{first[:60]}' has no entry in scripts/make-sbom.sh COMPONENTS")
  127. continue
  128. if spec.get("shipped") is False:
  129. continue
  130. if "split_libs" in spec:
  131. for name, lic, url in spec["split_libs"]:
  132. add(name, "bundled with JUCE 8.0.4", url, lic, None, used_for, [])
  133. continue
  134. # one row can name several projects ([Signalsmith Stretch 1.4](..) and [Signalsmith Linear 0.6.6](..), Link + Asio)
  135. for text, url in (links or [(key, None)]):
  136. spec2 = COMPONENTS.get(text)
  137. if spec2 is None:
  138. if text == key:
  139. spec2 = spec
  140. else:
  141. continue # a link inside the description (a source library, a dataset): not a component
  142. if "split" in spec2:
  143. files = files_for(spec2)
  144. for name, ver in spec2["split"]:
  145. add(name, ver, url, spec2["concluded"], spec2.get("declared"), used_for,
  146. [f for f in files if ("copying." + name) in f.lower()] or files)
  147. continue
  148. m = re.match(r"^(.*?)\s+(\d+(?:\.\d+)+)$", text)
  149. name = spec2.get("name") or (m.group(1) if m else text)
  150. version = spec2.get("version") or (m.group(2) if m else None)
  151. add(name, version, url, spec2["concluded"], spec2.get("declared"), used_for, files_for(spec2))
  152. for key, spec in EXTRA_ROWS.items():
  153. add(key, spec["version"], spec["url"], spec["concluded"], None, spec["used_for"], files_for(spec))
  154. for f in lic_files:
  155. if f not in claimed:
  156. errors.append(f"licences folder file {f} belongs to no SBOM component (add it to THIRD_PARTY.md / make-sbom.sh)")
  157. if errors:
  158. sys.exit("make-sbom:\n " + "\n ".join(errors))
  159. ids = [p["SPDXID"] for p in packages]
  160. if len(ids) != len(set(ids)):
  161. sys.exit("make-sbom: duplicate SPDX ids: " + ", ".join(sorted({i for i in ids if ids.count(i) > 1})))
  162. root = {
  163. "name": "LYNX SHARE", "SPDXID": "SPDXRef-LYNX-SHARE", "versionInfo": label,
  164. "downloadLocation": f"git+https://github.com/Ka1-S/LYNX-SHARE@{commit}" if commit != "unknown"
  165. else "https://github.com/Ka1-S/LYNX-SHARE",
  166. "homepage": "https://lynx-share.com", "filesAnalyzed": False,
  167. "licenseConcluded": "AGPL-3.0-only", "licenseDeclared": "AGPL-3.0-only",
  168. "copyrightText": NOA, "supplier": "Person: Ka1-S",
  169. "primaryPackagePurpose": "APPLICATION",
  170. }
  171. used_refs = sorted({r for p in packages for r in re.findall(r"LicenseRef-[A-Za-z0-9.-]+", p["licenseDeclared"])})
  172. doc = {
  173. "spdxVersion": "SPDX-2.3",
  174. "dataLicense": "CC0-1.0",
  175. "SPDXID": "SPDXRef-DOCUMENT",
  176. "name": f"LYNX-SHARE-{label}",
  177. "documentNamespace": f"https://github.com/Ka1-S/LYNX-SHARE/releases/v{label}/sbom-{uuid.uuid4()}",
  178. "creationInfo": {
  179. "created": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
  180. "creators": ["Tool: LYNX-SHARE scripts/make-sbom.sh", "Organization: LYNX SHARE"],
  181. "comment": "Third-party components of LYNX SHARE, from THIRD_PARTY.md and the packages' licenses folder.",
  182. },
  183. "documentDescribes": ["SPDXRef-LYNX-SHARE"],
  184. "packages": [root] + packages,
  185. "relationships": [{"spdxElementId": "SPDXRef-DOCUMENT", "relationshipType": "DESCRIBES",
  186. "relatedSpdxElement": "SPDXRef-LYNX-SHARE"}] +
  187. [{"spdxElementId": "SPDXRef-LYNX-SHARE", "relationshipType": "CONTAINS",
  188. "relatedSpdxElement": p["SPDXID"]} for p in packages],
  189. }
  190. if used_refs:
  191. doc["hasExtractedLicensingInfos"] = [{"licenseId": r, "name": LICENSE_REFS[r][0], "extractedText": LICENSE_REFS[r][1]}
  192. for r in used_refs]
  193. with open(out, "w", encoding="utf-8") as fh:
  194. json.dump(doc, fh, indent=2, ensure_ascii=False)
  195. fh.write("\n")
  196. print(f"make-sbom: {len(packages)} components -> {out}")
  197. PY