Skip to content

Commit 7c07476

Browse files
author
José Valim
committed
Add :archives option to Mix.Project
1 parent e3be6dd commit 7c07476

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

lib/mix/lib/mix/tasks/app.start.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ defmodule Mix.Tasks.App.Start do
2121
* `--permanent` - start the application as permanent
2222
* `--no-compile` - do not compile even if files require compilation
2323
* `--no-protocols` - do not load consolidated protocols
24+
* `--no-archives-check` - do not check archives
2425
* `--no-deps-check` - do not check dependencies
2526
* `--no-elixir-version-check` - do not check Elixir version
2627
* `--no-start` - do not start applications after compilation
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
defmodule Mix.Tasks.Archive.Check do
2+
use Mix.Task
3+
4+
@moduledoc """
5+
Checks all archives are available.
6+
7+
Mix projects can specify required archives using
8+
the `:archives` option:
9+
10+
archives: [{:foo, "~> 1.0.0"}]
11+
12+
This task guarantees this option is respected.
13+
"""
14+
def run(_) do
15+
archives = Mix.Project.config[:archives] || []
16+
17+
Enum.each archives, fn tuple ->
18+
{archive, req} = parse_archive(tuple)
19+
_ = Application.load(archive)
20+
vsn = Application.spec(archive, :vsn)
21+
cond do
22+
is_nil(vsn) ->
23+
Mix.raise "Archive \"#{archive}\" could not be found. " <>
24+
"Please make sure the archive is installed locally."
25+
not Version.match?(List.to_string(vsn), req) ->
26+
Mix.raise "Archive \"#{archive}-#{vsn}\" does not match requirement #{req}. " <>
27+
"Please update your archive version accordingly."
28+
true ->
29+
:ok
30+
end
31+
end
32+
end
33+
34+
defp parse_archive({archive, req}) when is_atom(archive) and is_binary(req) do
35+
case Version.parse_requirement(req) do
36+
{:ok, req} ->
37+
{archive, req}
38+
:error ->
39+
Mix.raise "Invalid requirement #{req} for archive \"#{archive}\""
40+
end
41+
end
42+
43+
defp parse_archive(other) do
44+
Mix.raise """
45+
Expected archive to be in the format:
46+
47+
{app :: atom, requirement :: binary}
48+
49+
got:
50+
51+
#{inspect other}
52+
53+
"""
54+
end
55+
end

lib/mix/lib/mix/tasks/clean.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ defmodule Mix.Tasks.Clean do
4747

4848
# Loadpaths without checks because compilers may be defined in deps.
4949
defp loadpaths! do
50-
Mix.Task.run "loadpaths", ["--no-elixir-version-check", "--no-deps-check"]
50+
Mix.Task.run "loadpaths", ["--no-elixir-version-check", "--no-deps-check", "--no-archives-check"]
5151
Mix.Task.reenable "loadpaths"
5252
end
5353
end

lib/mix/lib/mix/tasks/compile.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ defmodule Mix.Tasks.Compile do
4141
4242
## Command line options
4343
44-
* `--list` - list all enabled compilers
45-
* `--no-deps-check` - skip checking of dependencies
46-
* `--force` - force compilation
44+
* `--list` - list all enabled compilers
45+
* `--no-archives-check` - skip checking of archives
46+
* `--no-deps-check` - skip checking of dependencies
47+
* `--force` - force compilation
4748
4849
"""
4950
@spec run(OptionParser.argv) :: :ok | :noop
@@ -96,7 +97,7 @@ defmodule Mix.Tasks.Compile do
9697

9798
# Loadpaths without checks because compilers may be defined in deps.
9899
defp loadpaths! do
99-
Mix.Task.run "loadpaths", ["--no-elixir-version-check", "--no-deps-check"]
100+
Mix.Task.run "loadpaths", ["--no-elixir-version-check", "--no-deps-check", "--no-archives-check"]
100101
Mix.Task.reenable "loadpaths"
101102
end
102103

lib/mix/lib/mix/tasks/help.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ defmodule Mix.Tasks.Help do
109109

110110
# Loadpaths without checks because tasks may be defined in deps.
111111
defp loadpaths! do
112-
Mix.Task.run "loadpaths", ["--no-elixir-version-check", "--no-deps-check"]
112+
Mix.Task.run "loadpaths", ["--no-elixir-version-check", "--no-deps-check", "--no-archives-check"]
113113
Mix.Task.reenable "loadpaths"
114114
end
115115

lib/mix/lib/mix/tasks/loadpaths.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Mix.Tasks.Loadpaths do
66
77
## Command line options
88
9+
* `--no-archives-check` - do not check archive
910
* `--no-deps-check` - do not check dependencies
1011
* `--no-elixir-version-check` - do not check Elixir version
1112
@@ -19,6 +20,10 @@ defmodule Mix.Tasks.Loadpaths do
1920
check_elixir_version(config, args)
2021
end
2122

23+
unless "--no-archives-check" in args do
24+
Mix.Task.run "archive.check", args
25+
end
26+
2227
# --no-deps is used only internally. It has not purpose
2328
# from Mix.CLI because the CLI itself already loads deps.
2429
unless "--no-deps" in args do

0 commit comments

Comments
 (0)