|
1 | 1 | using Compat
|
2 |
| -using BinDeps # just for download_cmd, unpack_cmd |
3 | 2 | if is_apple()
|
4 | 3 | using Homebrew
|
5 | 4 | end
|
6 | 5 |
|
7 | 6 | gitcmd = `git`
|
8 |
| -gitversion = "notfound" |
| 7 | +gitver = "notfound" |
9 | 8 | try
|
10 |
| - gitversion = readchomp(`$gitcmd --version`) |
| 9 | + gitver = readchomp(`$gitcmd --version`) |
11 | 10 | 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 |
17 | 63 | else
|
18 | 64 | try
|
19 | 65 | # this is in a try because some environments like centos 7
|
20 | 66 | # docker containers don't have `which` installed by default
|
21 | 67 | gitpath = readchomp(is_windows() ? `where git` : `which git`)
|
22 | 68 | gitcmd = `$gitpath`
|
23 | 69 | end
|
24 |
| - info("Using $gitversion found on path" * (gitcmd == `git` ? |
| 70 | + info("Using $gitver found on path" * (gitcmd == `git` ? |
25 | 71 | "" : " at $gitcmd"))
|
26 | 72 | end
|
27 | 73 | open("deps.jl", "w") do f
|
|
0 commit comments