Nimbin[12]?Mirrors & Forks / syntastic / commits / 4b93dffb

syntastic git · master

syntastic vim plugin (fork)

vim fork · first commit 2009-07-10 · last commit 2022-07-10 (4 years ago) · synced 3 days ago · upstream: github.com/vim-syntastic/syntastic

Vim Script 99%
git clone https://git.christianimmanuel.de/mirrors-forks/syntastic.gitwget https://git.christianimmanuel.de/mirrors-forks/syntastic/archive/syntastic.tar.gz

Use correct erlang include paths for rebar3 projects

Russ Garrett · 2017-12-14 12:36 · 4b93dffbd98fd3885ee7c4fcedaa65cf5b72f56d

Add a few more include paths for erlang projects built using rebar 3.
This allows syntastic to pick up dependencies and resolve include paths
in multiple-app rebar3 projects (assuming that the default `apps`
parent directory is used).

Existing erlang projects should be unaffected.

It's possible that this could be done slightly more elegantly by
shelling out to the new `rebar3 path` command, but this is quite slow in
our setup and may not be configured correctly in editing environments.
 syntax_checkers/erlang/erlang_check_file.erl | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/syntax_checkers/erlang/erlang_check_file.erl b/syntax_checkers/erlang/erlang_check_file.erl
index 89884345..0dc01658 100755
--- a/syntax_checkers/erlang/erlang_check_file.erl
+++ b/syntax_checkers/erlang/erlang_check_file.erl
@@ -69,6 +69,7 @@ rebar_opts(RebarFile) ->
     Dir = get_root(filename:dirname(RebarFile)),
     case file:consult(RebarFile) of
         {ok, Terms} ->
+            %% Add deps for a rebar (version < 3) project
             RebarLibDirs = proplists:get_value(lib_dirs, Terms, []),
             lists:foreach(
                 fun(LibDir) ->
@@ -76,8 +77,14 @@ rebar_opts(RebarFile) ->
                 end, RebarLibDirs),
             RebarDepsDir = proplists:get_value(deps_dir, Terms, "deps"),
             code:add_pathsa(filelib:wildcard(RebarDepsDir ++ "/*/ebin")),
-            IncludeDeps = {i, filename:join(Dir, RebarDepsDir)},
-            proplists:get_value(erl_opts, Terms, []) ++ [IncludeDeps];
+
+            %% Add deps for rebar 3
+            code:add_pathsa(filelib:wildcard(Dir ++ "/_build/default/lib/*/ebin")),
+            %% Add include dependencies
+            IncludeDeps = [{i, IPath} || IPath <- filelib:wildcard(Dir ++ "/_build/default/lib/*")] ++
+                            [{i, filename:join(Dir, RebarDepsDir)}, %% rebar 2 dependencies
+                             {i, filename:join(Dir, "apps")}], %% rebar 3 multi-apps
+            proplists:get_value(erl_opts, Terms, []) ++ IncludeDeps;
         {error, _} when RebarFile == "rebar.config" ->
           fallback_opts();
         {error, _} ->
@@ -258,12 +265,19 @@ apps_dir_from_src(SrcFile) ->
     SrcDir = filename:dirname(SrcFile),
     filename:join(SrcDir, "../../ebin").
 
+%% Find the root directory of the project
 get_root(Dir) ->
     Path = filename:split(filename:absname(Dir)),
     filename:join(get_root(lists:reverse(Path), Path)).
 
 get_root([], Path) ->
     Path;
+%% Strip off /apps/<appname>/src from the end of the path
+%% (rebar 3 multi-app project)
+get_root(["src", _Appname, "apps" | Tail], _Path) ->
+    lists:reverse(Tail);
+%% Strip off /src or /test from the end of the path
+%% (single-app project)
 get_root(["src" | Tail], _Path) ->
     lists:reverse(Tail);
 get_root(["test" | Tail], _Path) ->