From 6b1c91a5c92e993acf74cc3a0052b74f9f94b8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Catalinas=20Jim=C3=A9nez?= Date: Mon, 22 Apr 2013 00:21:43 +0200 Subject: [PATCH 1/2] Escript locate app root to improve include paths handling Thanks to the suggestions of @lafka and @aerosol on: http://github.com/jimenezrick/vimerl/pull/46/files --- compiler/erlang_check.erl | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/compiler/erlang_check.erl b/compiler/erlang_check.erl index a65c387..0a51fe2 100755 --- a/compiler/erlang_check.erl +++ b/compiler/erlang_check.erl @@ -1,7 +1,7 @@ #!/usr/bin/env escript main([File]) -> - Dir = filename:dirname(File), + Dir = get_root(filename:dirname(File)), Defs = [strong_validation, warn_export_all, warn_export_vars, @@ -9,10 +9,7 @@ main([File]) -> warn_obsolete_guard, warn_unused_import, report, - {i, Dir ++ "/include"}, - {i, Dir ++ "/../include"}, - {i, Dir ++ "/../../include"}, - {i, Dir ++ "/../../../include"}], + {i, Dir ++ "/include"}], RebarFile = rebar_file(Dir), RebarOpts = rebar_opts(RebarFile), code:add_patha(filename:absname("ebin")), @@ -31,6 +28,7 @@ rebar_file(Dir) -> end. rebar_opts(RebarFile) -> + Dir = get_root(filename:dirname(File)), case file:consult(RebarFile) of {ok, Terms} -> RebarLibDirs = proplists:get_value(lib_dirs, Terms, []), @@ -40,9 +38,21 @@ rebar_opts(RebarFile) -> end, RebarLibDirs), RebarDepsDir = proplists:get_value(deps_dir, Terms, "deps"), code:add_pathsa(filelib:wildcard(RebarDepsDir ++ "/*/ebin")), - proplists:get_value(erl_opts, Terms, []); + IncludeDeps = {i, filename:join(Dir, RebarDepsDir)}, + proplists:get_value(erl_opts, Terms, []) ++ [IncludeDeps]; {error, _} when RebarFile == "rebar.config" -> []; {error, _} -> rebar_opts("rebar.config") end. + +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). From ae5824c8e3ed14ac1142e6075634142b44b4776c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Catalinas=20Jim=C3=A9nez?= Date: Mon, 22 Apr 2013 13:28:21 +0200 Subject: [PATCH 2/2] Fix code typo --- compiler/erlang_check.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/erlang_check.erl b/compiler/erlang_check.erl index 0a51fe2..71f19c9 100755 --- a/compiler/erlang_check.erl +++ b/compiler/erlang_check.erl @@ -28,7 +28,7 @@ rebar_file(Dir) -> end. rebar_opts(RebarFile) -> - Dir = get_root(filename:dirname(File)), + Dir = get_root(filename:dirname(RebarFile)), case file:consult(RebarFile) of {ok, Terms} -> RebarLibDirs = proplists:get_value(lib_dirs, Terms, []),