diff options
Diffstat (limited to 'pkgs/development/julia-modules/python/extract_artifacts.py')
-rwxr-xr-x | pkgs/development/julia-modules/python/extract_artifacts.py | 90 |
1 files changed, 63 insertions, 27 deletions
diff --git a/pkgs/development/julia-modules/python/extract_artifacts.py b/pkgs/development/julia-modules/python/extract_artifacts.py index ecbdf10ed7148..f811c6624e851 100755 --- a/pkgs/development/julia-modules/python/extract_artifacts.py +++ b/pkgs/development/julia-modules/python/extract_artifacts.py @@ -5,10 +5,33 @@ import multiprocessing import subprocess import sys import toml +from urllib.parse import urlparse import yaml import dag +# This should match the behavior of the default unpackPhase. +# See https://github.com/NixOS/nixpkgs/blob/59fa082abdbf462515facc8800d517f5728c909d/pkgs/stdenv/generic/setup.sh#L1044 +archive_extensions = [ + # xz extensions + ".tar.xz", + ".tar.lzma", + ".txz", + + # *.tar or *.tar.* + ".tar", + ".tar.Z", + ".tar.bz2", + ".tar.gz", + + # Other tar extensions + ".tgz", + ".tbz2", + ".tbz", + + ".zip" + ] + dependencies_path = Path(sys.argv[1]) closure_yaml_path = Path(sys.argv[2]) julia_path = Path(sys.argv[3]) @@ -33,33 +56,14 @@ with open(closure_yaml_path, "r") as f: if contents.get("depends_on"): closure_dependencies_dag.add_node(uuid, dependencies=contents["depends_on"].values()) -with open(out_path, "w") as f: - f.write("{ lib, fetchurl, glibc, pkgs, stdenv }:\n\n") - f.write("rec {\n") - - def process_item(item): - uuid, src = item - lines = [] - artifacts = toml.loads(subprocess.check_output([julia_path, extract_artifacts_script, uuid, src]).decode()) - if not artifacts: return f' uuid-{uuid} = {{}};\n' - - lines.append(f' uuid-{uuid} = {{') - - for artifact_name, details in artifacts.items(): - if len(details["download"]) == 0: continue - download = details["download"][0] - url = download["url"] - sha256 = download["sha256"] - - git_tree_sha1 = details["git-tree-sha1"] - - depends_on = set() - if closure_dependencies_dag.has_node(uuid): - depends_on = set(closure_dependencies_dag.get_dependencies(uuid)).intersection(dependency_uuids) +def get_archive_derivation(uuid, artifact_name, url, sha256): + depends_on = set() + if closure_dependencies_dag.has_node(uuid): + depends_on = set(closure_dependencies_dag.get_dependencies(uuid)).intersection(dependency_uuids) - other_libs = extra_libs.get(uuid, []) + other_libs = extra_libs.get(uuid, []) - fixup = f"""fixupPhase = let + fixup = f"""fixupPhase = let libs = lib.concatMap (lib.mapAttrsToList (k: v: v.path)) [{" ".join(["uuid-" + x for x in depends_on])}]; in '' @@ -69,7 +73,7 @@ with open(out_path, "w") as f: patchelf --set-interpreter ${{glibc}}/lib/ld-linux-x86-64.so.2 {{}} \; ''""" - derivation = f"""{{ + return f"""stdenv.mkDerivation {{ name = "{artifact_name}"; src = fetchurl {{ url = "{url}"; @@ -82,9 +86,41 @@ with open(out_path, "w") as f: {fixup}; }}""" +def get_plain_derivation(url, sha256): + return f"""fetchurl {{ + url = "{url}"; + sha256 = "{sha256}"; + }}""" + +with open(out_path, "w") as f: + f.write("{ lib, fetchurl, glibc, pkgs, stdenv }:\n\n") + f.write("rec {\n") + + def process_item(item): + uuid, src = item + lines = [] + artifacts = toml.loads(subprocess.check_output([julia_path, extract_artifacts_script, uuid, src]).decode()) + if not artifacts: return f' uuid-{uuid} = {{}};\n' + + lines.append(f' uuid-{uuid} = {{') + + for artifact_name, details in artifacts.items(): + if len(details["download"]) == 0: continue + download = details["download"][0] + url = download["url"] + sha256 = download["sha256"] + + git_tree_sha1 = details["git-tree-sha1"] + + parsed_url = urlparse(url) + if any(parsed_url.path.endswith(x) for x in archive_extensions): + derivation = get_archive_derivation(uuid, artifact_name, url, sha256) + else: + derivation = get_plain_derivation(url, sha256) + lines.append(f""" "{artifact_name}" = {{ sha1 = "{git_tree_sha1}"; - path = stdenv.mkDerivation {derivation}; + path = {derivation}; }};\n""") lines.append(' };\n') |