Skip to content

Commit 5bf3767

Browse files
committed
Download git binary on Windows or Linux if not found
TODO: test this on Windows
1 parent c187668 commit 5bf3767

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*.jl.*.cov
33
*.jl.mem
44
deps/downloads/
5+
deps/usr/
56
deps/deps.jl

deps/build.jl

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,73 @@
11
using Compat
2-
using BinDeps # just for download_cmd, unpack_cmd
32
if is_apple()
43
using Homebrew
54
end
65

76
gitcmd = `git`
8-
gitversion = "notfound"
7+
gitver = "notfound"
98
try
10-
gitversion = readchomp(`$gitcmd --version`)
9+
gitver = readchomp(`$gitcmd --version`)
1110
end
12-
if gitversion == "notfound"
13-
# TODO download it, or use homebrew's
14-
gitversion = ""
15-
downloadurl = ""
16-
info("Downloading git version $gitversion from $downloadurl")
11+
if gitver == "notfound"
12+
if is_apple()
13+
# we could allow other options, but lots of other packages already
14+
# depend on Homebrew.jl on mac and it needs a working git to function
15+
error("Working git not found on path, try running\nPkg.build(\"Homebrew\")")
16+
end
17+
import BinDeps: download_cmd, unpack_cmd, splittarpath
18+
baseurl = ""
19+
filename = ""
20+
if is_linux() && Sys.ARCH === :x86_64
21+
# use conda for a non-root option
22+
gitver = "2.8.2"
23+
baseurl = "https://anaconda.org/conda-forge/git/$gitver/download/linux-64/"
24+
filename = "git-$gitver-2.tar.bz2"
25+
elseif is_linux() && (Sys.ARCH in (:i686, :i586, :i486, :i386))
26+
# conda-forge doesn't build for 32 bit linux
27+
gitver = "2.6.4"
28+
baseurl = "https://anaconda.org/anaconda/git/$gitver/download/linux-32/"
29+
filename = "git-$gitver-0.tar.bz2"
30+
elseif is_windows()
31+
# download and extract portablegit
32+
gitver = "2.9.0"
33+
baseurl = "https://github.com/git-for-windows/git/releases/" *
34+
"download/v$gitver.windows.1/"
35+
filename = "PortableGit-$gitver-$(Sys.WORD_SIZE)-bit.7z.exe"
36+
end
37+
downloadurl = baseurl * filename
38+
if !isempty(downloadurl)
39+
info("Downloading git version $gitver from $downloadurl\nTo " *
40+
"avoid this download, install git manually and add it to your " *
41+
"path before\nrunning Pkg.add(\"Git\") or Pkg.build(\"Git\")")
42+
dest = joinpath("usr", string(Sys.MACHINE))
43+
for dir in ("downloads", "usr", dest)
44+
isdir(dir) || mkdir(dir)
45+
end
46+
filename = joinpath("downloads", filename)
47+
isfile(filename) || run(download_cmd(downloadurl, filename))
48+
# TODO: checksum validation
49+
(b, ext, sec_ext) = splittarpath(filename)
50+
run(unpack_cmd(filename, dest, ext, sec_ext))
51+
gitcmd = `$(joinpath(dirname(@__FILE__), dest, "bin", "git"))`
52+
end
53+
try
54+
gitver = readchomp(`$gitcmd --version`)
55+
info("Successfully installed $gitver to $gitcmd")
56+
# TODO: fix a warning about missing /templates here on linux
57+
# by setting an environment variable in deps.jl
58+
catch err
59+
error("Could not automatically install git, error was: $err\n" *
60+
(isempty(downloadurl) ? "Try installing git via your system " *
61+
"package manager then running\nPkg.build(\"Git\")" : ""))
62+
end
1763
else
1864
try
1965
# this is in a try because some environments like centos 7
2066
# docker containers don't have `which` installed by default
2167
gitpath = readchomp(is_windows() ? `where git` : `which git`)
2268
gitcmd = `$gitpath`
2369
end
24-
info("Using $gitversion found on path" * (gitcmd == `git` ?
70+
info("Using $gitver found on path" * (gitcmd == `git` ?
2571
"" : " at $gitcmd"))
2672
end
2773
open("deps.jl", "w") do f

0 commit comments

Comments
 (0)