Browse Source

recpect to deps_dir, also added Config to context

Maxim Sokhatsky 11 years ago
parent
commit
fdf67a8a56
3 changed files with 25 additions and 24 deletions
  1. BIN
      mad
  2. 6 6
      src/mad.erl
  3. 19 18
      src/mad_deps.erl

BIN
mad


+ 6 - 6
src/mad.erl

@@ -25,9 +25,8 @@ main(Args) ->
     Conf = mad_utils:consult(ConfigFileAbs),
     Conf = mad_utils:consult(ConfigFileAbs),
     Conf1 = mad_utils:script(ConfigFileAbs, Conf),
     Conf1 = mad_utils:script(ConfigFileAbs, Conf),
 
 
-    %% TODO: deps_dir might be a list of directories, add them all to code path
-    DepsDir = filename:join([hd(mad_utils:get_value(deps_dir, Conf1, ["deps"])),
-                             "*", "ebin"]),
+    %% rebar should create deps dir in deps_dir only, this is not a list
+    DepsDir = filename:join([mad_utils:get_value(deps_dir, Conf1, ["deps"]),"*","ebin"]),
     Paths = ["ebin"|filelib:wildcard(DepsDir)],
     Paths = ["ebin"|filelib:wildcard(DepsDir)],
     code:add_paths(Paths),
     code:add_paths(Paths),
 
 
@@ -45,8 +44,9 @@ main(Args) ->
             ok;
             ok;
         Deps ->
         Deps ->
             file:make_dir(mad_deps:repos_path()),
             file:make_dir(mad_deps:repos_path()),
-            file:make_dir("deps"),
-            mad_deps:fetch(Cwd, ConfigFile, Deps)
+            FetchDir = mad_utils:get_value(deps_dir, Conf, ["deps"]),
+            file:make_dir(FetchDir),
+            mad_deps:fetch(Cwd, Conf, ConfigFile, Deps)
     end.
     end.
 
 
 %% compile dependencies and the app
 %% compile dependencies and the app
@@ -64,7 +64,7 @@ compile(Cwd, ConfigFile, Conf) ->
     mad_compile:foreach(fun mad_compile:app/2, Dirs, ConfigFile).
     mad_compile:foreach(fun mad_compile:app/2, Dirs, ConfigFile).
 
 
 'compile-deps'(Cwd, ConfigFile, Conf) ->
 'compile-deps'(Cwd, ConfigFile, Conf) ->
-    mad_compile:deps(Cwd, ConfigFile, get_value(deps, Conf, [])).
+    mad_compile:deps(Cwd, Conf, ConfigFile, get_value(deps, Conf, [])).
 
 
 get_value(Key, Opts, Default) ->
 get_value(Key, Opts, Default) ->
     case lists:keyfind(Key, 1, Opts) of
     case lists:keyfind(Key, 1, Opts) of

+ 19 - 18
src/mad_deps.erl

@@ -2,7 +2,7 @@
 
 
 -export([repos_path/0]).
 -export([repos_path/0]).
 -export([path/2]).
 -export([path/2]).
--export([fetch/3]).
+-export([fetch/4]).
 -export([name_and_repo/1]).
 -export([name_and_repo/1]).
 -export([checkout_to/1]).
 -export([checkout_to/1]).
 -export([get_publisher/1]).
 -export([get_publisher/1]).
@@ -29,12 +29,12 @@ path(Publisher, Repo) ->
     %% ~/.mad/repos/Publisher/Repo
     %% ~/.mad/repos/Publisher/Repo
     filename:join([?REPOS_PATH, Publisher, Repo]).
     filename:join([?REPOS_PATH, Publisher, Repo]).
 
 
--spec fetch(directory(), filename(), [dependency()]) -> ok.
-fetch(_, _, []) ->
+-spec fetch(directory(), any(), filename(), [dependency()]) -> ok.
+fetch(_, _Config, _, []) ->
     ok;
     ok;
-fetch(Cwd, ConfigFile, [H|T]) when is_tuple(H) =:= false ->
-    fetch(Cwd, ConfigFile, T);
-fetch(Cwd, ConfigFile, [H|T]) ->
+fetch(Cwd, Config, ConfigFile, [H|T]) when is_tuple(H) =:= false ->
+    fetch(Cwd, Config, ConfigFile, T);
+fetch(Cwd, Config, ConfigFile, [H|T]) ->
     {Name, Repo} = name_and_repo(H),
     {Name, Repo} = name_and_repo(H),
     {Cmd, Uri, Co} = case Repo of
     {Cmd, Uri, Co} = case Repo of
                          V={_, _, _} ->
                          V={_, _, _} ->
