Skip to content

Commit 8e1c978

Browse files
Merge pull request #37340 from JuliaLang/sk/downloader
add Downloads stdlib
2 parents ebbf55c + a39c252 commit 8e1c978

File tree

110 files changed

+207
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+207
-141
lines changed

Make.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ USE_SYSTEM_LIBUV:=0
4949
USE_SYSTEM_UTF8PROC:=0
5050
USE_SYSTEM_MBEDTLS:=0
5151
USE_SYSTEM_LIBSSH2:=0
52+
USE_SYSTEM_NGHTTP2:=0
5253
USE_SYSTEM_CURL:=0
5354
USE_SYSTEM_LIBGIT2:=0
5455
USE_SYSTEM_PATCHELF:=0
@@ -1099,7 +1100,7 @@ USE_BINARYBUILDER ?= 0
10991100
endif
11001101

11011102
# This is the set of projects that BinaryBuilder dependencies are hooked up for.
1102-
BB_PROJECTS := OPENBLAS LLVM SUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP
1103+
BB_PROJECTS := OPENBLAS LLVM SUITESPARSE OPENLIBM GMP MBEDTLS LIBSSH2 NGHTTP2 MPFR CURL LIBGIT2 PCRE LIBUV LIBUNWIND DSFMT OBJCONV ZLIB P7ZIP
11031104
define SET_BB_DEFAULT
11041105
# First, check to see if BB is disabled on a global setting
11051106
ifeq ($$(USE_BINARYBUILDER),0)

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ JL_PRIVATE_LIBS-$(USE_SYSTEM_DSFMT) += libdSFMT
170170
JL_PRIVATE_LIBS-$(USE_SYSTEM_GMP) += libgmp
171171
JL_PRIVATE_LIBS-$(USE_SYSTEM_MPFR) += libmpfr
172172
JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBSSH2) += libssh2
173+
JL_PRIVATE_LIBS-$(USE_SYSTEM_NGHTTP2) += libnghttp2
173174
JL_PRIVATE_LIBS-$(USE_SYSTEM_MBEDTLS) += libmbedtls libmbedcrypto libmbedx509
174175
JL_PRIVATE_LIBS-$(USE_SYSTEM_CURL) += libcurl
175176
JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBGIT2) += libgit2

NEWS.md

Lines changed: 5 additions & 1 deletion

base/download.jl

Lines changed: 17 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,5 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
# file downloading
4-
5-
if Sys.iswindows()
6-
function download_powershell(url::AbstractString, filename::AbstractString)
7-
ps = joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "System32\\WindowsPowerShell\\v1.0\\powershell.exe")
8-
tls12 = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
9-
client = "New-Object System.Net.Webclient"
10-
# in the following we escape ' with '' (see https://ss64.com/ps/syntax-esc.html)
11-
downloadfile = "($client).DownloadFile('$(replace(url, "'" => "''"))', '$(replace(filename, "'" => "''"))')"
12-
# PowerShell v3 or later is required for Tls12
13-
proc = run(pipeline(`$ps -Version 3 -NoProfile -Command "$tls12; $downloadfile"`; stderr=stderr); wait=false)
14-
if !success(proc)
15-
if proc.exitcode % Int32 == -393216
16-
# appears to be "wrong version" exit code, based on
17-
# https://docs.microsoft.com/en-us/azure/cloud-services/cloud-services-startup-tasks-common
18-
@error "Downloading files requires Windows Management Framework 3.0 or later."
19-
end
20-
pipeline_error(proc)
21-
end
22-
return filename
23-
end
24-
end
25-
26-
function find_curl()
27-
if Sys.isapple() && Sys.isexecutable("/usr/bin/curl")
28-
"/usr/bin/curl"
29-
elseif Sys.iswindows() && Sys.isexecutable(joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "System32\\curl.exe"))
30-
joinpath(get(ENV, "SYSTEMROOT", "C:\\Windows"), "System32\\curl.exe")
31-
elseif !Sys.iswindows() && Sys.which("curl") !== nothing
32-
"curl"
33-
else
34-
nothing
35-
end
36-
end
37-
38-
function download_curl(curl_exe::AbstractString, url::AbstractString, filename::AbstractString)
39-
err = PipeBuffer()
40-
process = run(pipeline(`$curl_exe -s -S -g -L -f -o $filename $url`, stderr=err), wait=false)
41-
if !success(process)
42-
error_msg = readline(err)
43-
@error "Download failed: $error_msg"
44-
pipeline_error(process)
45-
end
46-
return filename
47-
end
48-
493
const DOWNLOAD_HOOKS = Callable[]
504

