Skip to content

Commit 1e90076

Browse files
author
José Valim
committed
Make it explicit that some tasks require a project to be defined
1 parent 456b846 commit 1e90076

24 files changed

+66
-28
lines changed

lib/mix/lib/mix/deps/retriever.ex

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ defmodule Mix.Deps.Retriever do
99
as a `Mix.Dep` record.
1010
"""
1111
def children() do
12-
# Don't run recursively for the top-level project
1312
scms = Mix.SCM.available
1413
from = current_source(:mix)
15-
(Mix.project[:deps] || []) |> Enum.map(update(&1, scms, from))
14+
Enum.map(Mix.project[:deps], update(&1, scms, from))
1615
end
1716

1817
@doc """
@@ -157,7 +156,7 @@ defmodule Mix.Deps.Retriever do
157156
]
158157
else
159158
supported = Enum.join scms, ", "
160-
raise Mix.Error, message: "did not specify a supported scm, expected one of: " <> supported
159+
raise Mix.Error, message: "#{inspect Mix.Project.get} did not specify a supported scm, expected one of: " <> supported
161160
end
162161
end
163162

@@ -231,7 +230,7 @@ defmodule Mix.Deps.Retriever do
231230
end
232231

233232
defp invalid_dep_format(dep) do
234-
raise Mix.Error, message: %b(dependency specified in the wrong format: #{inspect dep}, ) <>
233+
raise Mix.Error, message: %b(Dependency specified in the wrong format: #{inspect dep}, ) <>
235234
%b(expected { app :: atom, opts :: Keyword.t } | { app :: atom, requirement :: String.t, opts :: Keyword.t })
236235
end
237236
end

lib/mix/lib/mix/exceptions.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defexception Mix.InvalidTaskError, task: nil, mix_error: true do
1111
end
1212

1313
defexception Mix.NoProjectError, mix_error: true,
14-
message: "Could not find a Mix.Project"
14+
message: "Could not find a Mix.Project, please ensure a mix.exs file is available"
1515

1616
defexception Mix.Error, mix_error: true, message: nil
1717

lib/mix/lib/mix/project.ex

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,16 +271,17 @@ defmodule Mix.Project do
271271
defp default_config do
272272
[ compile_path: "ebin",
273273
default_task: "run",
274+
deps: [],
274275
deps_path: "deps",
275276
elixirc_exts: [:ex],
276277
elixirc_paths: ["lib"],
277278
elixirc_watch_exts: [:ex, :eex, :exs],
278-
load_paths: [],
279-
lockfile: "mix.lock",
280-
preferred_cli_env: [{ "test", :test }],
281279
erlc_paths: ["src"],
282280
erlc_include_path: "include",
283-
erlc_options: [:debug_info] ]
281+
erlc_options: [:debug_info],
282+
load_paths: [],
283+
lockfile: "mix.lock",
284+
preferred_cli_env: [{ "test", :test }] ]
284285
end
285286

286287
defp get_project_config(nil), do: []

lib/mix/lib/mix/scm/git.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ defmodule Mix.SCM.Git do
132132

133133
defp run_cmd_or_raise(command) do
134134
if Mix.shell.cmd(command) != 0 do
135-
raise Mix.Error, message: "command `#{command}` failed"
135+
raise Mix.Error, message: "Command `#{command}` failed"
136136
end
137137
true
138138
end

lib/mix/lib/mix/scm/path.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule Mix.SCM.Path do
4040

4141
def checkout(opts) do
4242
path = Mix.Utils.relative_to_cwd opts[:dest]
43-
raise Mix.Error, message: "cannot checkout path dependency, expected a dependency at #{path}"
43+
raise Mix.Error, message: "Cannot checkout path dependency, expected a dependency at #{path}"
4444
end
4545

4646
def update(opts) do

lib/mix/lib/mix/tasks/archive.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ defmodule Mix.Tasks.Archive do
3434
app = Mix.project[:app] ->
3535
Mix.Archive.name(app, Mix.project[:version])
3636
true ->
37-
raise Mix.Error, message: "Could not create archive without a name. " <>
38-
"Please pass -o as an option"
37+
raise Mix.Error, message: "Could not create archive without a name, " <>
38+
"please pass -o as an option"
3939
end
4040

4141
Mix.Archive.create(archive_file)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ defmodule Mix.Tasks.Deps.Clean do
1616
import Mix.Deps, only: [all: 0, by_name: 1, format_dep: 1]
1717

1818
def run(args) do
19+
Mix.Project.get! # Require the project to be available
20+
1921
{ opts, args } = OptionParser.parse(args, switches: [unlock: :boolean, all: :boolean])
2022

2123
cond do

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ defmodule Mix.Tasks.Deps.Compile do
2828
depending: 2, format_dep: 1, make?: 1, mix?: 1, rebar?: 1 ]
2929

3030
def run(args) do
31+
Mix.Project.get! # Require the project to be available
32+
3133
case OptionParser.parse(args) do
3234
{ _, [] } ->
3335
do_compile Enum.filter(all, available?(&1))
@@ -117,7 +119,7 @@ defmodule Mix.Tasks.Deps.Compile do
117119
shell.info "I can install a local copy which is just used by mix"
118120

119121
unless shell.yes?("Shall I install this local copy?") do
120-
raise Mix.Error, message: "could not find rebar to compile " <>
122+
raise Mix.Error, message: "Could not find rebar to compile " <>
121123
"dependency #{app}, please ensure rebar is available"
122124
end
123125

@@ -127,7 +129,7 @@ defmodule Mix.Tasks.Deps.Compile do
127129

128130
defp do_command(app, command, extra // "") do
129131
if Mix.shell.cmd("#{command} #{extra}") != 0 do
130-
raise Mix.Error, message: "could not compile dependency #{app}, #{command} command failed. " <>
132+
raise Mix.Error, message: "Could not compile dependency #{app}, #{command} command failed. " <>
131133
"If you want to recompile this dependency, please run: mix deps.compile #{app}"
132134
end
133135
end
@@ -139,7 +141,7 @@ defmodule Mix.Tasks.Deps.Compile do
139141
defp do_compile(app, command) when is_binary(command) do
140142
Mix.shell.info("#{app}: #{command}")
141143
if Mix.shell.cmd(command) != 0 do
142-
raise Mix.Error, message: "could not compile dependency #{app}, custom #{command} command failed. " <>
144+
raise Mix.Error, message: "Could not compile dependency #{app}, custom #{command} command failed. " <>
143145
"If you want to recompile this dependency, please run: mix deps.compile #{app}"
144146
end
145147
end

lib/mix/lib/mix/tasks/deps.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ defmodule Mix.Tasks.Deps do
1616
1717
"""
1818
def run(_) do
19+
Mix.Project.get! # Require the project to be available
20+
1921
shell = Mix.shell
2022
lock = Mix.Deps.Lock.read
2123

lib/mix/lib/mix/tasks/deps.get.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ defmodule Mix.Tasks.Deps.Get do
1919
import Mix.Deps, only: [all: 2, by_name: 1, format_dep: 1, check_lock: 2, out_of_date?: 1]
2020

2121
def run(args) do
22+
Mix.Project.get! # Require the project to be available
23+
2224
{ opts, rest } = OptionParser.parse(args, switches: [no_compile: :boolean, quiet: :boolean])
2325

2426
if rest != [] do

0 commit comments

Comments
 (0)