moaaar ci changes
This commit is contained in:
7 files changed
+555
-227
No files matched your search
@@ -9,6 +9,7 @@ Usage:
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import concurrent.futures
|
||||
import glob
|
||||
import io
|
||||
import os
|
||||
@@ -17,6 +18,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
@@ -176,40 +178,77 @@ def resolve_dependencies(packages, provides_map, pkg_prefix):
|
||||
return sorted(resolved)
|
||||
|
||||
|
||||
def _download_single_package(pkg_info, repo, download_dir):
|
||||
idx, total, filename = pkg_info
|
||||
last_err = None
|
||||
dest_file = os.path.join(download_dir, os.path.basename(filename))
|
||||
|
||||
for base in MIRROR_BASES:
|
||||
pkg_url = f"{base}/{repo}/{filename}"
|
||||
try:
|
||||
data = fetch_url(pkg_url, timeout=60)
|
||||
with open(dest_file, "wb") as f:
|
||||
f.write(data)
|
||||
print(f"[{idx}/{total}] Downloaded {filename}")
|
||||
return filename, dest_file
|
||||
except Exception as e:
|
||||
last_err = e
|
||||
print(f" Failed {filename} from {base}/{repo} ({e}), trying next mirror...", file=sys.stderr)
|
||||
|
||||
raise RuntimeError(f"Failed to download {filename}: {last_err}")
|
||||
|
||||
|
||||
def download_and_extract_packages(resolved, repo, dest_dir):
|
||||
os.makedirs(dest_dir, exist_ok=True)
|
||||
temp_pkg = f"/tmp/msys2_{repo}_pkg.tar.zst"
|
||||
total = len(resolved)
|
||||
|
||||
for i, (pkg_name, filename) in enumerate(resolved, 1):
|
||||
print(f"[{i}/{len(resolved)}] Downloading {filename}...")
|
||||
downloaded = False
|
||||
last_err = None
|
||||
with tempfile.TemporaryDirectory(prefix=f"msys2_{repo}_") as download_dir:
|
||||
tasks = [(i, total, filename) for i, (_, filename) in enumerate(resolved, 1)]
|
||||
downloaded_files = []
|
||||
|
||||
for base in MIRROR_BASES:
|
||||
pkg_url = f"{base}/{repo}/{filename}"
|
||||
try:
|
||||
data = fetch_url(pkg_url, timeout=60)
|
||||
with open(temp_pkg, "wb") as f:
|
||||
f.write(data)
|
||||
downloaded = True
|
||||
break
|
||||
except Exception as e:
|
||||
last_err = e
|
||||
print(f" Failed from {base}/{repo} ({e}), trying next mirror...", file=sys.stderr)
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||
futures = [executor.submit(_download_single_package, task, repo, download_dir) for task in tasks]
|
||||
for future in concurrent.futures.as_completed(futures):
|
||||
downloaded_files.append(future.result())
|
||||
|
||||
if not downloaded:
|
||||
raise RuntimeError(f"Failed to download {filename}: {last_err}")
|
||||
# Extract sequentially in deterministic filename order
|
||||
for filename, pkg_path in sorted(downloaded_files):
|
||||
tar_res = subprocess.run(
|
||||
["tar", "-I", "zstd", "-xf", pkg_path, "--strip-components=1", "-C", dest_dir],
|
||||
capture_output=True,
|
||||
)
|
||||
os.remove(pkg_path)
|
||||
if tar_res.returncode != 0:
|
||||
err = tar_res.stderr.decode("utf-8", errors="replace")
|
||||
raise RuntimeError(f"Failed to extract {filename}: {err}")
|
||||
|
||||
tar_res = subprocess.run(
|
||||
["tar", "-I", "zstd", "-xf", temp_pkg, "--strip-components=1", "-C", dest_dir],
|
||||
capture_output=True,
|
||||
)
|
||||
if os.path.exists(temp_pkg):
|
||||
os.remove(temp_pkg)
|
||||
|
||||
if tar_res.returncode != 0:
|
||||
err = tar_res.stderr.decode("utf-8", errors="replace")
|
||||
raise RuntimeError(f"Failed to extract {filename}: {err}")
|
||||
def prune_sysroot(abs_dest):
|
||||
# Remove docs, manuals, locales, translations, and examples
|
||||
prune_dirs = [
|
||||
os.path.join(abs_dest, "share", "doc"),
|
||||
os.path.join(abs_dest, "share", "man"),
|
||||
os.path.join(abs_dest, "share", "info"),
|
||||
os.path.join(abs_dest, "share", "locale"),
|
||||
os.path.join(abs_dest, "share", "qt6", "doc"),
|
||||
os.path.join(abs_dest, "share", "qt6", "examples"),
|
||||
os.path.join(abs_dest, "share", "qt6", "translations"),
|
||||
os.path.join(abs_dest, "share", "qt6", "phrasebooks"),
|
||||
]
|
||||
for unused_qml in ("LocalStorage", "Particles", "Pdf", "Scene2D", "Scene3D", "Timeline", "VirtualKeyboard", "tooling"):
|
||||
prune_dirs.append(os.path.join(abs_dest, "share", "qt6", "qml", "QtQuick", unused_qml))
|
||||
|
||||
for d in prune_dirs:
|
||||
if os.path.isdir(d):
|
||||
shutil.rmtree(d)
|
||||
|
||||
# Remove static .a archives when a corresponding .dll.a import library exists
|
||||
lib_dir = os.path.join(abs_dest, "lib")
|
||||
if os.path.isdir(lib_dir):
|
||||
for dll_a in glob.glob(os.path.join(lib_dir, "*.dll.a")):
|
||||
static_a = dll_a[: -len(".dll.a")] + ".a"
|
||||
if os.path.isfile(static_a):
|
||||
os.remove(static_a)
|
||||
|
||||
|
||||
def configure_sysroot(dest_dir, repo):
|
||||
@@ -241,6 +280,8 @@ def configure_sysroot(dest_dir, repo):
|
||||
if os.path.isdir(tools_dir):
|
||||
shutil.rmtree(tools_dir)
|
||||
|
||||
prune_sysroot(abs_dest)
|
||||
|
||||
|
||||
def verify_installation(dest_dir):
|
||||
bin_dir = os.path.join(dest_dir, "bin")
|
||||
|
||||
Reference in new issue
Block a user