Просмотр исходного кода

mad plan now also supports proper return codes

Namdak Tonpa 10 лет назад
Родитель
Сommit
c103751ab2
3 измененных файлов с 22 добавлено и 29 удалено
  1. BIN
      mad
  2. 6 7
      src/mad.erl
  3. 16 22
      src/mad_plan.erl

+ 6 - 7
src/mad.erl

@@ -5,19 +5,18 @@
 
 main([]) -> help();
 main(Params) ->
-%    io:format("Bundle: ~p~n\r",[escript:script_name()]),
 
     {Other,FP} = mad_utils:fold_params(Params),
-%    io:format("Params: ~p~n\r",[FP]),
+    io:format("Params: ~p~n\r",[FP]),
     case Other == [] of
          true -> skip;
          false -> io:format("Unknown Command or Parameter ~p~n\r",[Other]), help() end,
 
-    Cwd = mad_utils:cwd(),
-    ConfigFile = "rebar.config",
+    Cwd           = mad_utils:cwd(),
+    ConfigFile    = "rebar.config",
     ConfigFileAbs = filename:join(Cwd, ConfigFile),
-    Conf = mad_utils:consult(ConfigFileAbs),
-    Conf1 = mad_script:script(ConfigFileAbs, Conf, ""),
+    Conf          = mad_utils:consult(ConfigFileAbs),
+    Conf1         = mad_script:script(ConfigFileAbs, Conf, ""),
 
     return(bool(lists:foldl(fun (_,true) -> true;
           ({Name,Par},false) -> ?MODULE:Name(Cwd, ConfigFile, Conf1, Par) end, false, FP))).
@@ -52,7 +51,7 @@ compile(Cwd, ConfigFile, Conf, Params) ->
 %% reltool apps resolving
 plan(_Cwd,_ConfigFileName,_Config,Params) ->
     io:format("Plan Params: ~p~n",[Params]),
-    mad_plan:main([]), false.
+    mad_plan:main([]).
 
 repl(_Cwd,_ConfigFileName,_Config,Params) ->
 %    io:format("Repl Params: ~p~n",[Params]),

+ 16 - 22
src/mad_plan.erl

@@ -5,24 +5,17 @@
 sort(Pairs) -> iterate(Pairs, [], lhs(Pairs) ++ rhs(Pairs)).
 lhs(L) -> [X || {X, _} <- L].
 rhs(L) -> [Y || {_, Y} <- L].
-remove_pairs(L1, L2) -> [All || All={X, _Y} <- L2, not lists:member(X, L1)].
+rm_pairs(L1, L2) -> [All || All={X, _Y} <- L2, not lists:member(X, L1)].
 subtract(L1, L2) -> [X || X <- L1, not lists:member(X, L2)].
-iterate([], L, All) -> {ok,remove_duplicates(L ++ subtract(All, L))};
-iterate(Pairs, L, All) ->
-    case subtract(lhs(Pairs), rhs(Pairs)) of
-        []  -> io:format("Cycling Apps: ~p~n\r", [Pairs]);
-        Lhs -> iterate(remove_pairs(Lhs, Pairs), L ++ Lhs, All) end.
-
-remove_duplicates([]) -> [];
-remove_duplicates([H|T]) ->
-    case lists:member(H, T) of
-          true  -> remove_duplicates(T);
-          false -> [H|remove_duplicates(T)] end.
+iterate([], L, All) -> {ok,rm_dups(L ++ subtract(All, L))};
+iterate(Pairs, L, All) -> case subtract(lhs(Pairs), rhs(Pairs)) of [] -> Pairs; Lhs -> iterate(rm_pairs(Lhs, Pairs), L ++ Lhs, All) end.
+rm_dups([]) -> [];
+rm_dups([H|T]) -> case lists:member(H, T) of true -> rm_dups(T); false -> [H|rm_dups(T)] end.
 
 orderapps() ->
     Pairs = lists:flatten([ case 
        file:consult(F) of
-         {ok,[{application,Name,Opt}]} -> 
+         {ok,[{application,Name,Opt}]} ->
               Apps = proplists:get_value(applications,Opt,[]),
               [ case lists:member(A,mad_repl:system()) of
                      false -> {A,Name};
@@ -31,16 +24,17 @@ orderapps() ->
             io:format("AppName: ~p~n",[F]), skip
     end || F <- filelib:wildcard("{apps,deps}/*/ebin/*.app")  ++ 
                 filelib:wildcard("ebin/*.app"), not filelib:is_dir(F) ]),
-    {ok,Sorted} = sort(lists:flatten(Pairs)),
-    Sorted.
+    case sort(lists:flatten(Pairs)) of
+         {ok,Sorted} -> {ok,Sorted};
+         Return -> {error,{cycling_apps,Return}} end.
 
 system_deps(A) ->
-   case file:consult(code:where_is_file(lists:concat([A,".app"]))) of
-        {ok,[{application,Name,Opt}]} -> [ {A,Name} || A <- proplists:get_value(applications,Opt,[]) ];
-        {error,_} -> [] end.
+    case file:consult(code:where_is_file(lists:concat([A,".app"]))) of
+         {ok,[{application,Name,Opt}]} -> [ {A,Name} || A <- proplists:get_value(applications,Opt,[]) ];
+         {error,_} -> [] end.
 
 main(_) ->
-    Ordered = orderapps(),
-    io:format("Ordered: ~p~n\r",[Ordered]),
-    file:write_file(".applist",io_lib:format("~w",[Ordered])),
-    Ordered.
+    case orderapps() of
+         {ok,Ordered}   -> io:format("Ordered: ~p~n\r",[Ordered]),
+                           file:write_file(".applist",io_lib:format("~w",[Ordered])), false;
+         {error,Reason} -> io:format("Ordering Error: ~p~n\r",[Reason]), true end.