@@ -49,14 +49,14 @@ fetch(Cwd, ConfigFile, [H|T]) ->
         fetched ->
         fetched ->
             ok;
             ok;
         _ ->
         _ ->
-            fetch_dep(Cwd, ConfigFile, Publisher, Name, Cmd1, Uri),
-            build_dep(Cwd, Publisher, Name, Cmd1, Co1)
+            fetch_dep(Cwd, Config, ConfigFile, Publisher, Name, Cmd1, Uri),
+            build_dep(Cwd, Config, ConfigFile, Publisher, Name, Cmd1, Co1)
     end,
     end,
-    fetch(Cwd, ConfigFile, T).
+    fetch(Cwd, Config, ConfigFile, T).
 
 
--spec fetch_dep(directory(), filename(), string(), string(), string(), uri())
+-spec fetch_dep(directory(), any(), filename(), string(), string(), string(), uri())
                -> ok.
                -> ok.
-fetch_dep(Cwd, ConfigFile, Publisher, Name, Cmd, Uri) ->
+fetch_dep(Cwd, Config, ConfigFile, Publisher, Name, Cmd, Uri) ->
     TrunkPath = path(Publisher, Name),
     TrunkPath = path(Publisher, Name),
     Opts = ["clone", Uri, TrunkPath],
     Opts = ["clone", Uri, TrunkPath],
     io:format("dependency: ~s~n", [Name]),
     io:format("dependency: ~s~n", [Name]),
@@ -68,21 +68,22 @@ fetch_dep(Cwd, ConfigFile, Publisher, Name, Cmd, Uri) ->
     TrunkConfigFile = filename:join(TrunkPath, ConfigFile),
     TrunkConfigFile = filename:join(TrunkPath, ConfigFile),
     Conf = mad_utils:consult(TrunkConfigFile),
     Conf = mad_utils:consult(TrunkConfigFile),
     Conf1 = mad_utils:script(TrunkConfigFile, Conf),
     Conf1 = mad_utils:script(TrunkConfigFile, Conf),
-    fetch(Cwd, ConfigFile, mad_utils:get_value(deps, Conf1, [])).
+    fetch(Cwd, Config, ConfigFile, mad_utils:get_value(deps, Conf1, [])).
 
 
 %% build dependency based on branch/tag/commit
 %% build dependency based on branch/tag/commit
--spec build_dep(directory(), string(), string(), string(), string()) -> ok.
-build_dep(Cwd, Publisher, Name, Cmd, Co) ->
+-spec build_dep(directory(), any(), string(), string(), string(), string(), string()) -> ok.
+build_dep(Cwd, Conf, _ConfFile, Publisher, Name, Cmd, Co) ->
     TrunkPath = path(Publisher, Name),
     TrunkPath = path(Publisher, Name),
-    DepPath = filename:join([Cwd, "deps", Name]),
+%    DepsDir = filename:join([Cwd, "deps", Name]),
+    DepsDir = mad_utils:get_value(deps_dir, Conf, ["deps"]),
+    io:format("Build Dep: ~p",[Conf]),
     %% get a copy of dependency from trunk
     %% get a copy of dependency from trunk
-    mad_utils:exec("cp", ["-r", TrunkPath, DepPath]),
+    mad_utils:exec("cp", ["-r", TrunkPath, DepsDir]),
     %% change cwd to the copy of trunk and checkout to Co
     %% change cwd to the copy of trunk and checkout to Co
-    ok = file:set_cwd(DepPath),
+    ok = file:set_cwd(DepsDir),
     mad_utils:exec(Cmd, ["checkout", Co]),
     mad_utils:exec(Cmd, ["checkout", Co]),
     ok = file:set_cwd(Cwd).
     ok = file:set_cwd(Cwd).
 
 
-
 %% internal
 %% internal
 -spec name_and_repo(dependency()) -> {string(), repo()}.
 -spec name_and_repo(dependency()) -> {string(), repo()}.
 name_and_repo({Name, _, Repo}) ->
 name_and_repo({Name, _, Repo}) ->