Files
RedBear-OS/local/recipes/dev/libclc/source/llvm/utils/gn/get.py
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

66 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python3
"""Downloads a prebuilt gn binary to a place where gn.py can find it."""
import io
import os
import sys
import urllib.request
import zipfile
def download_and_unpack(url, output_dir, gn):
"""Download an archive from url and extract gn from it into output_dir."""
print("downloading %s ..." % url, end="")
sys.stdout.flush()
data = urllib.request.urlopen(url).read()
print(" done")
zipfile.ZipFile(io.BytesIO(data)).extract(gn, path=output_dir)
def set_executable_bit(path):
mode = os.stat(path).st_mode
mode |= (mode & 0o444) >> 2 # Copy R bits to X.
os.chmod(path, mode) # No-op on Windows.
def get_platform():
import platform
if sys.platform == "darwin":
return "mac-amd64" if platform.machine() != "arm64" else "mac-arm64"
if platform.machine() not in ("AMD64", "x86_64"):
return None
if sys.platform.startswith("linux"):
return "linux-amd64"
if sys.platform == "win32":
return "windows-amd64"
def main():
platform = get_platform()
if not platform:
print("no prebuilt binary for", sys.platform)
print("build it yourself with:")
print(" rm -rf /tmp/gn &&")
print(" pushd /tmp && git clone https://gn.googlesource.com/gn &&")
print(" cd gn && build/gen.py && ninja -C out gn && popd &&")
print(" cp /tmp/gn/out/gn somewhere/on/PATH")
return 1
dirname = os.path.join(os.path.dirname(__file__), "bin", platform)
if not os.path.exists(dirname):
os.makedirs(dirname)
url = "https://chrome-infra-packages.appspot.com/dl/gn/gn/%s/+/latest"
gn = "gn" + (".exe" if sys.platform == "win32" else "")
if platform == "mac-arm64": # For https://openradar.appspot.com/FB8914243
try:
os.remove(os.path.join(dirname, gn))
except OSError:
pass
download_and_unpack(url % platform, dirname, gn)
set_executable_bit(os.path.join(dirname, gn))
if __name__ == "__main__":
sys.exit(main())