From 3d326d4e3fa6aa026f4e7568327b3fa007ab8cb6 Mon Sep 17 00:00:00 2001 From: Tom McLaughlin Date: Mon, 28 Nov 2022 22:14:21 -0700 Subject: [PATCH] Handle multiple artifacts with a given os/arch in extract_artifacts.jl --- extract_artifacts.jl | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/extract_artifacts.jl b/extract_artifacts.jl index abc23c0..ee3340d 100755 --- a/extract_artifacts.jl +++ b/extract_artifacts.jl @@ -19,22 +19,35 @@ platform = platform_key_abi() # It's possible for the artifacts to have multiple entries with the same sha1, # so group by that first sha1_to_meta = Dict{String, Vector{Tuple{String, Any}}}() -for (artifact_name, value) in artifact_dict - meta = artifact_meta(artifact_name, artifact_dict, artifacts_toml; platform=platform) - sha1 = meta["git-tree-sha1"] - - if !haskey(sha1_to_meta, sha1) - sha1_to_meta[sha1] = [] +for (artifact_name, items) in artifact_dict + if !isa(items, Vector) + items = [items]; end - push!(sha1_to_meta[sha1], (artifact_name, meta)) + # Get all possible artifacts that match our current os/arch. + # If they don't specify either key, consider it a match just to be safe. + for meta in items + if !( + !haskey(meta, "os") || meta["os"] == platform["os"] + && + !haskey(meta, "arch") || meta["arch"] == platform["arch"] + ) + continue + end + + sha1 = meta["git-tree-sha1"] + if !haskey(sha1_to_meta, sha1) + sha1_to_meta[sha1] = [] + end + push!(sha1_to_meta[sha1], (artifact_name, meta)) + end end # Print a Nix attrset where the keys are sha1 hashes and the values # are lists of "artifact infos" print("{") for (sha1, metas) in sha1_to_meta - print("""\n "$sha1" = [""") + print("""\n "$sha1" = [""") for (index, (artifact_name, meta)) in enumerate(metas) for download in meta["download"] @@ -44,13 +57,13 @@ for (sha1, metas) in sha1_to_meta print(" ") end print("{") - print("\n name = \"$artifact_name\";") - print("\n url = \"$url\";") - print("\n sha256 = \"$sha256\";") - print("\n }") + print("\n name = \"$artifact_name\";") + print("\n url = \"$url\";") + print("\n sha256 = \"$sha256\";") + print("\n }") end end print("];") end -print("\n }") +print("\n}")