12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- -module(mad_erl).
- %%-author('Sina Samavati').
- -export([
- compile/5
- ]).
- -define(COMPILE_OPTS(Inc, Ebin, Opts, Deps), [return_errors, return_warnings, warnings_as_errors, {i, [Inc]}, {outdir, Ebin}] ++ Opts ++ Deps).
- erl_to_beam(Bin, F) ->
- filename:join(Bin, filename:basename(F, ".erl") ++ ".beam").
- compile(File, Inc, Bin, Opt, Deps) ->
- BeamFile = erl_to_beam(Bin, File),
- Compiled = mad_compile:is_compiled(BeamFile, File),
- case Compiled of
- false ->
- Opts1 = ?COMPILE_OPTS(Inc, Bin, Opt, Deps),
- mad:info("Compiling ~s~n", [File -- mad_utils:cwd()]),
- ret(compile:file(File, Opts1));
- _ -> false
- end.
- ret(error) -> true;
- ret({error, X}) -> lines(error, X);
- ret({error, X, _}) -> lines(error, X);
- ret({ok, _}) -> false;
- ret({ok, _, []}) -> false;
- ret({ok, _, X}) -> lines(warning, X), false;
- ret({ok, _, X, _}) -> lines(warning, X), false.
- lines(Tag,X) ->
- S = case file:get_cwd() of
- {ok, Cwd} -> erlang:length(Cwd);
- _ -> 0
- end,
- [[ mad:info("Line ~p: ~p ~p in ~p~n", [ L, Tag, R, lists:nthtail(S, F) ]) || {L, _, R} <- E ] || {F, E} <- X ],
- true.
|