-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change xref paths to only those of runtime deps #2354
Change xref paths to only those of runtime deps #2354
Conversation
This commit changes mainly the `rebar_paths` module by adding a new `runtime` target. When using that target, `rebar_paths:get_apps/2` will, for each project app, find all their `applications` and `included_applicactions` and filter those that could be found in rebar3's state.
@@ -36,7 +36,7 @@ init(State) -> | |||
|
|||
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. | |||
do(State) -> | |||
rebar_paths:set_paths([deps], State), | |||
rebar_paths:set_paths([runtime], State), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ferd IIRC you were the one who reworked how rebar3 handles the paths, so if this change should instead be [deps, runtime]
or anything else, let me know :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The [deps, runtime]
approach would basically say "load all the deps, then put the runtime deps after them in the path". We use that form for [deps, plugins]
or [plugins, deps]
when we need both to be present, but favor one type of dependency if some of the apps in there clash (many versions exist).
Since the objective of this PR is to run only on runtime deps, then I'd expect the current [runtime]
to be correct.
Also this PR has yet to change (as I think that it should do so) the paths test suite to reflect these changes, but I'm a bit lost. I guess I should be making a new test case with an application that has runtime deps, but I'm afraid I might need some guidance to do that :/ |
I'm not sure there should be any change to the paths when running tests. |
AFAIK there isn't , but as you and Fred have more knowledge on the subject I wanted to raise the question to be sure. |
@@ -36,7 +36,7 @@ init(State) -> | |||
|
|||
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. | |||
do(State) -> | |||
rebar_paths:set_paths([deps], State), | |||
rebar_paths:set_paths([runtime], State), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The [deps, runtime]
approach would basically say "load all the deps, then put the runtime deps after them in the path". We use that form for [deps, plugins]
or [plugins, deps]
when we need both to be present, but favor one type of dependency if some of the apps in there clash (many versions exist).
Since the objective of this PR is to run only on runtime deps, then I'd expect the current [runtime]
to be correct.
bbbb73a
to
7cb5793
Compare
This looks good. I'm trying to think of a way we could make that work for tests to confirm the change works as desired here. |
Since testing the paths is hard, one thing we could do is test the new behaviour of By extension though it means I'd expect us to be able to write a proper test for rebar_paths as well. I'd expect we could do something like adding a top-level app in rebar3/test/rebar_paths_SUITE.erl Lines 17 to 56 in d11ceb4
rp_a and rp_b but none of the other apps. This will let us make sure that both these apps are visible during runtime deps being in scope but not in other cases.
Then we can add a test case like: runtime_paths(Config) ->
State = ?config(state, Config),
RootDir = filename:split(?config(root_dir, Config)),
%% Take a snapshot of runtime deps being set; to see if your test is valid, this should fail
%% when you set the [deps] paths nere
rebar_paths:set_paths([runtime], State),
RuntimePaths = code:get_path(),
%% Revert back to regular dep paths
rebar_paths:set_paths([deps, plugins], State),
DepPaths = code:get_path(),
?assertEqual(
RootDir ++ ["_build", "default", "lib", "rp_a", "ebin"],
find_first_instance("rp_a", RuntimePaths)
),
?assertEqual(
RootDir ++ ["_build", "default", "lib", "rp_b", "ebin"],
find_first_instance("rp_b", RuntimePaths)
),
?assertMatch(
{not_found, _},
find_first_instance("rp_c", RuntimePaths)
),
?assertEqual(
{not_found, _},
find_first_instance("rp_d", RuntimePaths)
),
?assertEqual(
{not_found, _},
find_first_instance("rp_e", RuntimePaths)
),
?assertEqual(
{not_found, _},
find_first_instance("relx", RuntimePaths)
),
ok. You could likely fold that part of the test into the existing |
This commit adds new checks in the `set_paths` test case related to runtime apps and their path handling with the `runtime` target in `rebar_paths`. These new checks also hope to increase the coverage of the changes done to the xref provider in this same PR (erlang#2354). This commit also adds some new helper functions to help deal with future changes related to these new checks (i.e., changes related to the runtime apps), besides fixing a problem when looking for the first instace of an app/dep/plugin in the path while testing.
@ferd Sorry this one took a bit of time to be updated, I had some errands to finish first. Thanks a lot for the detailed explanation of how to approach the changes to the test suite, it helped a lot! :) |
This commit adds new checks in the `set_paths` test case related to runtime apps and their path handling with the `runtime` target in `rebar_paths`. These new checks also hope to increase the coverage of the changes done to the xref provider in this same PR (erlang#2354). This commit also adds some new helper functions to help deal with future changes related to these new checks (i.e., changes related to the runtime apps), besides fixing a problem when looking for the first instace of an app/dep/plugin in the path while testing.
a95666f
to
24c4d78
Compare
Thanks for this! this is a cool fix to some hairy core utility code. |
This commit changes mainly the
rebar_paths
module by adding anew
runtime
target. When using that target,rebar_paths:get_apps/2
will, for each project app, find all their
applications
andincluded_applicactions
and filter those that could be foundin rebar3's state.