|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import json |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +ICU_VERSIONS_FILE = Path(__file__).parent.parent / "icu-versions.json" |
| 8 | +PACKAGE_SCRIPT = Path(__file__).parent / "package-icudata.py" |
| 9 | +OUTPUT_BASE = Path(__file__).parent.parent / "Sources" |
| 10 | + |
| 11 | +def build_with_filter(filter_json: Path, filter_name: str, versions: dict): |
| 12 | + print(f"Building with filter {filter_json}") |
| 13 | + icu_versions = set(versions["swift-icu-versions"].values()) |
| 14 | + build_dir = Path(__file__).parent.parent / ".build" / "icu" |
| 15 | + |
| 16 | + for icu_version in icu_versions: |
| 17 | + out_dir = OUTPUT_BASE / f"icudata/{icu_version}" |
| 18 | + out_dir.mkdir(parents=True, exist_ok=True) |
| 19 | + out_c = out_dir / filter_name / "icudata.c" |
| 20 | + print(f"Building ICU data {icu_version} -> {out_c}") |
| 21 | + if out_c.exists(): |
| 22 | + print(f"Skipping {out_c} because it already exists") |
| 23 | + continue |
| 24 | + |
| 25 | + args = [ |
| 26 | + "python3", str(PACKAGE_SCRIPT), |
| 27 | + "--icu-version", icu_version, |
| 28 | + "--filter-json", str(filter_json), |
| 29 | + "--output", str(out_c), |
| 30 | + "--build-dir", str(build_dir / filter_name) |
| 31 | + ] |
| 32 | + print(f"Running {' '.join(args)}") |
| 33 | + subprocess.run(args, check=True) |
| 34 | + |
| 35 | + for swift_version in versions["swift-icu-versions"]: |
| 36 | + icu_version = versions["swift-icu-versions"][swift_version] |
| 37 | + out_dir = OUTPUT_BASE / f"ICUDataSlim_{swift_version.replace('.', '_')}" / filter_name |
| 38 | + out_dir.mkdir(parents=True, exist_ok=True) |
| 39 | + out_c = out_dir / "icudata.c" |
| 40 | + print(f"Generating C source file for Swift {swift_version} -> {out_c}") |
| 41 | + with open(out_c, "w") as f: |
| 42 | + f.write(f"// Generated by build-all.py\n") |
| 43 | + f.write(f"#include \"../../icudata/{icu_version}/{filter_name}/icudata.c\"\n") |
| 44 | + |
| 45 | + out_empty_h = out_dir / "include" / "empty.h" |
| 46 | + out_empty_h.parent.mkdir(parents=True, exist_ok=True) |
| 47 | + out_empty_h.touch() |
| 48 | + |
| 49 | + |
| 50 | +def main(): |
| 51 | + with open(ICU_VERSIONS_FILE) as f: |
| 52 | + versions = json.load(f) |
| 53 | + |
| 54 | + filters_dir = Path(__file__).parent / "filters" |
| 55 | + for filter_file in filters_dir.glob("*.json"): |
| 56 | + build_with_filter(filter_file, filter_file.stem, versions) |
| 57 | + |
| 58 | +if __name__ == "__main__": |
| 59 | + main() |
0 commit comments