Skip to content

Commit 54a40ef

Browse files
author
José Valim
committed
Push the given app name as default on Mix.Project
1 parent f781795 commit 54a40ef

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

lib/mix/lib/mix/project.ex

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ defmodule Mix.Project do
4444
# Push a project onto the project stack.
4545
# Only the top of the stack can be accessed.
4646
@doc false
47-
def push(atom, file \\ nil) when is_atom(atom) do
47+
def push(atom, file \\ nil, app \\ nil) when is_atom(atom) do
4848
file = file ||
4949
(atom && List.to_string(atom.__info__(:compile)[:source]))
5050

51-
config = default_config
51+
config = ([app: app] ++ default_config)
5252
|> Keyword.merge(get_project_config(atom))
5353
|> Keyword.drop(@private_config)
5454

@@ -335,23 +335,24 @@ defmodule Mix.Project do
335335

336336
if cached = Mix.ProjectStack.read_cache(app) do
337337
{project, file} = cached
338-
push(project, file)
338+
push(project, file, app)
339339
project
340340
else
341341
file = Path.expand("mix.exs")
342-
old_proj = get
343-
344-
_ = if File.regular?(file) do
345-
Code.load_file(file)
346-
end
347-
348-
new_proj = get
349-
350-
if old_proj == new_proj do
351-
file = "nofile"
352-
new_proj = nil
353-
push new_proj, file
354-
end
342+
old_proj = get()
343+
344+
new_proj =
345+
if File.regular?(file) do
346+
_ = Code.load_file(file)
347+
case get() do
348+
^old_proj -> Mix.raise "Could not find a Mix project at #{file}"
349+
new_proj -> new_proj
350+
end
351+
else
352+
file = "nofile"
353+
push(nil, file, app)
354+
nil
355+
end
355356

356357
Mix.ProjectStack.write_cache(app, {new_proj, file})
357358
new_proj

lib/mix/test/mix/project_test.exs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ defmodule Mix.ProjectTest do
7979
end
8080
end
8181

82+
test "in_project pushes given configuration" do
83+
in_fixture "no_mixfile", fn ->
84+
Mix.Project.in_project :foo, ".", [hello: :world], fn _ ->
85+
assert Mix.Project.config[:app] == :foo
86+
assert Mix.Project.config[:hello] == :world
87+
end
88+
end
89+
end
90+
8291
test "config_files" do
8392
Mix.Project.push(SampleProject)
8493

0 commit comments

Comments
 (0)