-
Notifications
You must be signed in to change notification settings - Fork 57
/
build.jl
110 lines (97 loc) · 3.67 KB
/
build.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const condadir = abspath(first(DEPOT_PATH), "conda")
const condadeps = joinpath(condadir, "deps.jl")
module DefaultDeps
if isfile("deps.jl")
include("deps.jl")
elseif isfile(Main.condadeps)
include(Main.condadeps)
end
if !isdefined(@__MODULE__, :MINICONDA_VERSION)
const MINICONDA_VERSION = "3"
end
if !isdefined(@__MODULE__, :ROOTENV)
const ROOTENV = joinpath(Main.condadir, MINICONDA_VERSION)
end
USE_MINIFORGE_DEFAULT = true
if Sys.ARCH in [:x86, :i686]
USE_MINIFORGE_DEFAULT = false
@warn """The free/open-source Miniforge (i.e. the conda-forge channel) does not support this platform.
Using the Anaconda/defaults channel instead, which is free for non-commercial use but otherwise may require a license.
"""
end
if !isdefined(@__MODULE__, :USE_MINIFORGE)
const USE_MINIFORGE = USE_MINIFORGE_DEFAULT
end
function default_conda_exe(ROOTENV)
@static if Sys.iswindows()
p = joinpath(ROOTENV, "Scripts")
conda_bat = joinpath(p, "conda.bat")
isfile(conda_bat) ? conda_bat : joinpath(p, "conda.exe")
else
joinpath(ROOTENV, "bin", "conda")
end
end
if !isdefined(@__MODULE__, :CONDA_EXE)
const CONDA_EXE = default_conda_exe(ROOTENV)
end
end
MINICONDA_VERSION = get(ENV, "CONDA_JL_VERSION", DefaultDeps.MINICONDA_VERSION)
ROOTENV = get(ENV, "CONDA_JL_HOME") do
root = DefaultDeps.ROOTENV
# Ensure the ROOTENV uses the current MINICONDA_VERSION when not using a custom ROOTENV
if normpath(dirname(root)) == normpath(condadir) && all(isdigit, basename(root))
joinpath(condadir, MINICONDA_VERSION)
else
root
end
end
USE_MINIFORGE = lowercase(get(ENV, "CONDA_JL_USE_MINIFORGE", DefaultDeps.USE_MINIFORGE ? "1" : "0")) in ("1","true","yes")
if isdir(ROOTENV) && MINICONDA_VERSION != DefaultDeps.MINICONDA_VERSION
error("""Miniconda version changed, since last build.
However, a root enviroment already exists at $(ROOTENV).
Setting Miniconda version is not supported for existing root enviroments.
To leave Miniconda version as, it is unset the CONDA_JL_VERSION enviroment variable and rebuild.
To change Miniconda version, you must delete the root enviroment and rebuild.
WARNING: deleting the root enviroment will delete all the packages in it.
This will break many Julia packages that have used Conda to install their dependancies.
These will require rebuilding.
""")
end
CONDA_EXE = get(ENV, "CONDA_JL_CONDA_EXE") do
if ROOTENV == DefaultDeps.ROOTENV
DefaultDeps.CONDA_EXE
else
DefaultDeps.default_conda_exe(ROOTENV)
end
end
if haskey(ENV, "CONDA_JL_CONDA_EXE")
# Check to see if CONDA_EXE is an executable file
if isfile(CONDA_EXE)
if Sys.isexecutable(CONDA_EXE)
@info "Executable conda located." CONDA_EXE
else
error("CONDA_JL_CONDA_EXE, $CONDA_EXE, cannot be executed by the current user.")
end
else
error("CONDA_JL_CONDA_EXE, $CONDA_EXE, does not exist.")
end
else
if !isfile(CONDA_EXE)
# An old CONDA_EXE has gone missing, revert to default in ROOTENV
@info "CONDA_EXE not found. Reverting to default in ROOTENV" CONDA_EXE ROOTENV
CONDA_EXE = DefaultDeps.default_conda_exe(ROOTENV)
end
end
deps = """
const ROOTENV = "$(escape_string(ROOTENV))"
const MINICONDA_VERSION = "$(escape_string(MINICONDA_VERSION))"
const USE_MINIFORGE = $USE_MINIFORGE
const CONDA_EXE = "$(escape_string(CONDA_EXE))"
"""
mkpath(condadir)
mkpath(ROOTENV)
for depsfile in ("deps.jl", condadeps)
if !isfile(depsfile) || read(depsfile, String) != deps
write(depsfile, deps)
end
end