515
function download_url(url::AbstractString)
@@ -55,50 +9,25 @@ function download_url(url::AbstractString)
559
return url
5610
end
5711

58-
function download(url::AbstractString, filename::AbstractString)
59-
url = download_url(url)
60-
curl_exe = find_curl()
61-
if curl_exe !== nothing
62-
return download_curl(curl_exe, url, filename)
63-
elseif Sys.iswindows()
64-
return download_powershell(url, filename)
65-
elseif Sys.which("wget") !== nothing
66-
try
67-
run(`wget -O $filename $url`)
68-
catch
69-
rm(filename, force=true) # wget always creates a file
70-
rethrow()
71-
end
72-
elseif Sys.which("busybox") !== nothing
73-
try
74-
run(`busybox wget -O $filename $url`)
75-
catch
76-
rm(filename, force=true) # wget always creates a file
77-
rethrow()
78-
end
79-
elseif Sys.which("fetch") !== nothing
80-
run(`fetch -f $filename $url`)
81-
else
82-
error("No download agent available; install curl, wget, busybox or fetch.")
83-
end
84-
return filename
85-
end
86-
87-
function download(url::AbstractString)
88-
filename = tempname()
89-
download(url, filename)
90-
end
12+
Downloads() = require(PkgId(
13+
UUID((0xf43a241f_c20a_4ad4, 0x852c_f6b1247861c6)),
14+
"Downloads",
15+
))
9116

9217
"""
93-
download(url::AbstractString, [localfile::AbstractString])
18+
download(url::AbstractString, [path::AbstractString = tempname()]) -> path
9419
95-
Download a file from the given url, optionally renaming it to the given local file name. If
96-
no filename is given this will download into a randomly-named file in your temp directory.
97-
Note that this function relies on the availability of external tools such as `curl`, `wget`
98-
or `fetch` to download the file and is provided for convenience. For production use or
99-
situations in which more options are needed, please use a package that provides the desired
100-
functionality instead.
20+
Download a file from the given url, saving it to the location `path`, or if not
21+
specified, a temporary path. Returns the path of the downloaded file.
10122
102-
Returns the filename of the downloaded file.
23+
!!! note
24+
Since Julia 1.6, this function is deprecated and is just a thin wrapper
25+
around `Downloads.download`. In new code, you should use that function
26+
directly instead of calling this.
10327
"""
104-
download(url, filename)
28+
function download(url::AbstractString, path::AbstractString)
29+
invokelatest(Downloads().download, download_url(url), path)
30+
end
31+
function download(url::AbstractString)
32+
invokelatest(Downloads().download, download_url(url))
33+
end

base/sysimg.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ let
5252
:Test,
5353
:REPL,
5454
:Statistics,
55+
:MozillaCACerts_jll,
56+
:LibCURL_jll,
57+
:LibCURL,
58+
:Downloads,
5559
]
5660

5761
maxlen = reduce(max, textwidth.(string.(stdlibs)); init=0)

contrib/refresh_bb_tarballs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
TRIPLETS="i686-linux-gnu x86_64-linux-gnu aarch64-linux-gnu armv7l-linux-gnueabihf powerpc64le-linux-gnu i686-linux-musl x86_64-linux-musl aarch64-linux-musl armv7l-linux-musleabihf x86_64-apple-darwin14 x86_64-unknown-freebsd11.1 i686-w64-mingw32 x86_64-w64-mingw32"
1313

