-
Notifications
You must be signed in to change notification settings - Fork 1
/
flymake.erl
49 lines (41 loc) · 1.32 KB
/
flymake.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-module(flymake).
-export([main/1]).
-define(REBARS, ["..", "../../.."]).
file_exists(FileName) ->
case file:read_file_info(FileName) of
{error, _} ->
false;
_ ->
true
end.
locate_build_tool([]) ->
not_found;
locate_build_tool([H|T]) ->
case file_exists(filename:join([H, "rebar"])) of
true ->
H;
false ->
locate_build_tool(T)
end.
manual_compile(FileName) ->
compile:file(FileName, [warn_obsolete_guard, warn_unused_import,
warn_shadow_vars, warn_export_vars,
strong_validation, report,
{i, "../include"},
{outdir,filename:join(["/tmp", os:getenv("USER")])}]).
normalize_rebar_error(Err, FileName) ->
[_|T] = string:tokens(Err, ":"),
string:join([FileName|T], ":").
rebar_build(FileName, Path) ->
file:set_cwd(Path),
Cmd = "./rebar compile 2>&1",
[_|T] = string:tokens(os:cmd(Cmd), "\n"),
Errors = [normalize_rebar_error(Err, FileName) || Err <- T],
lists:foreach(fun(E) -> io:format("~s~n", [E]) end, Errors).
main([FileName]) ->
case locate_build_tool(?REBARS) of
not_found ->
manual_compile(FileName);
Rebar ->
rebar_build(FileName, Rebar)
end.