11module VersionsJSONUtil
22
33using HTTP, JSON, Pkg. BinaryPlatforms, WebCacheUtilities, SHA, Lazy
4+ using Tar: Tar
45import Pkg. BinaryPlatforms: triplet, arch
6+ import Pkg. PlatformEngines: exe7z
57
68" Wrapper types to define three jlext methods for portable, tarball and installer Windows"
79struct WindowsPortable
@@ -109,6 +111,11 @@ julia_platforms = [
109111 FreeBSD (:x86_64 ),
110112]
111113
114+ const tarball_git_tree_hash_skiplist = [
115+ # Corrupt gzip stream: `7z` reports a CRC failure for the embedded tarball.
116+ " https://julialang-s3.julialang.org/bin/linux/x86/0.7/julia-0.7.0-alpha-linux-i686.tar.gz" ,
117+ ]
118+
112119function vnum_maybe (x:: AbstractString )
113120 try
114121 return VersionNumber (x)
@@ -122,6 +129,10 @@ function is_stable(v::VersionNumber)
122129 return v. prerelease == () && v. build == ()
123130end
124131
132+ function tarball_git_tree_hash (; tarball_path:: AbstractString , algorithm:: AbstractString )
133+ return open (io -> Tar. tree_hash (io; algorithm), ` $(exe7z ()) x $tarball_path -so` )
134+ end
135+
125136# Get list of tags from the Julia repo
126137function get_tags ()
127138 @info (" Probing for tag list..." )
@@ -160,6 +171,22 @@ function main(out_path)
160171 number_urls_success += 1
161172 println (stdout , " ✓" )
162173
174+ if endswith (filename, " .dmg" )
175+ kind = " archive"
176+ extension = " dmg"
177+ elseif endswith (filename, " .exe" )
178+ kind = " installer"
179+ extension = " exe"
180+ elseif endswith (filename, " .tar.gz" )
181+ kind = " archive"
182+ extension = " tar.gz"
183+ elseif endswith (filename, " .zip" )
184+ kind = " archive"
185+ extension = " zip"
186+ else
187+ error (" Unsupported file extension in filename: $(filename) " )
188+ end
189+
163190 tarball_hash_path = hit_file_cache (" $(filename) .sha256" ) do tarball_hash_path
164191 open (filepath, " r" ) do io
165192 open (tarball_hash_path, " w" ) do hash_io
@@ -169,6 +196,24 @@ function main(out_path)
169196 end
170197 tarball_hash = String (read (tarball_hash_path))
171198
199+ if extension == " tar.gz" && ! (url in tarball_git_tree_hash_skiplist)
200+ tarball_git_tree_hashes = Dict {String, String} ()
201+ tree_hash_path_sha1 = hit_file_cache (" $(filename) .git-tree-sha1" ) do tree_hash_path
202+ open (tree_hash_path, " w" ) do hash_io
203+ write (hash_io, tarball_git_tree_hash (; tarball_path= filepath, algorithm= " git-sha1" ))
204+ end
205+ end
206+ tree_hash_path_sha256 = hit_file_cache (" $(filename) .git-tree-sha256" ) do tree_hash_path
207+ open (tree_hash_path, " w" ) do hash_io
208+ write (hash_io, tarball_git_tree_hash (; tarball_path= filepath, algorithm= " git-sha256" ))
209+ end
210+ end
211+ tarball_git_tree_hashes[" git-tree-sha1" ] = String (read (tree_hash_path_sha1))
212+ tarball_git_tree_hashes[" git-tree-sha256" ] = String (read (tree_hash_path_sha256))
213+ else
214+ tarball_git_tree_hashes = nothing
215+ end
216+
172217 # Initialize overall version key, if needed
173218 if ! haskey (meta, version)
174219 meta[version] = Dict (
@@ -196,21 +241,6 @@ function main(out_path)
196241 end
197242
198243 # Build up metadata about this file
199- if endswith (filename, " .dmg" )
200- kind = " archive"
201- extension = " dmg"
202- elseif endswith (filename, " .exe" )
203- kind = " installer"
204- extension = " exe"
205- elseif endswith (filename, " .tar.gz" )
206- kind = " archive"
207- extension = " tar.gz"
208- elseif endswith (filename, " .zip" )
209- kind = " archive"
210- extension = " zip"
211- else
212- error (" Unsupported file extension in filename: $(filename) " )
213- end
214244 file_dict = Dict (
215245 " triplet" => triplet (platform),
216246 " os" => meta_os (platform),
@@ -222,6 +252,9 @@ function main(out_path)
222252 " extension" => extension,
223253 " url" => url,
224254 )
255+ if tarball_git_tree_hashes != = nothing
256+ merge! (file_dict, tarball_git_tree_hashes)
257+ end
225258 # Add in `.asc` signature content, if applicable
226259 if asc_signature != = nothing
227260 file_dict[" asc" ] = asc_signature
0 commit comments