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,18 @@ 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 = algorithm), ` $(exe7z ()) x $tarball_path -so` )
134+ end
135+
136+ function tarball_git_tree_sha1 (tarball_path:: AbstractString )
137+ return tarball_git_tree_hash (tarball_path; algorithm = " git-sha1" )
138+ end
139+
140+ function tarball_git_tree_sha256 (tarball_path:: AbstractString )
141+ return tarball_git_tree_hash (tarball_path; algorithm = " git-sha256" )
142+ end
143+
125144# Get list of tags from the Julia repo
126145function get_tags ()
127146 @info (" Probing for tag list..." )
@@ -160,6 +179,22 @@ function main(out_path)
160179 number_urls_success += 1
161180 println (stdout , " ✓" )
162181
182+ if endswith (filename, " .dmg" )
183+ kind = " archive"
184+ extension = " dmg"
185+ elseif endswith (filename, " .exe" )
186+ kind = " installer"
187+ extension = " exe"
188+ elseif endswith (filename, " .tar.gz" )
189+ kind = " archive"
190+ extension = " tar.gz"
191+ elseif endswith (filename, " .zip" )
192+ kind = " archive"
193+ extension = " zip"
194+ else
195+ error (" Unsupported file extension in filename: $(filename) " )
196+ end
197+
163198 tarball_hash_path = hit_file_cache (" $(filename) .sha256" ) do tarball_hash_path
164199 open (filepath, " r" ) do io
165200 open (tarball_hash_path, " w" ) do hash_io
@@ -169,6 +204,23 @@ function main(out_path)
169204 end
170205 tarball_hash = String (read (tarball_hash_path))
171206
207+ tarball_git_tree_hashes = if extension == " tar.gz" && ! (url in tarball_git_tree_hash_skiplist)
208+ Dict (
209+ " git-tree-sha1" => String (read (hit_file_cache (" $(filename) .git-tree-sha1" ) do tree_hash_path
210+ open (tree_hash_path, " w" ) do hash_io
211+ write (hash_io, tarball_git_tree_sha1 (filepath))
212+ end
213+ end )),
214+ " git-tree-sha256" => String (read (hit_file_cache (" $(filename) .git-tree-sha256" ) do tree_hash_path
215+ open (tree_hash_path, " w" ) do hash_io
216+ write (hash_io, tarball_git_tree_sha256 (filepath))
217+ end
218+ end )),
219+ )
220+ else
221+ nothing
222+ end
223+
172224 # Initialize overall version key, if needed
173225 if ! haskey (meta, version)
174226 meta[version] = Dict (
@@ -196,21 +248,6 @@ function main(out_path)
196248 end
197249
198250 # 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
214251 file_dict = Dict (
215252 " triplet" => triplet (platform),
216253 " os" => meta_os (platform),
@@ -222,6 +259,9 @@ function main(out_path)
222259 " extension" => extension,
223260 " url" => url,
224261 )
262+ if tarball_git_tree_hashes != = nothing
263+ merge! (file_dict, tarball_git_tree_hashes)
264+ end
225265 # Add in `.asc` signature content, if applicable
226266 if asc_signature != = nothing
227267 file_dict[" asc" ] = asc_signature
0 commit comments