at 24.11-pre 3.2 kB view raw
1 2from collections import defaultdict 3import copy 4import json 5import os 6from pathlib import Path 7import shutil 8import subprocess 9import sys 10import tempfile 11import toml 12import util 13import yaml 14 15 16registry_path = Path(sys.argv[1]) 17desired_packages_path = Path(sys.argv[2]) 18package_overrides = json.loads(sys.argv[3]) 19dependencies_path = Path(sys.argv[4]) 20out_path = Path(sys.argv[5]) 21 22with open(desired_packages_path, "r") as f: 23 desired_packages = yaml.safe_load(f) or [] 24 25uuid_to_versions = defaultdict(list) 26for pkg in desired_packages: 27 uuid_to_versions[pkg["uuid"]].append(pkg["version"]) 28 29with open(dependencies_path, "r") as f: 30 uuid_to_store_path = yaml.safe_load(f) 31 32os.makedirs(out_path) 33 34registry = toml.load(registry_path / "Registry.toml") 35registry["packages"] = {k: v for k, v in registry["packages"].items() if k in uuid_to_versions} 36 37for (uuid, versions) in uuid_to_versions.items(): 38 if uuid in package_overrides: 39 info = package_overrides[uuid] 40 41 # Make a registry entry based on the info from the package override 42 path = Path(info["name"][0].upper()) / Path(info["name"]) 43 registry["packages"][uuid] = { 44 "name": info["name"], 45 "path": str(path), 46 } 47 48 os.makedirs(out_path / path) 49 50 # Read the Project.yaml from the src 51 project = toml.load(Path(info["src"]) / "Project.toml") 52 53 # Generate all the registry files 54 with open(out_path / path / Path("Compat.toml"), "w") as f: 55 f.write('["%s"]\n' % info["version"]) 56 # Write nothing in Compat.toml, because we've already resolved everything 57 with open(out_path / path / Path("Deps.toml"), "w") as f: 58 f.write('["%s"]\n' % info["version"]) 59 toml.dump(project["deps"], f) 60 with open(out_path / path / Path("Versions.toml"), "w") as f: 61 f.write('["%s"]\n' % info["version"]) 62 f.write('git-tree-sha1 = "%s"\n' % info["treehash"]) 63 with open(out_path / path / Path("Package.toml"), "w") as f: 64 toml.dump({ 65 "name": info["name"], 66 "uuid": uuid, 67 "repo": "file://" + info["src"], 68 }, f) 69 70 elif uuid in registry["packages"]: 71 registry_info = registry["packages"][uuid] 72 name = registry_info["name"] 73 path = registry_info["path"] 74 75 os.makedirs(out_path / path) 76 77 # Copy some files to the minimal repo unchanged 78 for f in ["Compat.toml", "Deps.toml"]: 79 if (registry_path / path / f).exists(): 80 shutil.copy2(registry_path / path / f, out_path / path) 81 82 # Copy the Versions.toml file, trimming down to the versions we care about 83 all_versions = toml.load(registry_path / path / "Versions.toml") 84 versions_to_keep = {k: v for k, v in all_versions.items() if k in versions} 85 for k, v in versions_to_keep.items(): 86 del v["nix-sha256"] 87 with open(out_path / path / "Versions.toml", "w") as f: 88 toml.dump(versions_to_keep, f) 89 90 # Fill in the local store path for the repo 91 if not uuid in uuid_to_store_path: continue 92 package_toml = toml.load(registry_path / path / "Package.toml") 93 package_toml["repo"] = "file://" + uuid_to_store_path[uuid] 94 with open(out_path / path / "Package.toml", "w") as f: 95 toml.dump(package_toml, f) 96 97with open(out_path / "Registry.toml", "w") as f: 98 toml.dump(registry, f)