Browse Source

fix erl_first_files

Namdak Tonpa 6 years ago
parent
commit
d1504d0634
3 changed files with 30 additions and 35 deletions
  1. 1 1
      include/mad.hrl
  2. BIN
      mad
  3. 29 34
      src/compile/mad_compile.erl

+ 1 - 1
include/mad.hrl

@@ -1 +1 @@
--define(VERSION,"4346b8").
+-define(VERSION,"6a8222").

BIN
mad


+ 29 - 34
src/compile/mad_compile.erl

@@ -22,7 +22,7 @@ deps(Cwd, Conf, ConfigFile, [H|T]) ->
          true  -> {error,Name};
          false -> deps(Cwd, Conf, ConfigFile, T) end.
 
-bool({ok,_}) -> false;
+bool({ok,_})    -> false;
 bool({error,_}) -> true.
 
 dep(Cwd, _Conf, ConfigFile, Name) ->
@@ -31,50 +31,45 @@ dep(Cwd, _Conf, ConfigFile, Name) ->
     DepPath = filename:join([Cwd, DepsDir, Name]),
     mad:info("==> ~p~n",[Name]),
 
-    DepConfigFile = filename:join(DepPath, ConfigFile),
-    Conf = mad_utils:consult(DepConfigFile),
-    Conf1 = mad_script:script(DepConfigFile, Conf, Name),
-    Deps = mad_utils:get_value(deps, Conf1, []),
-    DepsRes = bool(deps(Cwd, Conf, ConfigFile, Deps)),
-
-    SrcDir = filename:join([mad_utils:src(DepPath)]),
-    PrivDir = filename:join([mad_utils:priv(DepPath)]),
-    PrivFiles = case application:get_env(mad,cubical,[]) of
-                     [] -> [];
-                     _ -> files(PrivDir,".ctt") end,
-    AllFiles = files(SrcDir,".yrl") ++
-               files(SrcDir,".xrl") ++
-               files(SrcDir,".erl"), % comment this to build with erlc/1
+    DepConfig = filename:join(DepPath, ConfigFile),
+    Conf      = mad_utils:consult(DepConfig),
+    Conf1     = mad_script:script(DepConfig, Conf, Name),
+    Deps      = mad_utils:get_value(deps, Conf1, []),
+    DepsRes   = bool(deps(Cwd, Conf, ConfigFile, Deps)),
+    SrcDir    = filename:join([mad_utils:src(DepPath)]),
+    PrivDir   = filename:join([mad_utils:priv(DepPath)]),
+    PrivFiles = case application:get_env(mad,cubical,[]) of [] -> []; _ -> files(PrivDir,".ctt") end,
+
+    AllFiles  = files(SrcDir,".yrl") ++
+                files(SrcDir,".xrl") ++
+                files(SrcDir,".erl"),
+
     AppSrcFiles = files(SrcDir,".app.src"),
-    Files = case mad_utils:get_value(erl_first_files, Conf1, []) of
-              []         -> AllFiles;
-              FirstFiles ->
-                FirstFiles1 = lists:map(fun (F) -> filename:join(SrcDir, F ++ ".erl") end, FirstFiles),
-                FirstFiles1 ++ lists:filter(fun (F) -> lists:member(F, FirstFiles) == false end, AllFiles)
-            end,
+    FirstFiles = [ filename:join([SrcDir,Y]) || Y <- mad_utils:get_value(erl_first_files, Conf1, []) ],
+    Files = lists:filter(fun (F) -> lists:member(F, FirstFiles) == false end, AllFiles),
 
     case Files of
         [] -> {ok,Name};
         Files ->
-            IncDir = mad_utils:include(DepPath),
-            EbinDir = mad_utils:ebin(DepPath),
-            LibDirs = mad_utils:get_value(lib_dirs, Conf, []),
+            IncDir   = mad_utils:include(DepPath),
+            EbinDir  = mad_utils:ebin(DepPath),
+            LibDirs  = mad_utils:get_value(lib_dirs, Conf, []),
             Includes = lists:flatten([
-                [{i,filename:join([DepPath,L,D,include])} || D<-mad_utils:raw_deps(Deps) ] % for -include
-             ++ [{i,filename:join([DepPath,L])}] || L <- LibDirs ]), % for -include_lib
-            %mad:info("DepPath ~p~n Includes: ~p~nLibDirs: ~p~n",[DepPath,Includes,LibDirs]),
+                       [{i,filename:join([DepPath,L,D,include])} || D <- mad_utils:raw_deps(Deps) ]
+                    ++ [{i,filename:join([DepPath,L])}] || L <- LibDirs ]),
 
-            % create EbinDir and add it to code path
             file:make_dir(EbinDir),
             code:replace_path(Name,EbinDir),
 
-            Opts = mad_utils:get_value(erl_opts, Conf1, []),
-            FilesStatus = compile_files(lists:sort(Files++PrivFiles)++AppSrcFiles,IncDir, EbinDir, Opts,Includes),
-            DTLStatus = mad_dtl:compile(DepPath,Conf1),
-            PortStatus = lists:any(fun(X)->X end,mad_port:compile(DepPath,Conf1)),
-            % io:format("Status: ~p~n",[[Name,FilesStatus,DTLStatus,PortStatus,DepsRes]]),
+            PortStatus  = lists:any(fun(X)->X end,mad_port:compile(DepPath,Conf1)),
+            Opts        = mad_utils:get_value(erl_opts, Conf1, []),
+            DTLStatus   = mad_dtl:compile(DepPath,Conf1),
+            FilesStatus = compile_files(FirstFiles++lists:sort(Files++PrivFiles)++AppSrcFiles,
+                                        IncDir, EbinDir, Opts,Includes),
+
             put(Name, compiled),
-            case (DepsRes orelse FilesStatus orelse DTLStatus orelse PortStatus) andalso filelib:is_dir(Name)==false of
+            case (DepsRes orelse FilesStatus orelse DTLStatus orelse PortStatus)
+                 andalso filelib:is_dir(Name)==false of
                  true -> {error,Name};
                  false -> {ok,Name} end end.