1414
# These are the projects currently using BinaryBuilder; both GCC-expanded and non-GCC-expanded:
15-
BB_PROJECTS="mbedtls libssh2 mpfr curl libgit2 pcre libuv unwind osxunwind dsfmt objconv p7zip zlib suitesparse openlibm"
15+
BB_PROJECTS="mbedtls libssh2 nghttp2 mpfr curl libgit2 pcre libuv unwind osxunwind dsfmt objconv p7zip zlib suitesparse openlibm"
1616
BB_GCC_EXPANDED_PROJECTS="openblas"
1717
BB_CXX_EXPANDED_PROJECTS="gmp llvm"
1818

deps/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ ifeq ($(USE_SYSTEM_LIBSSH2), 0)
111111
DEP_LIBS += libssh2
112112
endif
113113

114-
ifneq ($(OS), WINNT)
114+
ifeq ($(USE_SYSTEM_NGHTTP2), 0)
115+
DEP_LIBS += nghttp2
116+
endif
117+
115118
ifeq ($(USE_SYSTEM_CURL), 0)
116119
DEP_LIBS += curl
117120
endif
118-
endif
119121

120122
DEP_LIBS += libgit2
121123
endif # USE_SYSTEM_LIBGIT2
@@ -178,7 +180,7 @@ install: $(addprefix install-, $(DEP_LIBS))
178180
cleanall: $(addprefix clean-, $(DEP_LIBS))
179181
distcleanall: $(addprefix distclean-, $(DEP_LIBS))
180182
rm -rf $(build_prefix)
181-
getall: get-llvm get-libuv get-pcre get-openlibm get-dsfmt get-openblas get-lapack get-suitesparse get-unwind get-osxunwind get-gmp get-mpfr get-patchelf get-utf8proc get-objconv get-mbedtls get-libssh2 get-curl get-libgit2 get-libwhich
183+
getall: get-llvm get-libuv get-pcre get-openlibm get-dsfmt get-openblas get-lapack get-suitesparse get-unwind get-osxunwind get-gmp get-mpfr get-patchelf get-utf8proc get-objconv get-mbedtls get-libssh2 get-nghttp2 get-curl get-libgit2 get-libwhich
182184

183185
include $(SRCDIR)/llvm.mk
184186
include $(SRCDIR)/libuv.mk
@@ -195,6 +197,7 @@ include $(SRCDIR)/mpfr.mk
195197
include $(SRCDIR)/patchelf.mk
196198
include $(SRCDIR)/mbedtls.mk
197199
include $(SRCDIR)/libssh2.mk
200+
include $(SRCDIR)/nghttp2.mk
198201
include $(SRCDIR)/curl.mk
199202
include $(SRCDIR)/libgit2.mk
200203
include $(SRCDIR)/libwhich.mk

deps/Versions.make

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ MBEDTLS_VER = 2.16.8
2424
MBEDTLS_BB_REL = 0
2525
LIBSSH2_VER = 1.9.0
2626
LIBSSH2_BB_REL = 1
27-
CURL_VER = 7.66.0
28-
CURL_BB_REL = 1
27+
CURL_VER = 7.71.1
28+
CURL_BB_REL = 0
29+
NGHTTP2_VER = 1.40.0
30+
NGHTTP2_BB_REL = 2
2931
LIBGIT2_VER = 1.0.1
3032
LIBGIT2_BB_REL = 0
3133
LIBUV_VER = 1.29.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
24a8b8fc2398d20c24a13ce73482a3d7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4b652be535dce6a5cf36e546a31d3221f4c2534d1a3ac710f31f9ed2dfbeabd21b36c0186e4abe12cfee992ff557317aefe2bdeb9cb8b1c44da085b030719329

0 commit comments

Comments
 (0)