Skip to content

Commit 6ce02e6

Browse files
author
José Valim
committed
Allow profile tasks to run without a project
1 parent 463fd60 commit 6ce02e6

File tree

5 files changed

+14
-13
lines changed

5 files changed

+14
-13
lines changed

lib/mix/lib/mix/tasks/profile.cprof.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ defmodule Mix.Tasks.Profile.Cprof do
9999
{opts, head} = OptionParser.parse_head!(args,
100100
aliases: [r: :require, p: :parallel, e: :eval, c: :config],
101101
strict: @switches)
102-
Mix.Tasks.Run.run(args, opts, head, &profile_code(&1, opts),
102+
Mix.Tasks.Run.run(["--no-mixexs" | args], opts, head,
103+
&profile_code(&1, opts),
103104
&profile_code(File.read!(&1), opts))
104105
end
105106

lib/mix/lib/mix/tasks/profile.fprof.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ defmodule Mix.Tasks.Profile.Fprof do
116116
{opts, head} = OptionParser.parse_head!(args,
117117
aliases: [r: :require, p: :parallel, e: :eval, c: :config],
118118
strict: @switches)
119-
Mix.Tasks.Run.run(args, opts, head, &profile_code(&1, opts),
119+
Mix.Tasks.Run.run(["--no-mixexs" | args], opts, head,
120+
&profile_code(&1, opts),
120121
&profile_code(File.read!(&1), opts))
121122
end
122123

lib/mix/lib/mix/tasks/run.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ defmodule Mix.Tasks.Run do
3838
* `--no-deps-check` - does not check dependencies
3939
* `--no-archives-check` - does not check archives
4040
* `--no-halt` - does not halt the system after running the command
41+
* `--no-mixexs` - allows the command to run even if there is no mix.exs
4142
* `--no-start` - does not start applications after compilation
4243
* `--no-elixir-version-check` - does not check the Elixir version from mix.exs
4344
@@ -47,7 +48,7 @@ defmodule Mix.Tasks.Run do
4748
def run(args) do
4849
{opts, head} = OptionParser.parse_head!(args,
4950
aliases: [r: :require, p: :parallel, e: :eval, c: :config],
50-
strict: [parallel: :boolean, require: :keep, eval: :keep, config: :keep,
51+
strict: [parallel: :boolean, require: :keep, eval: :keep, config: :keep, mixexs: :boolean,
5152
halt: :boolean, compile: :boolean, deps_check: :boolean, start: :boolean,
5253
archives_check: :boolean, elixir_version_check: :boolean, parallel_require: :keep])
5354

@@ -83,7 +84,14 @@ defmodule Mix.Tasks.Run do
8384

8485
# Start app after rewriting System.argv,
8586
# but before requiring and evaling.
86-
Mix.Task.run "app.start", args
87+
cond do
88+
Mix.Project.get ->
89+
Mix.Task.run "app.start", args
90+
"--no-mixexs" in args ->
91+
:ok
92+
true ->
93+
Mix.Project.get!
94+
end
8795

8896
process_load(opts, expr_evaluator)
8997

lib/mix/test/mix/tasks/profile.cprof_test.exs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ defmodule Mix.Tasks.Profile.CprofTest do
1010
@moduletag apps: [:sample]
1111
@expr "Enum.each(1..5, &String.Chars.Integer.to_string/1)"
1212

13-
setup do
14-
Mix.Project.push MixTest.Case.Sample
15-
end
16-
1713
test "profiles evaluated expression", context do
1814
in_tmp context.test, fn ->
1915
assert capture_io(fn ->

lib/mix/test/mix/tasks/profile.fprof_test.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@ defmodule Mix.Tasks.Profile.FprofTest do
66
import ExUnit.CaptureIO
77

88
alias Mix.Tasks.Profile.Fprof
9-
109
@moduletag apps: [:sample]
1110

12-
setup do
13-
Mix.Project.push MixTest.Case.Sample
14-
end
15-
1611
test "profiles evaluated expression", context do
1712
in_tmp context.test, fn ->
1813
assert capture_io(fn ->

0 commit comments

Comments
 (0)