File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ defmodule Mix.CLI do
50
50
51
51
defp proceed ( args ) do
52
52
Mix.Local . append_tasks
53
+ Mix.Local . append_paths
53
54
54
55
args = load_mixfile ( args )
55
56
{ task , args } = get_task ( args )
Original file line number Diff line number Diff line change @@ -17,6 +17,13 @@ defmodule Mix.Local do
17
17
Code . append_path tasks_path
18
18
end
19
19
20
+ @ doc """
21
+ Append mix paths into Erlang code path.
22
+ """
23
+ def append_paths do
24
+ Enum . each Mix.Utils . mix_path , Code . append_path ( & 1 )
25
+ end
26
+
20
27
@ doc """
21
28
Returns all tasks modules in .mix/tasks.
22
29
"""
Original file line number Diff line number Diff line change @@ -22,6 +22,27 @@ defmodule Mix.Utils do
22
22
System . get_env ( "MIX_HOME" ) || Path . expand ( "~/.mix" )
23
23
end
24
24
25
+ @ doc """
26
+ Gets all extra paths defined in the environment variable
27
+ MIX_PATH. MIX_PATH may contain multiple paths. If on windows,
28
+ those paths should be separated by `;`, if on unix systems,
29
+ use `:`.
30
+ """
31
+ def mix_path do
32
+ if path = System . get_env ( "MIX_PATH" ) do
33
+ String . split ( path , path_separator )
34
+ else
35
+ [ ]
36
+ end
37
+ end
38
+
39
+ defp path_separator do
40
+ case :os . type do
41
+ { :win32 , _ } -> ";"
42
+ { :unix , _ } -> ":"
43
+ end
44
+ end
45
+
25
46
@ doc """
26
47
Gets the source location of a module as a binary.
27
48
"""
Original file line number Diff line number Diff line change @@ -25,4 +25,17 @@ defmodule Mix.Tasks.LocalTest do
25
25
Mix.Tasks.Local.Uninstall . run [ "local.sample" ]
26
26
refute File . regular? tmp_path ( "userhome/.mix/tasks/Elixir-Mix-Tasks-Local-Sample.beam" )
27
27
end
28
+
29
+ test "manage mix paths" do
30
+ File . rm_rf! tmp_path ( "userhome" )
31
+ System . put_env "MIX_PATH" , tmp_path ( "userhome/.mix" )
32
+
33
+ # Install on MIX_PATH manually
34
+ File . cp fixture_path ( "beams/Elixir-Mix-Tasks-Local-Sample.beam" ) ,
35
+ tmp_path ( "userhome/.mix/tasks/Elixir-Mix-Tasks-Local-Sample.beam" )
36
+
37
+ # Run it
38
+ Mix.Task . run "local.sample"
39
+ assert_received { :mix_shell , :info , [ "sample" ] }
40
+ end
28
41
end
You can’t perform that action at this time.
0 commit comments