Skip to content

Commit

Permalink
Runs deps on prod by default (since we don't want to carry dev deps o…
Browse files Browse the repository at this point in the history
…ver)
  • Loading branch information
José Valim committed Sep 14, 2012
1 parent e86a650 commit be96754
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/mix/lib/mix/project.ex
Expand Up @@ -69,10 +69,12 @@ defmodule Mix.Project do
# tasks stack are properly manipulated, no side-effects
# should remain.
@doc false
def in_subproject(config, function) do
def in_subproject(env, config, function) do
old_env = Mix.env
current = Mix.Project.current
tasks = Mix.Task.clear

Mix.env(env)
Mix.Server.cast({ :post_config, config })

if File.regular?("mix.exs") do
Expand All @@ -86,6 +88,7 @@ defmodule Mix.Project do
try do
function.()
after
Mix.env(old_env)
Mix.Project.pop
Mix.Task.set_tasks(tasks)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/mix/lib/mix/tasks/deps.compile.ex
Expand Up @@ -63,10 +63,12 @@ defmodule Mix.Tasks.Deps.Compile do
lockfile: File.expand_path(Mix.project[:lockfile])
]

child_env = opts[:env] || :prod

File.cd! compile_path, fn ->
cond do
opts[:compile] -> do_command(opts[:compile], app)
mix? -> Mix.Project.in_subproject child_config, fn -> Mix.Task.run "compile" end
mix? -> Mix.Project.in_subproject child_env, child_config, fn -> Mix.Task.run "compile" end
rebar? -> shell.info System.cmd("rebar compile deps_dir=#{inspect root_path}")
make? -> shell.info System.cmd("make")
true -> shell.error "Could not compile #{app}, no mix.exs, rebar.config or Makefile " <>
Expand Down
1 change: 1 addition & 0 deletions lib/mix/test/fixtures/deps_status/custom/raw_repo/mix.exs
Expand Up @@ -2,6 +2,7 @@ defmodule RawRepo.Mix do
use Mix.Project

def project do
Process.put(:raw_repo_env, Mix.env)
[app: :raw_repo, version: "0.1.0"]
end
end
50 changes: 50 additions & 0 deletions lib/mix/test/mix/tasks/deps_test.exs
Expand Up @@ -153,6 +153,56 @@ defmodule Mix.Tasks.DepsTest do
end
end

## Deps environment

defmodule DepsEnvApp do
def project do
[
app: :raw_sample,
version: "0.1.0",
deps: [
{ :raw_repo, "0.1.0", raw: "custom/raw_repo" }
]
]
end
end

defmodule CustomDepsEnvApp do
def project do
[
app: :raw_sample,
version: "0.1.0",
deps: [
{ :raw_repo, "0.1.0", raw: "custom/raw_repo", env: :dev }
]
]
end
end

test "by default sets deps env to prod" do
Mix.Project.push DepsEnvApp

in_fixture "deps_status", fn ->
Mix.Tasks.Deps.Update.run []
assert Process.get(:raw_repo_env) == :prod
end
after
purge [RawRepo, RawRepo.Mix]
Mix.Project.pop
end

test "can customize environment" do
Mix.Project.push CustomDepsEnvApp

in_fixture "deps_status", fn ->
Mix.Tasks.Deps.Update.run []
assert Process.get(:raw_repo_env) == :dev
end
after
purge [RawRepo, RawRepo.Mix]
Mix.Project.pop
end

## Nested dependencies

defmodule UnmetNestedDepsApp do
Expand Down

0 comments on commit be96754

Please sign in to comment.