|
@@ -1,6 +1,6 @@
|
|
-module(mad_deps).
|
|
-module(mad_deps).
|
|
-copyright('Sina Samavati').
|
|
-copyright('Sina Samavati').
|
|
--export([path/3,fetch/4,name_and_repo/1,checkout_to/1,get_publisher/1]).
|
|
|
|
|
|
+-export([fetch/4,name_and_repo/1,checkout_to/1,get_publisher/1]).
|
|
|
|
|
|
-type directory() :: string().
|
|
-type directory() :: string().
|
|
-type filename() :: string().
|
|
-type filename() :: string().
|
|
@@ -11,16 +11,9 @@
|
|
-type dependency() :: {name(), string(), repo()}.
|
|
-type dependency() :: {name(), string(), repo()}.
|
|
-export_type([dependency/0]).
|
|
-export_type([dependency/0]).
|
|
|
|
|
|
--spec path(string(), string(), string()) -> directory().
|
|
|
|
-path(Dir,Publisher, Repo) ->
|
|
|
|
- %% ~/.mad/repos/Publisher/Repo
|
|
|
|
- filename:join([Dir, Publisher, Repo]).
|
|
|
|
-
|
|
|
|
-spec fetch(directory(), any(), filename(), [dependency()]) -> ok.
|
|
-spec fetch(directory(), any(), filename(), [dependency()]) -> ok.
|
|
-fetch(_, _Config, _, []) ->
|
|
|
|
- ok;
|
|
|
|
-fetch(Cwd, Config, ConfigFile, [H|T]) when is_tuple(H) =:= false ->
|
|
|
|
- fetch(Cwd, Config, ConfigFile, T);
|
|
|
|
|
|
+fetch(_, _Config, _, []) -> ok;
|
|
|
|
+fetch(Cwd, Config, ConfigFile, [H|T]) when is_tuple(H) =:= false -> fetch(Cwd, Config, ConfigFile, T);
|
|
fetch(Cwd, Config, ConfigFile, [H|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
|
|
@@ -43,7 +36,7 @@ fetch_dep(Cwd, Config, ConfigFile, Name, Cmd, Uri, Co, Cache) ->
|
|
|
|
|
|
TrunkPath = case Cache of
|
|
TrunkPath = case Cache of
|
|
deps_fetch -> filename:join([mad_utils:get_value(deps_dir,Config,"deps"),Name]);
|
|
deps_fetch -> filename:join([mad_utils:get_value(deps_dir,Config,"deps"),Name]);
|
|
- Dir -> path(Dir,get_publisher(Uri),Name) end,
|
|
|
|
|
|
+ Dir -> filename:join([Dir,get_publisher(Uri),Name]) end,
|
|
|
|
|
|
Opts = ["clone", Uri, TrunkPath ],
|
|
Opts = ["clone", Uri, TrunkPath ],
|
|
io:format("dependency: ~s~n", [Name]),
|
|
io:format("dependency: ~s~n", [Name]),
|
|
@@ -57,28 +50,23 @@ fetch_dep(Cwd, Config, ConfigFile, Name, Cmd, Uri, Co, Cache) ->
|
|
Conf1 = mad_utils:script(TrunkConfigFile, Conf),
|
|
Conf1 = mad_utils:script(TrunkConfigFile, Conf),
|
|
fetch(Cwd, Config, ConfigFile, mad_utils:get_value(deps, Conf1, [])),
|
|
fetch(Cwd, Config, ConfigFile, mad_utils:get_value(deps, Conf1, [])),
|
|
case Cache of
|
|
case Cache of
|
|
- deps_dir -> skip;
|
|
|
|
|
|
+ deps_fetch -> skip;
|
|
CacheDir -> build_dep(Cwd, Config, ConfigFile, get_publisher(Uri), Name, Cmd, Co, CacheDir) end.
|
|
CacheDir -> build_dep(Cwd, Config, ConfigFile, get_publisher(Uri), Name, Cmd, Co, CacheDir) end.
|
|
|
|
|
|
%% build dependency based on branch/tag/commit
|
|
%% build dependency based on branch/tag/commit
|
|
-spec build_dep(directory(), any(), string(), string(), string(), string(), string(), string()) -> ok.
|
|
-spec build_dep(directory(), any(), string(), string(), string(), string(), string(), string()) -> ok.
|
|
build_dep(Cwd, Conf, _ConfFile, Publisher, Name, Cmd, Co, Dir) ->
|
|
build_dep(Cwd, Conf, _ConfFile, Publisher, Name, Cmd, Co, Dir) ->
|
|
- TrunkPath = path(Dir, Publisher, Name),
|
|
|
|
-% DepsDir = filename:join([Cwd, "deps", Name]),
|
|
|
|
|
|
+ TrunkPath = filename:join([Dir, Publisher, Name]),
|
|
DepsDir = mad_utils:get_value(deps_dir, Conf, ["deps"]),
|
|
DepsDir = mad_utils:get_value(deps_dir, Conf, ["deps"]),
|
|
- %% get a copy of dependency from trunk
|
|
|
|
mad_utils:exec("cp", ["-r", TrunkPath, DepsDir]),
|
|
mad_utils:exec("cp", ["-r", TrunkPath, DepsDir]),
|
|
- %% change cwd to the copy of trunk and checkout to Co
|
|
|
|
ok = file:set_cwd(DepsDir),
|
|
ok = file:set_cwd(DepsDir),
|
|
mad_utils:exec(Cmd, ["checkout", lists:concat([Co])]),
|
|
mad_utils:exec(Cmd, ["checkout", lists:concat([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}) ->
|
|
|
|
- {atom_to_list(Name), Repo};
|
|
|
|
-name_and_repo({Name, _, Repo, _}) ->
|
|
|
|
- {atom_to_list(Name), Repo}.
|
|
|
|
|
|
+name_and_repo({Name, _, Repo}) -> {atom_to_list(Name), Repo};
|
|
|
|
+name_and_repo({Name, _, Repo, _}) -> {atom_to_list(Name), Repo}.
|
|
|
|
|
|
-spec checkout_to(term() | {any(), string}) -> term().
|
|
-spec checkout_to(term() | {any(), string}) -> term().
|
|
checkout_to({_, V}) -> V;
|
|
checkout_to({_, V}) -> V;
|
|
@@ -86,7 +74,9 @@ checkout_to(Else) -> Else.
|
|
|
|
|
|
-spec get_publisher(uri()) -> string().
|
|
-spec get_publisher(uri()) -> string().
|
|
get_publisher(Uri) ->
|
|
get_publisher(Uri) ->
|
|
- S = [{git, 9418}|http_uri:scheme_defaults()],
|
|
|
|
- {ok, {_, _, _, _, Path, _}} = http_uri:parse(Uri, [{scheme_defaults, S}]),
|
|
|
|
- [Publisher|_] = string:tokens(Path, "/"),
|
|
|
|
- Publisher.
|
|
|
|
|
|
+ case http_uri:parse(Uri, [{scheme_defaults,
|
|
|
|
+ [{git, 9418}|http_uri:scheme_defaults()]}]) of
|
|
|
|
+ {ok, {_, _, _, _, Path, _}} -> hd(string:tokens(Path,"/"));
|
|
|
|
+ _ -> case string:tokens(Uri,":/") of
|
|
|
|
+ [_Server,Publisher,_Repo] -> Publisher;
|
|
|
|
+ _ -> exit(error) end end.
|