@@ -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 )
5454end
@@ -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
86122end
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)
145195end
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 )), " ) " )
154204end
155205
156206output_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)
185233end
0 commit comments