From f39fba1c87cf2d1d2293417656c0fa7b67eee532 Mon Sep 17 00:00:00 2001 From: Olav Frengstad Date: Thu, 18 Apr 2013 17:07:15 +0200 Subject: [PATCH] Add support for nested dirs inside src/ When having nested directories (for instance `src/protocol/tm_protocol.erl`) autocompilation would fail. This fix adds the abspath of all depdencies to the codepath and sets compile option {i, _} to support both `deps/` and `lib/`. --- syntax_checkers/erlang/erlang_check_file.erl | 30 +++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/syntax_checkers/erlang/erlang_check_file.erl b/syntax_checkers/erlang/erlang_check_file.erl index f4da8f93..54cc9366 100755 --- a/syntax_checkers/erlang/erlang_check_file.erl +++ b/syntax_checkers/erlang/erlang_check_file.erl @@ -1,18 +1,34 @@ #!/usr/bin/env escript -export([main/1]). -main([FileName| LibDirs=[_|_]]) -> - code:add_pathsa(LibDirs), - main([FileName]); - main([FileName]) -> + LibDirs = filelib:wildcard("{lib,deps}/*/ebin"), + compile(FileName, LibDirs); +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:dirname(FileName) ++ "/../include"}, - {i, filename:dirname(FileName) ++ "/../deps"}, - {i, filename:dirname(FileName) ++ "/../../../deps"} + {i, filename:join(Root, "include")}, + {i, filename:join(Root, "deps")}, + {i, filename:join(Root, "apps")}, + {i, filename:join(Root, "lib")} ]). + +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([_ | Tail], Path) -> + get_root(Tail, Path).