Skip to content

Commit 707c443

Browse files
staticfloatKristofferC
authored andcommitted
[ext/HSG]: Enable generating historical stdlibs on macOS (#2417)
Also, update the historical stdlib list (cherry picked from commit 7b87092)
1 parent 2fa9f8f commit 707c443

File tree

3 files changed

+109
-58
lines changed

3 files changed

+109
-58
lines changed

ext/HistoricaStdlibGenerator/Manifest.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
7474
version = "1.0.15"
7575

7676
[[Pkg]]
77-
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs"]
77+
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
7878
path = "../.."
7979
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78e"
8080
version = "1.5.0"
@@ -134,3 +134,7 @@ uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
134134
[[nghttp2_jll]]
135135
deps = ["Artifacts", "Libdl"]
136136
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
137+
138+
[[p7zip_jll]]
139+
deps = ["Artifacts", "Libdl"]
140+
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"

ext/HistoricaStdlibGenerator/generate_historical_stdlibs.jl

Lines changed: 85 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function generate_nightly_url(major, minor, host = HostPlatform())
3434
# Map arch
3535
arch_str = Dict("x86_64" => "x64", "i686" => "x86", "aarch64" => "aarch64", "armv7l" => "armv7l", "ppc64le" => "ppc64le")[arch(host)]
3636
# Map OS name
37-
os_str = Dict("linux" => "linux", "windows" => "winnt", "macos" => "macos", "freebsd" => "freebsd")[os(host)]
37+
os_str = Dict("linux" => "linux", "windows" => "winnt", "macos" => "mac", "freebsd" => "freebsd")[os(host)]
3838
# Map wordsize tag
3939
wordsize_str = Dict("x86_64" => "64", "i686" => "32", "aarch64" => "aarch64", "armv7l" => "armv7l", "ppc64le" => "ppc64")[arch(host)]
4040

@@ -48,7 +48,7 @@ function generate_nightly_url(major, minor, host = HostPlatform())
4848
string(major), ".", string(minor), "/",
4949
"julia-latest-",
5050
# linux64
51-
os(host), wordsize_str,
51+
os_str, wordsize_str,
5252
".tar.gz",
5353
)
5454
end
@@ -68,20 +68,56 @@ function get_stdlibs(scratch_dir, julia_installer_name)
6868
installer_path = joinpath(scratch_dir, julia_installer_name)
6969
mktempdir() do dir
7070
@info("Extracting $(julia_installer_name)")
71-
run(`tar -C $(dir) --strip-components=1 -zxf $(installer_path)`)
72-
73-
jlexe = joinpath(dir, "bin", @static Sys.iswindows() ? "julia.exe" : "julia")
74-
jlflags = ["--startup-file=no", "-O0"]
75-
jlvers = VersionNumber(readchomp(`$(jlexe) $(jlflags) -e 'print(VERSION)'`))
76-
jlvers = VersionNumber(jlvers.major, jlvers.minor, jlvers.patch)
77-
@info("Auto-detected Julia version $(jlvers)")
78-
79-
if jlvers < v"1.1"
80-
stdlibs_str = readchomp(`$(jlexe) $(jlflags) -e 'import Pkg; println(repr(Pkg.Types.gather_stdlib_uuids()))'`)
81-
else
82-
stdlibs_str = readchomp(`$(jlexe) $(jlflags) -e 'import Pkg; println(repr(Pkg.Types.load_stdlib()))'`)
71+
mount_dir = joinpath(dir, "mount_dir")
72+
try
73+
if endswith(installer_path, ".dmg")
74+
mkdir(mount_dir)
75+
# Try to mount many times, as this seems to fail randomly
76+
mount_cmd = `hdiutil mount $(installer_path) -mountpoint $(mount_dir)`
77+
tries = 0
78+
while !success(mount_cmd)
79+
if tries > 10
80+
error("Unable to mount via hdiutil!")
81+
end
82+
sleep(0.1)
83+
tries += 1
84+
end
85+
#@show readdir(mount_dir; join=true)
86+
app_dir = first(filter(d -> startswith(basename(d), "Julia-"), readdir(mount_dir; join=true)))
87+
symlink(joinpath(app_dir, "Contents", "Resources", "julia", "bin"), joinpath(dir, "bin"))
88+
elseif endswith(installer_path, ".exe")
89+
error("This script doesn't work with `.exe` downloads")
90+
else
91+
run(`tar -C $(dir) --strip-components=1 -zxf $(installer_path)`)
92+
end
93+
94+
jlexe = joinpath(dir, "bin", @static Sys.iswindows() ? "julia.exe" : "julia")
95+
jlflags = ["--startup-file=no", "-O0"]
96+
jlvers = VersionNumber(readchomp(`$(jlexe) $(jlflags) -e 'print(VERSION)'`))
97+
jlvers = VersionNumber(jlvers.major, jlvers.minor, jlvers.patch)
98+
@info("Auto-detected Julia version $(jlvers)")
99+
100+
if jlvers < v"1.1"
101+
stdlibs_str = readchomp(`$(jlexe) $(jlflags) -e 'import Pkg; println(repr(Pkg.Types.gather_stdlib_uuids()))'`)
102+
else
103+
stdlibs_str = readchomp(`$(jlexe) $(jlflags) -e 'import Pkg; println(repr(Pkg.Types.load_stdlib()))'`)
104+
end
105+
106+
return (jlvers, stdlibs_str)
107+
finally
108+
# Clean up mounted directories
109+
if isdir(mount_dir)
110+
unmount_cmd = `hdiutil detach $(mount_dir)`
111+
tries = 0
112+
while !success(unmount_cmd)
113+
if tries > 10
114+
error("Unable to unmount $(mount_dir)")
115+
end
116+
sleep(0.1)
117+
tries += 1
118+
end
119+
end
83120
end
84-
return (jlvers, stdlibs_str)
85121
end
86122
end
87123

