-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
loadpaths.ex
69 lines (54 loc) · 2.13 KB
/
loadpaths.ex
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
defmodule Mix.Tasks.Loadpaths do
use Mix.Task
@moduledoc """
Loads the application and its dependencies paths.
This task is never directly invoked from the command line,
but it is rather used as building block by other tasks.
Dependencies are checked, compiled, and loaded. Each step
can be explicitly disabled with flags.
## Configuration
* `:elixir` - matches the current Elixir version against the
given requirement
## Command line options
* `--no-archives-check` - does not check archives
* `--no-compile` - does not compile dependencies, only check and load them
* `--no-deps-check` - does not check dependencies, only load available ones
* `--no-deps-loading` - does not add deps loadpaths to the code path
* `--no-elixir-version-check` - does not check Elixir version
* `--no-optional-deps` - does not compile or load optional deps
"""
@impl true
def run(args) do
config = Mix.Project.config()
# --from-mix-deps-compile is used only internally to avoid
# recursively checking and loading dependencies that have
# already been loaded. It has no purpose from Mix.CLI
# because running a task may load deps.
unless "--from-mix-deps-compile" in args do
Mix.Task.run("deps.loadpaths", args)
end
if config[:app] do
load_project(config, args)
end
:ok
end
defp load_project(config, _args) do
vsn = {System.version(), :erlang.system_info(:otp_release)}
scm = config[:build_scm]
# Erase the app build if we have lock mismatch.
# We do this to force full recompilation when
# any of SCM or Elixir version changes. Applies
# to dependencies and the main project alike.
case Mix.Dep.ElixirSCM.read() do
{:ok, old_vsn, _} when old_vsn != vsn -> rm_rf_app(config)
{:ok, _, old_scm} when old_scm != scm -> rm_rf_app(config)
_ -> :ok
end
# We don't cache the current application as we may still write to it
Code.prepend_path(Mix.Project.compile_path(config))
end
defp rm_rf_app(config) do
File.rm_rf(Mix.Project.app_path(config))
File.rm_rf(Mix.Project.consolidation_path(config))
end
end