forked from codedownio/julia2nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_artifacts.jl
executable file
·58 lines (46 loc) · 1.6 KB
/
extract_artifacts.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#! /usr/bin/env nix-shell
#! nix-shell -i julia -p julia_16-bin
using Pkg, Pkg.Artifacts, Pkg.BinaryPlatforms, Pkg.PlatformEngines
derivation = ARGS[1]
full = string("with import <nixpkgs> { }; ", derivation)
built = String(rstrip(read(`nix-build -E $full --no-out-link`, String)))
artifacts_toml = find_artifacts_toml(built)
if artifacts_toml == nothing
print("{}")
exit()
end
artifact_dict = Pkg.Artifacts.load_artifacts_toml(artifacts_toml)
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] = []
end
push!(sha1_to_meta[sha1], (artifact_name, meta))
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" = [""")
for (index, (artifact_name, meta)) in enumerate(metas)
for download in meta["download"]
url = download["url"]
sha256 = download["sha256"]
if index > 1
print(" ")
end
print("{")
print("\n name = \"$artifact_name\";")
print("\n url = \"$url\";")
print("\n sha256 = \"$sha256\";")
print("\n }")
end
end
print("];")
end
print("\n }")