@@ -101,21 +137,35 @@ versions_dict = Dict()
101137
for _ in 1:num_concurrent_downloads
102138
@async begin
103139
for (url, hash) in jobs
104-
fname = joinpath(scratch_dir, basename(url))
105-
if !isfile(fname)
106-
@info("Downloading $(url)")
107-
Downloads.download(url, fname)
108-
end
140+
try
141+
fname = joinpath(scratch_dir, basename(url))
142+
if !isfile(fname)
143+
@info("Downloading $(url)")
144+
Downloads.download(url, fname)
145+
end
109146

110-
if !isempty(hash)
111-
calc_hash = bytes2hex(open(io -> sha256(io), fname, "r"))
112-
if calc_hash != hash
113-
@error("Hash mismatch on $(fname)")
147+
if !isempty(hash)
148+
calc_hash = bytes2hex(open(io -> sha256(io), fname, "r"))
149+
if calc_hash != hash
150+
@error("Hash mismatch on $(fname); deleting and re-downloading")
151+
rm(fname; force=true)
152+
Downloads.download(url, fname)
153+
calc_hash = bytes2hex(open(io -> sha256(io), fname, "r"))
154+
if calc_hash != hash
155+
@error("Hash mismatch on $(fname); re-download failed!")
156+
continue
157+
end
158+
end
114159
end
115-
end
116160

117-
version, stdlibs = get_stdlibs(scratch_dir, basename(url))
118-
versions_dict[version] = eval(Meta.parse(stdlibs))
161+
version, stdlibs = get_stdlibs(scratch_dir, basename(url))
162+
versions_dict[version] = eval(Meta.parse(stdlibs))
163+
catch e
164+
if isa(e, InterruptException)
165+
rethrow()
166+
end
167+
@error(e, exception=(e, catch_backtrace()))
168+
end
119169
end
120170
end
121171
end
@@ -145,12 +195,12 @@ unregistered_stdlibs = filter(all_stdlibs) do (uuid, name)
145195
end
146196

147197
# Helper function for getting these printed out in a nicely-sorted order
148-
function print_sorted(io::IO, d::Dict)
198+
function print_sorted(io::IO, d::Dict; indent::Int=0)
149199
println(io, "Dict(")
150200
for pair in sort(collect(d), by = kv-> kv[2])
151-
println(io, " ", pair, ",")
201+
println(io, " "^indent, pair, ",")
152202
end
153-
println(io, " ),")
203+
print(io, " "^(max(indent - 4, 0)), ")")
154204
end
155205

156206
output_fname = joinpath(dirname(dirname(@__DIR__)), "src", "HistoricalStdlibs.jl")
@@ -168,18 +218,16 @@ open(output_fname, "w") do io
168218
""")
169219
for v in sorted_versions
170220
print(io, " $(repr(v)) => ")
171-
print_sorted(io, versions_dict[v])
221+
print_sorted(io, versions_dict[v]; indent=8)
222+
println(io, ",")
172223
end
173224
println(io, "]")
174225

175226
print(io, """
176227
# Next, we also embed a list of stdlibs that must _always_ be treated as stdlibs,
177228
# because they cannot be resolved in the registry; they have only ever existed within
178229
# the Julia stdlib source tree, and because of that, trying to resolve them will fail.
179-
const UNREGISTERED_STDLIBS = Dict(
180-
""")
181-
for (uuid, name) in unregistered_stdlibs
182-
println(io, " $(repr(uuid)) => $(repr(name)),")
183-
end
184-
println(io, ")")
230+
const UNREGISTERED_STDLIBS = """)
231+
print_sorted(io, unregistered_stdlibs; indent=4)
232+
println(io)
185233
end

