mad_erl.erl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. -module(mad_erl).
  2. %%-author('Sina Samavati').
  3. -export([
  4. compile/5
  5. ]).
  6. -define(COMPILE_OPTS(Inc, Ebin, Opts, Deps), [return_errors, return_warnings, warnings_as_errors, {i, [Inc]}, {outdir, Ebin}] ++ Opts ++ Deps).
  7. erl_to_beam(Bin, F) ->
  8. filename:join(Bin, filename:basename(F, ".erl") ++ ".beam").
  9. compile(File, Inc, Bin, Opt, Deps) ->
  10. BeamFile = erl_to_beam(Bin, File),
  11. Compiled = mad_compile:is_compiled(BeamFile, File),
  12. case Compiled of
  13. false ->
  14. Opts1 = ?COMPILE_OPTS(Inc, Bin, Opt, Deps),
  15. mad:info("Compiling ~s~n", [File -- mad_utils:cwd()]),
  16. ret(compile:file(File, Opts1));
  17. _ -> false
  18. end.
  19. ret(error) -> true;
  20. ret({error, X}) -> lines(error, X);
  21. ret({error, X, _}) -> lines(error, X);
  22. ret({ok, _}) -> false;
  23. ret({ok, _, []}) -> false;
  24. ret({ok, _, X}) -> lines(warning, X), false;
  25. ret({ok, _, X, _}) -> lines(warning, X), false.
  26. lines(Tag,X) ->
  27. S = case file:get_cwd() of
  28. {ok, Cwd} -> erlang:length(Cwd);
  29. _ -> 0
  30. end,
  31. [[ mad:info("Line ~p: ~p ~p in ~p~n", [ L, Tag, R, lists:nthtail(S, F) ]) || {L, _, R} <- E ] || {F, E} <- X ],
  32. true.