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
5050
5151 defp proceed ( args ) do
5252 Mix.Local . append_tasks
53+ Mix.Local . append_paths
5354
5455 args = load_mixfile ( args )
5556 { task , args } = get_task ( args )
Original file line number Diff line number Diff line change @@ -17,6 +17,13 @@ defmodule Mix.Local do
1717 Code . append_path tasks_path
1818 end
1919
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+
2027 @ doc """
2128 Returns all tasks modules in .mix/tasks.
2229 """
Original file line number Diff line number Diff line change @@ -22,6 +22,27 @@ defmodule Mix.Utils do
2222 System . get_env ( "MIX_HOME" ) || Path . expand ( "~/.mix" )
2323 end
2424
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+
2546 @ doc """
2647 Gets the source location of a module as a binary.
2748 """
Original file line number Diff line number Diff line change @@ -25,4 +25,17 @@ defmodule Mix.Tasks.LocalTest do
2525 Mix.Tasks.Local.Uninstall . run [ "local.sample" ]
2626 refute File . regular? tmp_path ( "userhome/.mix/tasks/Elixir-Mix-Tasks-Local-Sample.beam" )
2727 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
2841end
You can’t perform that action at this time.
0 commit comments