src/HistoricalStdlibs.jl

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,32 +100,31 @@ const STDLIBS_BY_VERSION = [
100100
# because they cannot be resolved in the registry; they have only ever existed within
101101
# the Julia stdlib source tree, and because of that, trying to resolve them will fail.
102102
const UNREGISTERED_STDLIBS = Dict(
103-
UUID("9a3f8284-a2c9-5f02-9a11-845980a1fd5c") => "Random",
104-
UUID("10745b16-79ce-11e8-11f9-7d13ad32a3b2") => "Statistics",
105-
UUID("8bb1440f-4735-579b-a4ab-409b98df4dab") => "DelimitedFiles",
106-
UUID("a63ad114-7e13-5084-954f-fe012c677804") => "Mmap",
107-
UUID("8f399da3-3557-5675-b5ff-fb832c97cbdb") => "Libdl",
103+
UUID("2a0f44e3-6c83-55bd-87e4-b1978d98bd5f") => "Base64",
108104
UUID("8bf52ea8-c179-5cab-976a-9e18b702a9bc") => "CRC32c",
105+
UUID("ade2ca70-3891-5945-98fb-dc099432e06a") => "Dates",
106+
UUID("8bb1440f-4735-579b-a4ab-409b98df4dab") => "DelimitedFiles",
107+
UUID("8ba89e20-285c-5b6f-9357-94700520ee1b") => "Distributed",
108+
UUID("7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee") => "FileWatching",
109+
UUID("9fa8497b-333b-5362-9e8d-4d0656e87820") => "Future",
109110
UUID("b77e0a4c-d291-57a0-90e8-8db25a27a240") => "InteractiveUtils",
110-
UUID("de0858da-6303-5e67-8744-51eddeeeb8d7") => "Printf",
111+
UUID("76f85450-5226-5b5a-8eaa-529ad045b433") => "LibGit2",
112+
UUID("8f399da3-3557-5675-b5ff-fb832c97cbdb") => "Libdl",
113+
UUID("37e2e46d-f89d-539d-b4ee-838fcccc9c8e") => "LinearAlgebra",
114+
UUID("56ddb016-857b-54e1-b83d-db4d58db5568") => "Logging",
111115
UUID("d6f4376e-aef5-505a-96c1-9c027394607a") => "Markdown",
112-
UUID("4af54fe1-eca0-43a8-85a7-787d91b784e3") => "LazyArtifacts",
113-
UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb") => "REPL",
114-
UUID("6462fe0b-24de-5631-8697-dd941f90decc") => "Sockets",
116+
UUID("a63ad114-7e13-5084-954f-fe012c677804") => "Mmap",
115117
UUID("44cfe95a-1eb2-52ea-b672-e2afdf69b78f") => "Pkg",
116-
UUID("37e2e46d-f89d-539d-b4ee-838fcccc9c8e") => "LinearAlgebra",
118+
UUID("de0858da-6303-5e67-8744-51eddeeeb8d7") => "Printf",
117119
UUID("9abbd945-dff8-562f-b5e8-e1ebf5ef1b79") => "Profile",
118-
UUID("2a0f44e3-6c83-55bd-87e4-b1978d98bd5f") => "Base64",
119-
UUID("7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee") => "FileWatching",
120+
UUID("3fa0cd96-eef1-5676-8a61-b3b8758bbffb") => "REPL",
121+
UUID("9a3f8284-a2c9-5f02-9a11-845980a1fd5c") => "Random",
120122
UUID("9e88b42a-f829-5b0c-bbe9-9e923198166b") => "Serialization",
121-
UUID("56ddb016-857b-54e1-b83d-db4d58db5568") => "Logging",
123+
UUID("1a1011a3-84de-559e-8e89-a11a2f7dc383") => "SharedArrays",
124+
UUID("6462fe0b-24de-5631-8697-dd941f90decc") => "Sockets",
125+
UUID("2f01184e-e22b-5df5-ae63-d93ebab69eaf") => "SparseArrays",
126+
UUID("10745b16-79ce-11e8-11f9-7d13ad32a3b2") => "Statistics",
127+
UUID("8dfed614-e22c-5e08-85e1-65c5234f0b40") => "Test",
122128
UUID("cf7118a7-6976-5b1a-9a39-7adc72f591a4") => "UUIDs",
123-
UUID("ade2ca70-3891-5945-98fb-dc099432e06a") => "Dates",
124129
UUID("4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5") => "Unicode",
125-
UUID("8dfed614-e22c-5e08-85e1-65c5234f0b40") => "Test",
126-
UUID("9fa8497b-333b-5362-9e8d-4d0656e87820") => "Future",
127-
UUID("76f85450-5226-5b5a-8eaa-529ad045b433") => "LibGit2",
128-
UUID("2f01184e-e22b-5df5-ae63-d93ebab69eaf") => "SparseArrays",
129-
UUID("1a1011a3-84de-559e-8e89-a11a2f7dc383") => "SharedArrays",
130-
UUID("8ba89e20-285c-5b6f-9357-94700520ee1b") => "Distributed",
131130
)

0 commit comments

Comments
 (0)