]> granicus.if.org Git - ejabberd/commitdiff
Ignore beams compiled by Elixir
authorEvgeny Khramtsov <ekhramtsov@process-one.net>
Fri, 14 Jun 2019 20:35:51 +0000 (23:35 +0300)
committerEvgeny Khramtsov <ekhramtsov@process-one.net>
Fri, 14 Jun 2019 20:35:51 +0000 (23:35 +0300)
tools/hook_deps.sh
tools/opt_types.sh

index 4dca7f0784868e2e102de8619d51d47ecb58a27e..1ca4b4265979af75c2cc0619441ad822fcb8eb81 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
-%%! -pa ebin
 
 -record(state, {run_hooks = dict:new(),
                run_fold_hooks = dict:new(),
@@ -342,12 +341,16 @@ fold_beams(Fun, State, Paths) ->
          fun(File, {I, Acc}) ->
                  io:format("Progress: ~B% (~B/~B)\r",
                            [round(I*100/Total), I, Total]),
-                 AbsCode = get_code_from_beam(File),
-                 Acc2 = lists:foldl(
-                          fun(Form, Acc1) ->
-                                  Fun(File, Form, Acc1)
-                          end, Acc, AbsCode),
-                 {I+1, Acc2}
+                 case is_elixir_beam(File) of
+                     true -> {I+1, Acc};
+                     false ->
+                         AbsCode = get_code_from_beam(File),
+                         Acc2 = lists:foldl(
+                                  fun(Form, Acc1) ->
+                                          Fun(File, Form, Acc1)
+                                  end, Acc, AbsCode),
+                         {I+1, Acc2}
+                 end
          end, {0, State}, Paths1),
     State1.
 
@@ -356,17 +359,28 @@ fold_paths(Paths) ->
       fun(Path) ->
              case filelib:is_dir(Path) of
                  true ->
-                     lists:reverse(
-                       filelib:fold_files(
-                         Path, ".+\.beam\$", false,
-                         fun(File, Acc) ->
-                                 [File|Acc]
-                         end, []));
+                     Beams = lists:reverse(
+                               filelib:fold_files(
+                                 Path, ".+\.beam\$", false,
+                                 fun(File, Acc) ->
+                                         [File|Acc]
+                                 end, [])),
+                     case Beams of
+                         [] -> ok;
+                         _ -> code:add_path(Path)
+                     end,
+                     Beams;
                  false ->
                      [Path]
              end
       end, Paths).
 
+is_elixir_beam(File) ->
+    case filename:basename(File) of
+       "Elixir" ++ _ -> true;
+       _ -> false
+    end.
+
 get_code_from_beam(File) ->
     try
        {ok, {_, List}} = beam_lib:chunks(File, [abstract_code]),
index a5c475970dda4a51a17be2d37ac06710d0929a4c..6dd46c3364754c5a3f770349861b7718a9902dfc 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/env escript
 %% -*- erlang -*-
-%%! -pa ebin
 
 -compile([nowarn_unused_function]).
 -record(state, {g_opts = #{} :: map(),
@@ -495,14 +494,18 @@ fold_beams(Fun, State, Paths) ->
          fun(File, {I, Acc}) ->
                  io:format("Progress: ~B% (~B/~B)\r",
                            [round(I*100/Total), I, Total]),
-                 AbsCode = get_code_from_beam(File),
-                 Acc2 = case is_behaviour(AbsCode, ejabberd_config) of
-                            true ->
-                                fold_opt(File, Fun, Acc, AbsCode);
-                            false ->
-                                fold_mod_opt(File, Fun, Acc, AbsCode)
-                        end,
-                 {I+1, Acc2}
+                 case is_elixir_beam(File) of
+                     true -> {I+1, Acc};
+                     false ->
+                         AbsCode = get_code_from_beam(File),
+                         Acc2 = case is_behaviour(AbsCode, ejabberd_config) of
+                                    true ->
+                                        fold_opt(File, Fun, Acc, AbsCode);
+                                    false ->
+                                        fold_mod_opt(File, Fun, Acc, AbsCode)
+                                end,
+                         {I+1, Acc2}
+                 end
          end, {0, State}, Paths1),
     State1.
 
@@ -543,12 +546,17 @@ fold_paths(Paths) ->
       fun(Path) ->
              case filelib:is_dir(Path) of
                  true ->
-                     lists:reverse(
-                       filelib:fold_files(
-                         Path, ".+\.beam\$", false,
-                         fun(File, Acc) ->
-                                 [File|Acc]
-                         end, []));
+                     Beams = lists:reverse(
+                               filelib:fold_files(
+                                 Path, ".+\.beam\$", false,
+                                 fun(File, Acc) ->
+                                         [File|Acc]
+                                 end, [])),
+                     case Beams of
+                         [] -> ok;
+                         _ -> code:add_path(Path)
+                     end,
+                     Beams;
                  false ->
                      [Path]
              end
@@ -566,6 +574,12 @@ is_behaviour(AbsCode, Mod) ->
              end
       end, AbsCode).
 
+is_elixir_beam(File) ->
+    case filename:basename(File) of
+       "Elixir" ++ _ -> true;
+       _ -> false
+    end.
+
 get_code_from_beam(File) ->
     try
         {ok, {_, List}} = beam_lib:chunks(File, [abstract_code]),