Browse Source

fix ERROR returning

Namdak Tonpa 6 years ago
parent
commit
d9f7be0bb3
5 changed files with 23 additions and 28 deletions
  1. 1 1
      include/mad.hrl
  2. BIN
      mad
  3. 4 5
      src/compile/mad_compile.erl
  4. 2 1
      src/compile/mad_erl.erl
  5. 16 21
      src/mad.erl

+ 1 - 1
include/mad.hrl

@@ -1 +1 @@
--define(VERSION,"6f6474").
+-define(VERSION,"871327").

BIN
mad


+ 4 - 5
src/compile/mad_compile.erl

@@ -68,17 +68,16 @@ dep(Cwd, _Conf, ConfigFile, Name) ->
                                         IncDir, EbinDir, Opts,Includes),
 
             put(Name, compiled),
-            case (DepsRes orelse FilesStatus orelse DTLStatus orelse PortStatus)
-                 andalso filelib:is_dir(Name)==false of
-                 true -> {error,Name};
+            case (DepsRes orelse FilesStatus orelse DTLStatus orelse PortStatus) of
+                 true  -> {error,Name};
                  false -> {ok,Name} end end.
 
 compile_files([],_,_,_,_) -> false;
 compile_files([File|Files],Inc,Bin,Opt,Deps) ->
     case (module(filetype(File))):compile(File,Inc,Bin,Opt,Deps) of
-         true -> io:format("Error: ~p~n",[[File,Inc,Bin,Opt,Deps]]), true;
+         true -> io:format("Broken Compilation in ~p~n",[File]), true;
          false -> compile_files(Files,Inc,Bin,Opt,Deps);
-         X -> mad:info("Compilation Error: ~p~n",[{X,File}]), true end.
+         X -> mad:info("Unknown Error: ~p~n",[{X,File}]), true end.
 
 module("erl")      -> mad_erl;
 module("ctt")      -> mad_cubical;

+ 2 - 1
src/compile/mad_erl.erl

@@ -14,8 +14,9 @@ compile(File,Inc,Bin,Opt,Deps) ->
     Compiled = mad_compile:is_compiled(BeamFile, File),
     if  Compiled =:= false ->
         Opts1 = ?COMPILE_OPTS(Inc, Bin, Opt, Deps),
+        NewCompile = compile:file(File, filter(Opts1)),
         mad:info("Compiling ~s~n", [File -- mad_utils:cwd()]),
-        ret(compile:file(File, filter(Opts1)));
+        ret(NewCompile);
     true -> false end.
 
 ret(error) -> true;

+ 16 - 21
src/mad.erl

@@ -14,19 +14,16 @@ main(Params)      ->
 
     return(
         lists:any(fun({error,_}) -> true; (_) -> false end,
-            lists:flatten(
-                lists:foldl(fun({Fun,Arg},[]) ->
-                    mad_hooks:run_hooks(pre, Fun),
-                    Errors = errors((profile()):Fun(Arg)),
-                    mad_hooks:run_hooks(post, Fun),
-                    Errors;
-                ({_,_},Err) ->
-                    errors(Invalid), {return,Err}
-                end,
-                [], Valid)
-           )
-        )
-    ).
+        lists:flatten(
+        lists:foldl(
+        fun ({Fun,Arg},[]) ->
+                mad_hooks:run_hooks(pre, Fun),
+                Errors = errors((profile()):Fun(Arg)),
+                mad_hooks:run_hooks(post, Fun),
+                Errors;
+            ({_,_},Err) ->
+                errors(Invalid), {return,Err}
+        end, [], Valid)))).
 
 atomize("static") -> 'static';
 atomize("deploy") -> 'deploy';
@@ -50,16 +47,14 @@ atomize(Else)     -> Else.
 
 profile()         -> application:get_env(mad,profile,mad_local).
 
-errors([])        -> [];
-errors(false)     -> [];
-errors(true)      -> {error,unknown};
-errors({error,L}) -> info("ERROR: ~tp~n",[L]), [{error,L}];
-errors({ok,_})    -> info("OK~n",[]), [];
-errors(X)         -> info("RETURN: ~tp~n",[X]), [{error,X}].
+errors([])            -> [];
+errors(false)         -> [];
+errors(true)          -> {error,unknown};
+errors({error,Where}) -> info("ERROR~n"), [{error,Where}];
+errors({ok,_})        -> info("OK~n",[]), [].
 
 return(true)      -> 1;
-return(false)     -> 0;
-return(X)         -> X.
+return(false)     -> 0.
 
 host()            -> try {ok,H} = inet:gethostname(), H catch _:_ -> <<>> end.