Browse Source

Add is_behaviour/1, improve sort_by_priority/4

Sina Samavati 11 years ago
parent
commit
9c31fbf911
1 changed files with 15 additions and 5 deletions
  1. 15 5
      src/mad_compile.erl

+ 15 - 5
src/mad_compile.erl

@@ -175,11 +175,11 @@ sort_by_priority([], High, Medium, Low) ->
     (High ++ Medium) ++ Low;
 sort_by_priority([H|T], High, Medium, Low) ->
     {High1, Medium1, Low1} =
-        case mad_utils:exec("sed", ["-n", "'/-callback/p'", H]) of
-            [] ->
-                {High, [H|Medium], Low};
-            _ ->
-                {[H|High], Medium, Low}
+        case is_behaviour(H) of
+            true ->
+                {[H|High], Medium, Low};
+            false ->
+                {High, [H|Medium], Low}
         end,
     {High2, Medium2, Low2} =
         case mad_utils:exec("sed", ["-n", "'/-compile/p'", H]) of
@@ -197,3 +197,13 @@ foreach(_, [], _) ->
 foreach(Fun, [Dir|T], ConfigFile) ->
     Fun(Dir, ConfigFile),
     foreach(Fun, T, ConfigFile).
+
+-spec is_behaviour(file:name()) -> boolean().
+is_behaviour(File) ->
+    case filelib:is_file(File) of
+        true ->
+            [] =/= mad_utils:exec("sed", ["-n", "-e", "'/-callback/p'", "-e",
+                                          "'/behaviour_info\\/1/p'", File]);
+        _ ->
+            false
+    end.