File: erlang_check_file.erl

package info (click to toggle)
vim-syntastic 3.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,064 kB
  • ctags: 888
  • sloc: erlang: 52; sh: 41; python: 8; makefile: 2
file content (61 lines) | stat: -rwxr-xr-x 1,972 bytes parent folder | download
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
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env escript
-export([main/1]).

main([FileName]) ->
    LibDirs = (["ebin", "include", "src", "test"] ++
               filelib:wildcard("{apps,deps,lib}/*/{ebin,include}")),
    compile(FileName, LibDirs);

main([FileName, "-rebar", Path, LibDirs]) ->
    {ok, L} = file:consult(Path),
    P = dict:from_list(L),
    Root = filename:dirname(Path),

    Lib1 = case dict:find(lib_dirs, P) of
             {ok, X} -> lists:map(fun(Sub) -> Root ++ "/" ++ Sub end, X);
             _ -> []
           end,

    Lib2 = case dict:find(sub_dirs, P) of
             {ok, Y} -> lists:foldl(
                          fun(Sub,Sofar) ->
                              Sofar ++ [
                                        Root ++ "/" ++ Sub,
                                        Root ++ "/" ++ Sub ++ "/include",
                                        Root ++ "/" ++ Sub ++ "/deps",
                                        Root ++ "/" ++ Sub ++ "/lib"
                                       ] end, [], Y);
             _ -> []
           end,

    LibDirs1 = LibDirs ++ Lib1 ++ Lib2,
    %io:format("~p~n", [LibDirs1]),
    compile(FileName, LibDirs1);

main([FileName, LibDirs]) ->
    compile(FileName, LibDirs).

compile(FileName, LibDirs) ->
    Root = get_root(filename:dirname(FileName)),
    ok = code:add_pathsa(LibDirs),
    compile:file(FileName,
                 [warn_obsolete_guard,
                  warn_unused_import,
                  warn_shadow_vars,
                  warn_export_vars,
                  strong_validation,
                  report] ++
                 [{i, filename:join(Root, I)} || I <- LibDirs]).

get_root(Dir) ->
    Path = filename:split(filename:absname(Dir)),
    filename:join(get_root(lists:reverse(Path), Path)).

get_root([], Path) ->
    Path;
get_root(["src" | Tail], _Path) ->
    lists:reverse(Tail);
get_root(["test" | Tail], _Path) ->
    lists:reverse(Tail);
get_root([_ | Tail], Path) ->
    get_root(Tail, Path).