diff options
author | Loïc Hoguin <[email protected]> | 2015-05-17 10:33:21 +0300 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2015-05-17 10:49:35 +0300 |
commit | f8224ed56e141013b636e556f24ff00a7724b0d9 (patch) | |
tree | d2ad5248da20402eddbf38f94ed8a295c7784701 /core | |
parent | 909553ad7e16126e70756eca888edfb2e2b2c65b (diff) | |
download | erlang.mk-f8224ed56e141013b636e556f24ff00a7724b0d9.tar.gz erlang.mk-f8224ed56e141013b636e556f24ff00a7724b0d9.tar.bz2 erlang.mk-f8224ed56e141013b636e556f24ff00a7724b0d9.zip |
Find first files from source forms
Some projects use parse transforms but do not put them in
erl_first_files. We need to parse the files directly and
find the compile directives ourselves.
Diffstat (limited to 'core')
-rw-r--r-- | core/deps.mk | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/core/deps.mk b/core/deps.mk index 480f07b..6219f76 100644 --- a/core/deps.mk +++ b/core/deps.mk @@ -184,6 +184,38 @@ define dep_autopatch_rebar.erl Write(io_lib:format("COMPILE_FIRST +=~s\n", [Names])) end end(), + FindFirst = fun(F, Fd) -> + case io:parse_erl_form(Fd, undefined) of + {ok, {attribute, _,compile, {parse_transform, PT}}, _} -> + [PT, F(F, Fd)]; + {ok, {attribute, _, include, Hrl}, _} -> + case file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]) of + {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)]; + _ -> + case file:open("$(DEPS_DIR)/$(1)/src/" ++ Hrl, [read]) of + {ok, HrlFd} -> [F(F, HrlFd), F(F, Fd)]; + _ -> [F(F, Fd)] + end + end; + {ok, {attribute, _, include_lib, "$(1)/include/" ++ Hrl}, _} -> + {ok, HrlFd} = file:open("$(DEPS_DIR)/$(1)/include/" ++ Hrl, [read]), + [F(F, HrlFd), F(F, Fd)]; + {eof, _} -> + file:close(Fd), + []; + _ -> + F(F, Fd) + end + end, + fun() -> + ErlFiles = filelib:wildcard("$(DEPS_DIR)/$(1)/src/*.erl"), + First = lists:usort(lists:flatten([begin + {ok, Fd} = file:open(F, [read]), + FindFirst(FindFirst, Fd) + end || F <- ErlFiles])), + Write(["COMPILE_FIRST +=", [[" ", atom_to_list(M)] || M <- First, + lists:member("$(DEPS_DIR)/$(1)/src/" ++ atom_to_list(M) ++ ".erl", ErlFiles)], "\n"]) + end(), PortSpec = fun(Name, {_, Output, Input, [{env, Env}]}) -> filelib:ensure_dir("$(DEPS_DIR)/$(1)/" ++ Output), file:write_file("$(DEPS_DIR)/$(1)/c_src/Makefile." ++ Name, [ |