Browse Source

v2.3 by @5HT

221V 1 year ago
parent
commit
0a300039b4

+ 2 - 1
.travis.yml

@@ -1,8 +1,9 @@
 language: erlang
 language: erlang
 otp_release:
 otp_release:
+  - 18.0
   - R16B02
   - R16B02
   - R16B01
   - R16B01
 notifications:
 notifications:
   email: false
   email: false
   irc: "chat.freenode.net#n2o"
   irc: "chat.freenode.net#n2o"
-script: "./mad get-deps compile"
+script: "make"

+ 1 - 1
Makefile

@@ -1,4 +1,4 @@
 default:
 default:
 	echo "-define(VERSION,\"`git rev-parse HEAD | head -c 6`\")." > include/mad.hrl
 	echo "-define(VERSION,\"`git rev-parse HEAD | head -c 6`\")." > include/mad.hrl
 	erlc -o ebin deps/ling/bc/*.erl || true
 	erlc -o ebin deps/ling/bc/*.erl || true
-	./mad cle dep com rel script mad
+	./mad cle dep com bun mad

+ 1 - 1
include/mad.hrl

@@ -1 +1 @@
--define(VERSION,"aa2dac").
+-define(VERSION,"2f5d1f").

BIN
mad


+ 1 - 1
mix.exs

@@ -3,7 +3,7 @@ defmodule MAD.Mixfile do
 
 
   def project do
   def project do
     [app: :mad,
     [app: :mad,
-     version: "0.9.0",
+     version: "2.3.0",
      description: "Small and fast rebar replacement",
      description: "Small and fast rebar replacement",
      package: package]
      package: package]
   end
   end

+ 3 - 3
src/compile/mad_compile.erl

@@ -1,12 +1,12 @@
 -module(mad_compile).
 -module(mad_compile).
--copyright('Sina Samavati').
+%%-author('Sina Samavati').
 -compile([export_all, nowarn_export_all]).
 -compile([export_all, nowarn_export_all]).
 
 
 compile(Params) ->
 compile(Params) ->
     { Cwd, ConfigFile, Conf } = mad_utils:configs(),
     { Cwd, ConfigFile, Conf } = mad_utils:configs(),
     Res = case Params of
     Res = case Params of
          [] -> mad_compile:'compile-deps'(Cwd, ConfigFile, Conf);
          [] -> mad_compile:'compile-deps'(Cwd, ConfigFile, Conf);
-         __ -> mad_compile:deps(Cwd, Conf, ConfigFile, [Params])
+         _ -> mad_compile:deps(Cwd, Conf, ConfigFile, [Params])
     end,
     end,
     case bool(Res) of
     case bool(Res) of
          true -> {error,Params};
          true -> {error,Params};
@@ -104,4 +104,4 @@ is_compiled(BeamFile, File) -> mad_utils:last_modified(BeamFile) >= mad_utils:la
     mad_compile:deps(Cwd, Conf, ConfigFile, mad_utils:get_value(deps, Conf, [])).
     mad_compile:deps(Cwd, Conf, ConfigFile, mad_utils:get_value(deps, Conf, [])).
 
 
 list(X) when is_atom(X) -> atom_to_list(X);
 list(X) when is_atom(X) -> atom_to_list(X);
-list(X) -> X.
+list(X) -> X.

+ 38 - 18
src/compile/mad_erl.erl

@@ -1,23 +1,43 @@
 -module(mad_erl).
 -module(mad_erl).
--copyright('Sina Samavati').
--compile([export_all, nowarn_export_all]).
--define(COMPILE_OPTS(Inc, Ebin, Opts, Deps), [return_errors, {i, [Inc]}, {outdir, Ebin}] ++ Opts++Deps).
+%%-author('Sina Samavati').
 
 
-erl_to_beam(Bin, F) -> filename:join(Bin, filename:basename(F, ".erl") ++ ".beam").
+-export([
+  compile/5
+]).
+
+
+-define(COMPILE_OPTS(Inc, Ebin, Opts, Deps), [return_errors, return_warnings, warnings_as_errors, {i, [Inc]}, {outdir, Ebin}] ++ Opts ++ Deps).
+
+
+erl_to_beam(Bin, F) ->
+  filename:join(Bin, filename:basename(F, ".erl") ++ ".beam").
+
+
+compile(File, Inc, Bin, Opt, Deps) ->
+  BeamFile = erl_to_beam(Bin, File),
+  Compiled = mad_compile:is_compiled(BeamFile, File),
+  case Compiled of
+    false ->
+      Opts1 = ?COMPILE_OPTS(Inc, Bin, Opt, Deps),
+      mad:info("Compiling ~s~n", [File -- mad_utils:cwd()]),
+      ret(compile:file(File, Opts1));
+    _ -> false
+  end.
 
 
-compile(File,Inc,Bin,Opt,Deps) ->
-    BeamFile = erl_to_beam(Bin, File),
-    Compiled = mad_compile:is_compiled(BeamFile, File),
-    if  Compiled =:= false ->
-        Opts1 = ?COMPILE_OPTS(Inc, Bin, Opt, Deps),
-        mad:info("Compiling ~s~n", [File -- mad_utils:cwd()]),
-        ret(compile:file(File, Opts1));
-    true -> false end.
 
 
 ret(error) -> true;
 ret(error) -> true;
-ret({error,Errors,_}) ->
-    S=case file:get_cwd() of {ok,Cwd} -> length(Cwd); _ -> 0 end,
-    [[ mad:info("Line ~p: ~p in ~p~n",[ L,R,lists:nthtail(S,F) ]) || {L,_,R} <- E ] || {F,E} <- Errors ], true;
-ret({ok,_}) -> false;
-ret({ok,_,_}) -> false;
-ret({ok,_,_,_}) -> false.
+ret({error, X}) -> lines(error, X);
+ret({error, X, _}) -> lines(error, X);
+ret({ok, _}) -> false;
+ret({ok, _, []}) -> false;
+ret({ok, _, X}) -> lines(warning, X), false;
+ret({ok, _, X, _}) -> lines(warning, X), false.
+
+lines(Tag,X) ->
+  S = case file:get_cwd() of
+    {ok, Cwd} -> erlang:length(Cwd);
+    _ -> 0
+  end,
+  [[ mad:info("Line ~p: ~p ~p in ~p~n", [ L, Tag, R, lists:nthtail(S, F) ]) || {L, _, R} <- E ] || {F, E} <- X ],
+  true.
+

+ 2 - 2
src/mad.app.src

@@ -1,6 +1,6 @@
 {application, mad,
 {application, mad,
- [{description, "MAD VXZ Build Tool"},
-  {vsn, "1.9"},
+ [{description, "MAD VXZ Build Tool - Erlang/OTP Containers"},
+  {vsn, "2.3"},
   {registered, []},
   {registered, []},
   {applications, [kernel,stdlib,inets]},
   {applications, [kernel,stdlib,inets]},
   {env, []}]}.
   {env, []}]}.

+ 39 - 19
src/mad.erl

@@ -1,25 +1,35 @@
 -module(mad).
 -module(mad).
--copyright('Maxim Sokhatsky').
+%%-author('Maxim Sokhatsky').
+
 -include("mad.hrl").
 -include("mad.hrl").
+
 -compile([export_all, nowarn_export_all]).
 -compile([export_all, nowarn_export_all]).
 -export([main/1]).
 -export([main/1]).
 
 
-main([])          -> help();
-main(Params)      ->
 
 
-    { Invalid, Valid } = lists:foldr(
-                               fun (X,{C,R}) when is_atom(X) -> {[],[{X,C}|R]};
-                                   (X,{C,R}) -> {[X|C],R} end,
-                               {[],[]}, lists:map(fun atomize/1, Params)),
+main([])     -> help();
+main(Params) ->
+  {Invalid, Valid} = lists:foldr(
+    fun(X, {C, R}) when erlang:is_atom(X) ->
+         {[], [{X, C}|R]};
+       (X, {C, R}) ->
+         {[X|C], R}
+    end, {[], []}, lists:map(fun atomize/1, Params) ),
+  
+  return(lists:any(
+    fun({error, _}) -> true;
+       (_) -> false
+    end,
+    lists:flatten(
+      lists:foldl(
+        fun({Fun, Arg}, []) ->
+             errors((profile()):Fun(Arg));
+           ({_, _}, Err) ->
+             errors(Invalid),
+             {return, Err}
+        end, [], Valid)
+      ))).
 
 
-    return(lists:any(fun({error,_}) -> true;
-                                (_) -> false end,
-           lists:flatten(
-           lists:foldl(
-                 fun ({Fun,Arg},[])  -> errors((profile()):Fun(Arg));
-                     ({_Fun,_Arg},Err) -> errors(Invalid),
-                                        { return, Err } end,
-                 [], Valid)))).
 
 
 atomize("static") -> 'static';
 atomize("static") -> 'static';
 atomize("deploy") -> 'deploy';
 atomize("deploy") -> 'deploy';
@@ -36,7 +46,7 @@ atomize("sto"++_) -> 'stop';
 atomize("att"++_) -> 'attach';
 atomize("att"++_) -> 'attach';
 atomize("sh")     -> 'sh';
 atomize("sh")     -> 'sh';
 atomize("rep"++_) -> 'sh';
 atomize("rep"++_) -> 'sh';
-atomize("pla"++_) -> 'release';
+atomize("pla"++_) -> 'resolve';
 atomize(Else)     -> Else.
 atomize(Else)     -> Else.
 
 
 profile()         -> application:get_env(mad,profile,mad_local).
 profile()         -> application:get_env(mad,profile,mad_local).
@@ -44,19 +54,29 @@ profile()         -> application:get_env(mad,profile,mad_local).
 errors([])        -> [];
 errors([])        -> [];
 errors(false)     -> [];
 errors(false)     -> [];
 errors(true)      -> {error,unknown};
 errors(true)      -> {error,unknown};
-errors({error,L}) -> info("ERROR: ~tp~n",[L]), {error,L};
+errors({error,L}) -> info("ERROR: ~tp~n",[L]), [{error,L}];
 errors({ok,_})    -> info("OK~n",[]), [];
 errors({ok,_})    -> info("OK~n",[]), [];
-errors(X)         -> info("RETURN: ~tp~n",[X]), {error,X}.
+errors(X)         -> info("RETURN: ~tp~n",[X]), [{error,X}].
 
 
 return(true)      -> 1;
 return(true)      -> 1;
 return(false)     -> 0;
 return(false)     -> 0;
 return(X)         -> X.
 return(X)         -> X.
 
 
+
+host() ->
+  try
+    {ok,H} = inet:gethostname(),
+    H
+  catch _:_ ->
+    <<>>
+  end.
+
+
 info(Format)      -> io:format(lists:concat([Format,"\r"])).
 info(Format)      -> io:format(lists:concat([Format,"\r"])).
 info(Format,Args) -> io:format(lists:concat([Format,"\r"]),Args).
 info(Format,Args) -> io:format(lists:concat([Format,"\r"]),Args).
 
 
 help(Reason,D)    -> help(io_lib:format("~s ~p", [Reason, D])).
 help(Reason,D)    -> help(io_lib:format("~s ~p", [Reason, D])).
-help(_Msg)         -> help().
+help(_Msg)        -> help().
 help()            -> info("MAD Container Tool version ~s~n",[?VERSION]),
 help()            -> info("MAD Container Tool version ~s~n",[?VERSION]),
                      info("~n"),
                      info("~n"),
                      info("    invoke = mad params~n"),
                      info("    invoke = mad params~n"),

+ 7 - 3
src/mad_resolve.erl

@@ -1,8 +1,10 @@
 -module(mad_resolve).
 -module(mad_resolve).
--author('Maxim Sokhatsky').
+%%-author('Maxim Sokhatsky').
+
 -compile([export_all, nowarn_export_all]).
 -compile([export_all, nowarn_export_all]).
 
 
-% dependency graph solver
+
+%% dependency graph solver
 
 
 sort(Pairs) -> iterate(Pairs, [], lhs(Pairs) ++ rhs(Pairs)).
 sort(Pairs) -> iterate(Pairs, [], lhs(Pairs) ++ rhs(Pairs)).
 lhs(L) -> [X || {X, _, _} <- L].
 lhs(L) -> [X || {X, _, _} <- L].
@@ -20,7 +22,9 @@ triples() ->
     lists:flatten([ case
     lists:flatten([ case
        file:consult(F) of
        file:consult(F) of
          {ok,[{application,Name,Opt}]} ->
          {ok,[{application,Name,Opt}]} ->
-              Apps = proplists:get_value(applications,Opt,[]),
+              Apps1 = proplists:get_value(included_applications,Opt,[]),
+              Apps2 = proplists:get_value(applications,Opt,[]),
+              Apps = lists:usort(Apps1++Apps2),
               Vsn  = proplists:get_value(vsn,Opt,[]),
               Vsn  = proplists:get_value(vsn,Opt,[]),
               [ case lists:member(A,mad_repl:system()) of
               [ case lists:member(A,mad_repl:system()) of
                      false -> {A,Name,{Vsn,appdir(filename:absname(F))}};
                      false -> {A,Name,{Vsn,appdir(filename:absname(F))}};

+ 2 - 2
src/package/mad_escript.erl

@@ -5,9 +5,9 @@
 main(N) ->
 main(N) ->
     App = filename:basename(case N of [] -> mad_utils:cwd(); E -> E end),
     App = filename:basename(case N of [] -> mad_utils:cwd(); E -> E end),
     mad_resolve:main([]),
     mad_resolve:main([]),
-    EmuArgs = "-noshell -noinput +pc unicode",
+    EmuArgs = "+pc unicode",
     Files = static() ++ beams(fun filename:basename/1, fun read_file/1) ++ overlay(),
     Files = static() ++ beams(fun filename:basename/1, fun read_file/1) ++ overlay(),
-%   [ io:format("Escript: ~ts~n",[File]) || { File, _ } <- Files ],
+    %[ io:format("Escript: ~ts~n", [File]) || { File, _ } <- Files ],
     escript:create(App,[shebang,{comment,""},{emu_args,EmuArgs},{archive,Files,[memory]}]),
     escript:create(App,[shebang,{comment,""},{emu_args,EmuArgs},{archive,Files,[memory]}]),
     file:change_mode(App, 8#764),
     file:change_mode(App, 8#764),
     {ok,App}.
     {ok,App}.

+ 2 - 2
src/package/mad_systools.erl

@@ -22,14 +22,14 @@ apps(List) ->
 
 
 release(Name) ->
 release(Name) ->
     Triples = mad_resolve:triples(),
     Triples = mad_resolve:triples(),
-    Apps = lists:usort(fun({Name,_},{Name2,_})-> Name =< Name2 end,
+    Apps = lists:usort(fun({Name1,_},{Name2,_})-> Name1 =< Name2 end,
                 [{A,{B,F}}||{_,A,{B,F}}<-Triples]) ++
                 [{A,{B,F}}||{_,A,{B,F}}<-Triples]) ++
       [{kernel,{proplists:get_value(vsn,element(2,
       [{kernel,{proplists:get_value(vsn,element(2,
                 application:get_all_key(kernel)),[]),
                 application:get_all_key(kernel)),[]),
                 filename:absname(code:lib_dir(kernel))}}],
                 filename:absname(code:lib_dir(kernel))}}],
     Sorted = [ lists:keyfind(A,1,Apps) || A <- element(2,mad_resolve:orderapps())],
     Sorted = [ lists:keyfind(A,1,Apps) || A <- element(2,mad_resolve:orderapps())],
     {L,R}     = lists:unzip(Sorted),
     {L,R}     = lists:unzip(Sorted),
-    {Ver,Dir} = lists:unzip(R),
+    {Ver,_Dir} = lists:unzip(R),
     NameVer   = [ X || X <- lists:zip(L,Ver), element(1,X) /= active,
     NameVer   = [ X || X <- lists:zip(L,Ver), element(1,X) /= active,
                                               element(1,X) /= fs ],
                                               element(1,X) /= fs ],
     Version = case lists:keyfind(list_to_atom(Name),2,Triples) of
     Version = case lists:keyfind(list_to_atom(Name),2,Triples) of

+ 1 - 0
src/profile/mad_local.erl

@@ -4,6 +4,7 @@
 compile(Params)   -> mad_compile:compile(Params).
 compile(Params)   -> mad_compile:compile(Params).
 app(Params)       -> mad_static:app(Params).
 app(Params)       -> mad_static:app(Params).
 release(Params)   -> mad_release:release(Params).
 release(Params)   -> mad_release:release(Params).
+resolve(Params)   -> mad_resolve:main(Params).
 clean(Params)     -> mad_run:clean(Params).
 clean(Params)     -> mad_run:clean(Params).
 start(Params)     -> mad_run:start(Params).
 start(Params)     -> mad_run:start(Params).
 attach(Params)    -> mad_run:attach(Params).
 attach(Params)    -> mad_run:attach(Params).

+ 1 - 0
src/profile/mad_vz.erl

@@ -8,6 +8,7 @@ start(Params)     -> mad_vz:start(Params).
 attach(Params)    -> mad_vz:attach(Params).
 attach(Params)    -> mad_vz:attach(Params).
 stop(Params)      -> mad_vz:stop(Params).
 stop(Params)      -> mad_vz:stop(Params).
 release(Params)   -> mad_release:release(Params).
 release(Params)   -> mad_release:release(Params).
+resolve(Params)   -> mad_resolve:main(Params).
 sh(_Params)        -> {error,'N/A'}.
 sh(_Params)        -> {error,'N/A'}.
 deps(Params)      -> mad_synrc:deps(Params).
 deps(Params)      -> mad_synrc:deps(Params).
 up(Params)        -> mad_synrc:up(Params).
 up(Params)        -> mad_synrc:up(Params).

+ 35 - 24
src/provision/mad_repl.erl

@@ -1,7 +1,9 @@
 -module(mad_repl).
 -module(mad_repl).
--copyright('Maxim Sokhatsky').
+%%-copyright('Maxim Sokhatsky').
+
 -compile([export_all, nowarn_export_all]).
 -compile([export_all, nowarn_export_all]).
 
 
+
 disabled() -> [].
 disabled() -> [].
 system() -> [compiler,syntax_tools,sasl,tools,mnesia,reltool,xmerl,crypto,kernel,stdlib,ssh,eldap,
 system() -> [compiler,syntax_tools,sasl,tools,mnesia,reltool,xmerl,crypto,kernel,stdlib,ssh,eldap,
              wx,webtool,ssl,runtime_tools,public_key,observer,inets,asn1,et,eunit,hipe,os_mon].
              wx,webtool,ssl,runtime_tools,public_key,observer,inets,asn1,et,eunit,hipe,os_mon].
@@ -27,15 +29,31 @@ parse_applist(AppList) ->
    [ list_to_atom(R) || R <-Res ]  -- disabled().
    [ list_to_atom(R) || R <-Res ]  -- disabled().
 
 
 load_config() ->
 load_config() ->
-   Config = wildcards(["sys.config"]),
+   Config = wildcards(["sys.config", lists:concat( ["etc/", mad:host(), "/sys.config"] )]),
    Apps = case Config of
    Apps = case Config of
         [] -> case mad_repl:load_file("sys.config") of
         [] -> case mad_repl:load_file("sys.config") of
               {error,_} -> [];
               {error,_} -> [];
-              {ok,Bin} -> parse(binary_to_list(Bin)) end;
-      File -> case file:consult(File) of
+              {ok,Bin} -> parse(unicode:characters_to_list(Bin)) end;
+      File -> case file:consult(hd(File)) of
               {error,_} -> [];
               {error,_} -> [];
               {ok,[A]} -> A end end,
               {ok,[A]} -> A end end,
- [ begin [ application:set_env(App,K,V) || {K,V} <- Cfg ], {App,Cfg} end || {App,Cfg} <- Apps ].
+  load_config(Apps, []).
+
+
+load_config([H|T], Apps2) ->
+    App2 = case H of
+        {App,Cfg} -> [application:set_env(App,K,V) || {K,V} <- Cfg], [H];
+        File when erlang:is_list(File) ->
+            Apps = case file:consult(File) of
+                {error,_} -> [];
+                {ok,[A]} -> A end,
+            load_config(Apps, []);
+        _ -> []
+    end,
+    load_config(T, Apps2 ++ App2);
+load_config([], Apps2) ->
+    Apps2.
+
 
 
 acc_start(A,Acc) ->
 acc_start(A,Acc) ->
    case application:start(A) of
    case application:start(A) of
@@ -69,11 +87,14 @@ sh(Params) ->
     load(),
     load(),
     Config = load_config(),
     Config = load_config(),
     Driver = mad_utils:get_value(shell_driver,_Config,user_drv),
     Driver = mad_utils:get_value(shell_driver,_Config,user_drv),
-    pre(Driver),
+    repl_intro(),
     case os:type() of
     case os:type() of
-         {win32,nt} -> shell:start();
-                  _ -> Driver:start() end,
-    post(Driver),
+      {win32,nt} ->
+        os:cmd("chcp 65001"),
+        shell:start();
+      _ ->
+        Driver:start()
+    end,
     load_apps(Params,Config,[]),
     load_apps(Params,Config,[]),
     case Params of
     case Params of
         ["applist"] -> skip;
         ["applist"] -> skip;
@@ -121,18 +142,8 @@ parse(String) ->
     {value,Value,_Bs} = erl_eval:exprs(AbsForm, erl_eval:new_bindings()),
     {value,Value,_Bs} = erl_eval:exprs(AbsForm, erl_eval:new_bindings()),
     Value.
     Value.
 
 
-% we need to call printing before starting driver for user_drv
-% but for start_kjell we should call after, that's why we have pre and post here.
-
-pre(start_kjell) -> [];
-pre(user_drv) -> unregister(user), appconfig(user_drv);
-pre(Driver) -> appconfig(Driver).
-post(start_kjell) -> appconfig(start_kjell);
-post(_) -> [].
-print(Label,Value,start_kjell) -> io:requests([{put_chars,Label ++ normalize(length(Label)+1,Value) ++ "\n\r"}]);
-print(Label,Value,_) -> mad:info("~s~p~n",[Label,Value]).
-normalize(Padding,V) -> [ case X of 10 -> [13,10]; E -> E end || X <- lists:flatten(pp(Padding,V) )].
-pp(Padding,V) -> k_io_lib_pretty:print(V, Padding, 80, 30, 60, fun(_,_)-> no end).
-appconfig(Driver) ->
-    print("Configuration: ", load_config(), Driver),
-    print("Applications: ",  applist(),     Driver).
+
+repl_intro() ->
+  io:format("Configuration: ~p~n", [load_config()]),
+  io:format("Applications:  ~p~n", [applist()]).
+

+ 1 - 1
src/provision/mad_vz.erl

@@ -19,7 +19,7 @@ start(App) ->
     mad:info("Oneliner: ~p~n",[Concat]),
     mad:info("Oneliner: ~p~n",[Concat]),
     {ret(R),S}.
     {ret(R),S}.
 
 
-stop(App) -> ok.
+stop(_App) -> ok.
 
 
 ret(0) -> ok;
 ret(0) -> ok;
 ret(_) -> error.
 ret(_) -> error.

+ 1 - 1
src/sources/mad_git.erl

@@ -1,7 +1,7 @@
 -module(mad_git).
 -module(mad_git).
 -compile([export_all, nowarn_export_all]).
 -compile([export_all, nowarn_export_all]).
 
 
-deps(Params) ->
+deps(_Params) ->
     { Cwd, ConfigFile, Conf } = mad_utils:configs(),
     { Cwd, ConfigFile, Conf } = mad_utils:configs(),
     case mad_utils:get_value(deps, Conf, []) of
     case mad_utils:get_value(deps, Conf, []) of
         [] -> {ok,[]};
         [] -> {ok,[]};

+ 1 - 1
src/sources/mad_synrc.erl

@@ -1,7 +1,7 @@
 -module(mad_synrc).
 -module(mad_synrc).
 -compile([export_all, nowarn_export_all]).
 -compile([export_all, nowarn_export_all]).
 
 
-deps(Params) ->
+deps(_Params) ->
     { Cwd, ConfigFile, Conf } = mad_utils:configs(),
     { Cwd, ConfigFile, Conf } = mad_utils:configs(),
     case mad_utils:get_value(deps, Conf, []) of
     case mad_utils:get_value(deps, Conf, []) of
         [] -> {ok,[]};
         [] -> {ok,[]};