66
77import glob
88import json
9+ import os
10+ import subprocess
911import sys
1012
1113from enum import Enum
1214
1315VCPKG = "vcpkg.json"
1416VCPKG_OVERLAYS_PORTS = "Meta/CMake/vcpkg/overlay-ports/*"
17+ VCPKG_URL = "https://github.com/microsoft/vcpkg.git"
18+ VCPKG_REPO = "Build/vcpkg"
1519FLATPAK_MANIFEST = "Meta/CMake/flatpak/org.ladybird.Ladybird.json"
1620SELF = "Ladybird"
1721
18- # List of build tools that are not provided by the Flatpak SDK and therefor in the manifest
22+ # List of build tools that are not provided by the Flatpak SDK and therefore in the manifest
1923# For a vcpkg build these are installed on the host system
2024flatpak_build_tools = [
2125 "gn" ,
2226]
2327
2428# 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
29+ # These are in the manifest to fetch before building but not explicitely versioned
2630flatpak_deps_of_deps = [
27- "brotli" ,
28- "dav1d" ,
29- "highway" ,
30- "libdwarf" ,
31- "libxml2" ,
3231 "libyuv" ,
33- "vulkan-memory-allocator" ,
34- "zstd" ,
3532]
3633
37- # List of libraries that are in the Flatpak runtime and therefor not in the manifest
34+ # List of libraries that are in the Flatpak runtime and therefore not in the manifest
3835# See: https://docs.flatpak.org/en/latest/available-runtimes.html#check-software-available-in-runtimes
3936flatpak_runtime_libs = [
4037 "curl" ,
@@ -65,25 +62,69 @@ class DepMatch(Enum):
6562 Excluded = (3 ,)
6663
6764
68- def check_for_match (vcpkg : dict , name : str , identifier : str ) -> DepMatch :
65+ def get_baseline_version (baseline , name ):
66+ if not os .path .isdir (VCPKG_REPO ):
67+ cmd = f"git clone { VCPKG_URL } { VCPKG_REPO } && cd { VCPKG_REPO } && git reset --hard { baseline } "
68+ subprocess .run (cmd , stdout = subprocess .PIPE , shell = True , check = True )
69+
70+ # Query the current vcpkg baseline for its version of this package, this becomes the reference for linting
71+ cmd = f"cd { VCPKG_REPO } && git show { baseline } :versions/baseline.json | grep -E -A 3 -e '\" { name } \" '"
72+ result = subprocess .run (cmd , stdout = subprocess .PIPE , shell = True , check = True )
73+
74+ if not result .returncode :
75+ json_string = result .stdout .decode ("utf-8" ).replace ("\n " , "" ).removesuffix ("," )
76+ result = json .loads (f"{{{ json_string } }}" )
77+
78+ if "baseline" in result [name ]:
79+ return result [name ]["baseline" ]
80+
81+
82+ def check_for_match (vcpkg : dict , vcpkg_baseline , name : str , identifier : str ) -> DepMatch :
83+ if name == SELF or name in flatpak_build_tools or name in flatpak_deps_of_deps :
84+ return DepMatch .Excluded
85+
86+ if name not in vcpkg :
87+ version = get_baseline_version (vcpkg_baseline , name )
88+
89+ if version :
90+ vcpkg [name ] = version
91+
6992 if name in vcpkg :
7093 if vcpkg [name ] not in identifier :
7194 return DepMatch .VersionMismatch
7295 else :
7396 return DepMatch .Match
74- elif name == SELF or name in flatpak_build_tools or name in flatpak_deps_of_deps :
75- return DepMatch .Excluded
7697 else :
7798 return DepMatch .NoMatch
7899
79100
80101def check_vcpkg_vs_flatpak_versioning ():
102+ def match_and_update (name : str , identifier : str ) -> bool :
103+ dep_match = check_for_match (vcpkg , vcpkg_baseline , name , identifier )
104+
105+ if dep_match == DepMatch .Match or dep_match == DepMatch .Excluded :
106+ if name in vcpkg :
107+ del vcpkg [name ]
108+
109+ return False
110+ else :
111+ if dep_match == DepMatch .VersionMismatch :
112+ print (f"{ name } version mismatch. vcpkg: { vcpkg [name ]} , Flatpak: { source ['tag' ]} " )
113+ del vcpkg [name ]
114+ elif dep_match == DepMatch .NoMatch :
115+ flatpak .append (name )
116+
117+ return True
118+
81119 vcpkg = {}
82120 flatpak = []
83121 mismatch_found = False
84122
85123 with open (VCPKG ) as input :
86- for package in json .load (input )["overrides" ]:
124+ vcpkg_json = json .load (input )
125+ vcpkg_baseline = vcpkg_json ["builtin-baseline" ]
126+
127+ for package in vcpkg_json ["overrides" ]:
87128 # Add name/version pair, strip any '#' postfix from the version
88129 vcpkg [package ["name" ]] = str (package ["version" ]).split ("#" )[0 ]
89130
@@ -105,38 +146,14 @@ def check_vcpkg_vs_flatpak_versioning():
105146 # Get the tag
106147 # Replace '-' with '.': 76-1 vs 76.1
107148 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 )
149+ mismatch_found = match_and_update (name , tag )
121150
122151 break
123152 elif "branch" in source :
124153 # Get the branch
125154 # Strip '_' postfix, replace '/' with '_': chromium/7258_13 vs chromium_7258
126155 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 )
156+ mismatch_found = match_and_update (name , branch )
140157
141158 break
142159 else :
0 commit comments