|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright (c) 2025, The Ladybird contributors |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: BSD-2-Clause |
| 6 | + |
| 7 | +import glob |
| 8 | +import json |
| 9 | +import sys |
| 10 | + |
| 11 | +from enum import Enum |
| 12 | + |
| 13 | +VCPKG = "vcpkg.json" |
| 14 | +VCPKG_OVERLAYS_PORTS = "Meta/CMake/vcpkg/overlay-ports/*" |
| 15 | +FLATPAK_MANIFEST = "Meta/CMake/flatpak/org.ladybird.Ladybird.json" |
| 16 | +SELF = "Ladybird" |
| 17 | + |
| 18 | +# List of build tools that are not provided by the Flatpak SDK and therefor in the manifest |
| 19 | +# For a vcpkg build these are installed on the host system |
| 20 | +flatpak_build_tools = [ |
| 21 | + "gn", |
| 22 | +] |
| 23 | + |
| 24 | +# List of libraries that are dependencies of dependencies |
| 25 | +# These are in the manifest to fetch before the build but not explicitely versioned in vcpkg |
| 26 | +flatpak_deps_of_deps = [ |
| 27 | + "brotli", |
| 28 | + "dav1d", |
| 29 | + "highway", |
| 30 | + "libdwarf", |
| 31 | + "libxml2", |
| 32 | + "libyuv", |
| 33 | + "vulkan-memory-allocator", |
| 34 | + "zstd", |
| 35 | +] |
| 36 | + |
| 37 | +# List of libraries that are in the Flatpak runtime and therefor not in the manifest |
| 38 | +# See: https://docs.flatpak.org/en/latest/available-runtimes.html#check-software-available-in-runtimes |
| 39 | +flatpak_runtime_libs = [ |
| 40 | + "curl", |
| 41 | + "dbus", |
| 42 | + "ffmpeg", |
| 43 | + "fontconfig", |
| 44 | + "harfbuzz", |
| 45 | + "libjpeg-turbo", |
| 46 | + "libproxy", |
| 47 | + "openssl", |
| 48 | + "qtbase", |
| 49 | + "qtmultimedia", |
| 50 | + "sqlite3", |
| 51 | + "zlib", |
| 52 | +] |
| 53 | + |
| 54 | +# List of libraries that are in vcpkg but not needed for the Linux platform |
| 55 | +vcpkg_not_linux = [ |
| 56 | + "dirent", |
| 57 | + "mman", |
| 58 | +] |
| 59 | + |
| 60 | + |
| 61 | +class DepMatch(Enum): |
| 62 | + Match = (0,) |
| 63 | + NoMatch = (1,) |
| 64 | + VersionMismatch = (2,) |
| 65 | + Excluded = (3,) |
| 66 | + |
| 67 | + |
| 68 | +def check_for_match(vcpkg: dict, name: str, identifier: str) -> DepMatch: |
| 69 | + if name in vcpkg: |
| 70 | + if vcpkg[name] not in identifier: |
| 71 | + return DepMatch.VersionMismatch |
| 72 | + else: |
| 73 | + return DepMatch.Match |
| 74 | + elif name == SELF or name in flatpak_build_tools or name in flatpak_deps_of_deps: |
| 75 | + return DepMatch.Excluded |
| 76 | + else: |
| 77 | + return DepMatch.NoMatch |
| 78 | + |
| 79 | + |
| 80 | +def check_vcpkg_vs_flatpak_versioning(): |
| 81 | + vcpkg = {} |
| 82 | + flatpak = [] |
| 83 | + mismatch_found = False |
| 84 | + |
| 85 | + with open(VCPKG) as input: |
| 86 | + for package in json.load(input)["overrides"]: |
| 87 | + # Add name/version pair, strip any '#' postfix from the version |
| 88 | + vcpkg[package["name"]] = str(package["version"]).split("#")[0] |
| 89 | + |
| 90 | + # Check the vcpkg overlay ports for packages not listed in overrides |
| 91 | + for path in glob.glob(VCPKG_OVERLAYS_PORTS): |
| 92 | + with open(f"{path}/vcpkg.json") as input: |
| 93 | + overlay = json.load(input) |
| 94 | + |
| 95 | + if "name" in overlay and overlay["name"] not in vcpkg and "version" in overlay: |
| 96 | + vcpkg[overlay["name"]] = overlay["version"] |
| 97 | + |
| 98 | + with open(FLATPAK_MANIFEST) as input: |
| 99 | + for module in json.load(input)["modules"]: |
| 100 | + name = module["name"] |
| 101 | + |
| 102 | + for source in module["sources"]: |
| 103 | + if "type" in source and source["type"] == "git": |
| 104 | + if "tag" in source: |
| 105 | + # Get the tag |
| 106 | + # Replace '-' with '.': 76-1 vs 76.1 |
| 107 | + tag = str(source["tag"]).replace("-", ".") |
| 108 | + dep_match = check_for_match(vcpkg, name, tag) |
| 109 | + |
| 110 | + if dep_match == DepMatch.Match or dep_match == DepMatch.Excluded: |
| 111 | + if name in vcpkg: |
| 112 | + del vcpkg[name] |
| 113 | + else: |
| 114 | + mismatch_found = True |
| 115 | + |
| 116 | + if dep_match == DepMatch.VersionMismatch: |
| 117 | + print(f"{name} version mismatch. vcpkg: {vcpkg[name]}, Flatpak: {source['tag']}") |
| 118 | + del vcpkg[name] |
| 119 | + elif dep_match == DepMatch.NoMatch: |
| 120 | + flatpak.append(name) |
| 121 | + |
| 122 | + break |
| 123 | + elif "branch" in source: |
| 124 | + # Get the branch |
| 125 | + # Strip '_' postfix, replace '/' with '_': chromium/7258_13 vs chromium_7258 |
| 126 | + branch = str(source["branch"]).split("_")[0].replace("/", "_") |
| 127 | + dep_match = check_for_match(vcpkg, name, branch) |
| 128 | + |
| 129 | + if dep_match == DepMatch.Match or dep_match == DepMatch.Excluded: |
| 130 | + if name in vcpkg: |
| 131 | + del vcpkg[name] |
| 132 | + else: |
| 133 | + mismatch_found = True |
| 134 | + |
| 135 | + if dep_match == DepMatch.VersionMismatch: |
| 136 | + print(f"{name} version mismatch. vcpkg: {vcpkg[name]}, Flatpak: {source['branch']}") |
| 137 | + del vcpkg[name] |
| 138 | + elif DepMatch == DepMatch.NoMatch: |
| 139 | + flatpak.append(name) |
| 140 | + |
| 141 | + break |
| 142 | + else: |
| 143 | + if not (name == SELF or name in flatpak_build_tools or name in flatpak_deps_of_deps): |
| 144 | + flatpak.append(name) |
| 145 | + |
| 146 | + # Remove excluded dependencies from the vcpkg list |
| 147 | + for name in flatpak_runtime_libs + vcpkg_not_linux: |
| 148 | + if name in vcpkg: |
| 149 | + del vcpkg[name] |
| 150 | + |
| 151 | + if len(vcpkg): |
| 152 | + mismatch_found = True |
| 153 | + print(f"There are {len(vcpkg)} vcpkg dependencies that have no match in flatpak") |
| 154 | + |
| 155 | + for name in vcpkg.keys(): |
| 156 | + print(f"- {name}") |
| 157 | + |
| 158 | + if len(flatpak): |
| 159 | + mismatch_found = True |
| 160 | + print(f"There are {len(flatpak)} flatpak dependencies that have no match in vcpkg") |
| 161 | + |
| 162 | + for name in flatpak: |
| 163 | + print(f"- {name}") |
| 164 | + |
| 165 | + return mismatch_found |
| 166 | + |
| 167 | + |
| 168 | +def main(): |
| 169 | + file_list = sys.argv[1:] if len(sys.argv) > 1 else [VCPKG] |
| 170 | + did_fail = False |
| 171 | + |
| 172 | + if VCPKG in file_list or FLATPAK_MANIFEST in file_list: |
| 173 | + did_fail = check_vcpkg_vs_flatpak_versioning() |
| 174 | + |
| 175 | + # TODO: Add linting of Flatpak and AppStream manifest |
| 176 | + # See #5594, bullet point "Missing lint job in CI to ensure Flatpak and AppStream manifests are up to snuff" |
| 177 | + |
| 178 | + if did_fail: |
| 179 | + sys.exit(1) |
| 180 | + |
| 181 | + |
| 182 | +if __name__ == "__main__": |
| 183 | + main() |
0 commit comments