Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add other deps to library path when running xref #300

wants to merge 2 commits into from

4 participants


For those of us who do their sub_dirs as

{sub_dirs, ["apps/app1",

the other apps are not available in xrefs library path so calls between applications will always be seen as calls to undefined functions.

This fixes that problem.

(The proper and correct solution to how to run xref is of course to use a filtered code path which only contains applications which are (recursively) dependencies of the app that is currently checked. This is a bit bigger, and not part of the current pull request.)


This pull request passes (merged 1c05910c into ff8337f).


This pull request passes (merged 5c14f80a into ff8337f).

@tuncer tuncer was assigned

Looking into whether this is the correct solution or not. Potentially $SUBDIR/ebin should be in the global code path instead.


After looking at this again I think that this solution is not optimal, but good enough for now.

The proper way to do this is to merge code path handling with the way it's handled in compilation. I believe that all the directories should have already been part of the global code path. It has to be for compilation to work properly, so this already happens somewhere else in rebar.

The current patch is still a huge improvement from doing nothing, so I'm inclined to say merge for now and I'll do the proper fix at a later date.


Btw. I rebased from current master so it should merge cleanly.


I'm fine with this fix, but can you please add a comment in function that pulls in sub_dirs which explains why this is a short term fix? That way when we read the code in X months, we have a why. :)

Once you do that, I'll get it merged.


Got tired of waiting -- added comment myself and merged. :)

@dizzyd dizzyd closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 12, 2012
  1. @dLuna

    Add email address to my name

    dLuna authored
  2. @dLuna
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 5 deletions.
  1. +9 −5 src/rebar_xref.erl
14 src/rebar_xref.erl
@@ -28,7 +28,8 @@
%% -------------------------------------------------------------------
%% This module borrows heavily from project as
-%% written by Torbjorn Tornkvist <>, Daniel Luna and others.
+%% written by Torbjorn Tornkvist <>, Daniel Luna
+%% <> and others.
%% -------------------------------------------------------------------
@@ -43,7 +44,7 @@
xref(Config, _) ->
%% Spin up xref
{ok, _} = xref:start(xref),
- ok = xref:set_library_path(xref, code_path()),
+ ok = xref:set_library_path(xref, code_path(Config)),
xref:set_default(xref, [{warnings,
rebar_config:get(Config, xref_warnings, false)},
@@ -131,9 +132,12 @@ check_query({Query, Value}) ->
-code_path() ->
- [P || P <- code:get_path(),
- filelib:is_dir(P)] ++ [filename:join(rebar_utils:get_cwd(), "ebin")].
+code_path(Config) ->
+ BaseDir = rebar_config:get_xconf(Config, base_dir),
+ [P || P <- code:get_path() ++
+ [filename:join(BaseDir, filename:join(SubDir, "ebin"))
+ || SubDir <- rebar_config:get(Config, sub_dirs, [])],
+ filelib:is_dir(P)].
%% Ignore behaviour functions, and explicitly marked functions
Something went wrong with that request. Please try again.