Skip to content

Loading…

Add support for versioning in dependency name #87

Closed
wants to merge 1 commit into from

6 participants

@lafka

Pick the dependency version by wildcard, then filter it by #dep.vsn_regex
The highest number will be picked or with fallback to app name (<depsdir>/#dep.app).

Motivation for this are cases where rebar does not have sole responsibility
for managing and building dependencies and a the stricter -
format is used for dependencies.

@lafka lafka Add support for versioning in dependency name
Pick the dependency version by wildcard, then filter it by #dep.vsn_regex
The highest number will be picked or with fallback to app name (`<depsdir>/#dep.app`).

Motivation for this are cases where rebar does not have sole responsibility
for managing and building dependencies and a the stricter <app>-<vsn>
format is used for dependencies.
9463293
@dizzyd
Rebar member

@lafka - I'm curious, if rebar isn't managing the deps, what is? Also, if something else is managing the deps, why not just have it do this work?

@lafka

@dizzyd In this instance i'm using EPM to manage the deps. Rebar is in some cases used for compilation/release generation, which is something EPM will never do.

@tsloughter
Rebar member

+1

I just ran into this setting up Nix to handle creating dev environments for Erlang projects and needing to tell rebar where the deps are. I see no reason to not support -.

@jaredmorrow

This PR is interesting, but for it to move forward (if you are interested still), I need to see some documentation added, both to the help page and sample rebar.config. Tests added to inttest would also make it easier to reason with.

If there is no longer a need (since EPM looks dead), let me know and I can close it.

@tuncer

Wouldn't it better to implement a real constraint (sat) solver (see #240).

@lafka

@jaredmorrow EPM is currently not maintained, so no requirement from my side.
@tuncer I would like to see that as well.

If there is an interest to merge this I can add the documentation and tests.

@tuncer

@lafka if we merge this now and add a real solver later, what would it mean for the features introduced in this patch?

@lafka

@tuncer assuming #240 allows you to have multiple copies of a dependency (with different version), this PR would not provide any new features.

I don't think there is a an urgent need for this feature so if #240 or basho/rebar#263 gets merged in the future I can close this.

@tuncer

@lafka so we should probably bring the various efforts together and avoid introducing similar but not combinable features.

@tsloughter tsloughter closed this
@ferd

Hi, this issue was closed in an attempt to do quick basic filtering, with the benediction of rebar project owners. These issues and pull requests are not issues or code we're spitting on, but given the burden of the task and how much code rot may have happened since these were open is unknown from maintainers at this time. All tickets prior to March 2014 were closed and will be reopened on a per-request basis if we see interest from the reporter or contributor, or if some of the issues reported are still valid after the various patches that have made it since they were opened.

This is a fairly brutal first step to help us get a proper understanding of what is still valid or not, but that has been proven efficient in the past. Sorry for the inconvenience, things should go smoother from there on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 9, 2013
  1. @lafka

    Add support for versioning in dependency name

    lafka committed
    Pick the dependency version by wildcard, then filter it by #dep.vsn_regex
    The highest number will be picked or with fallback to app name (`<depsdir>/#dep.app`).
    
    Motivation for this are cases where rebar does not have sole responsibility
    for managing and building dependencies and a the stricter <app>-<vsn>
    format is used for dependencies.
Showing with 21 additions and 7 deletions.
  1. +21 −7 src/rebar_deps.erl
View
28 src/rebar_deps.erl
@@ -253,12 +253,26 @@ get_shared_deps_dir(Config, Default) ->
rebar_config:get_xconf(Config, deps_dir, Default).
get_deps_dir(Config) ->
- get_deps_dir(Config, "").
+ {true, get_deps_dir_base(Config, "")}.
-get_deps_dir(Config, App) ->
+%% Pick the dependency directory, works in the following way:
+%% Get all deps, filter the version suffix using #dep.vsn_regex,
+%% pick highest version number available or fallback to #dep.app
+get_deps_dir(Config, #dep{app = App, vsn_regex = VsnRegex}) ->
+ BaseDir = get_deps_dir_base(Config, App),
+ Dirs0 = lists:reverse(lists:sort(filelib:wildcard(BaseDir ++ "-*"))),
+
+ [Dir|_] = Dirs = lists:filter(fun(Dir) ->
+ nomatch =/= re:run(Dir, VsnRegex)
+ end, Dirs0) ++ [BaseDir],
+
+ ?DEBUG("Picked ~p directory from ~p~n", [Dir, Dirs]),
+ {true, Dir}.
+
+get_deps_dir_base(Config, Suffix) ->
BaseDir = rebar_config:get_xconf(Config, base_dir, []),
DepsDir = get_shared_deps_dir(Config, "deps"),
- {true, filename:join([BaseDir, DepsDir, App])}.
+ filename:join([BaseDir, DepsDir, Suffix]).
dep_dirs(Deps) ->
[D#dep.dir || D <- Deps].
@@ -331,7 +345,7 @@ find_dep(Config, Dep) ->
find_dep(Config, Dep, undefined) ->
%% 'source' is undefined. If Dep is not satisfied locally,
%% go ahead and find it amongst the lib_dir's.
- case find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)) of
+ case find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep)) of
{_Config1, {avail, _Dir}} = Avail ->
Avail;
{Config1, {missing, _}} ->
@@ -341,7 +355,7 @@ find_dep(Config, Dep, _Source) ->
%% _Source is defined. Regardless of what it is, we must find it
%% locally satisfied or fetch it from the original source
%% into the project's deps
- find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)).
+ find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep)).
find_dep_in_dir(Config, _Dep, {false, Dir}) ->
{Config, {missing, Dir}};
@@ -452,7 +466,7 @@ use_source(Config, Dep, Count) ->
false ->
?CONSOLE("Pulling ~p from ~p\n", [Dep#dep.app, Dep#dep.source]),
require_source_engine(Dep#dep.source),
- {true, TargetDir} = get_deps_dir(Config, Dep#dep.app),
+ {true, TargetDir} = get_deps_dir(Config, Dep),
download_source(TargetDir, Dep#dep.source),
use_source(Config, Dep#dep { dir = TargetDir }, Count-1)
end.
@@ -512,7 +526,7 @@ update_source(Config, Dep) ->
%% VCS directory, such as when a source archive is built of a project, with
%% all deps already downloaded/included. So, verify that the necessary VCS
%% directory exists before attempting to do the update.
- {true, AppDir} = get_deps_dir(Config, Dep#dep.app),
+ {true, AppDir} = get_deps_dir(Config, Dep),
case has_vcs_dir(element(1, Dep#dep.source), AppDir) of
true ->
?CONSOLE("Updating ~p from ~p\n", [Dep#dep.app, Dep#dep.source]),
Something went wrong with that request. Please try again.