Browse Source

support pkg attribute on dep to declare package name different from app name

pull/748/head
Tristan Sloughter 9 years ago
parent
commit
f2547a457f
3 changed files with 42 additions and 6 deletions
  1. +31
    -4
      src/rebar_app_utils.erl
  2. +9
    -0
      src/rebar_config.erl
  3. +2
    -2
      src/rebar_prv_install_deps.erl

+ 31
- 4
src/rebar_app_utils.erl View File

@ -117,6 +117,33 @@ parse_dep(Dep, Parent, DepsDir, State, Locks, Level) ->
end end
end. end.
parse_dep(Parent, {Name, Vsn, {pkg, PkgName}}, DepsDir, IsLock, State) ->
%% Versioned Package dependency with different package name from app name
CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, PkgName)),
case rebar_app_info:discover(CheckoutsDir) of
{ok, _App} ->
dep_to_app(root, DepsDir, Name, [], [], IsLock, State);
not_found ->
{PkgName1, PkgVsn} = parse_goal(ec_cnv:to_binary(PkgName)
,ec_cnv:to_binary(Vsn)),
%% Verify package actually exists. This will throw a missing_package exception
rebar_packages:deps(PkgName1, PkgVsn, State),
Source = {pkg, PkgName1, PkgVsn},
rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, Name, PkgVsn, Source, IsLock, State), pkg)
end;
parse_dep(Parent, {Name, {pkg, PkgName}}, DepsDir, IsLock, State) ->
%% Package dependency with different package name from app name
{PkgName1, PkgVsn} = get_package(ec_cnv:to_binary(PkgName), State),
CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, PkgName1)),
case rebar_app_info:discover(CheckoutsDir) of
{ok, _App} ->
dep_to_app(root, DepsDir, Name, [], [], IsLock, State);
not_found ->
%% Verify package actually exists. This will throw a missing_package exception
rebar_packages:deps(PkgName1, PkgVsn, State),
Source = {pkg, PkgName1, PkgVsn},
rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, Name, PkgVsn, Source, IsLock, State), pkg)
end;
parse_dep(Parent, {Name, Vsn}, DepsDir, IsLock, State) when is_list(Vsn); is_binary(Vsn) -> parse_dep(Parent, {Name, Vsn}, DepsDir, IsLock, State) when is_list(Vsn); is_binary(Vsn) ->
%% Versioned Package dependency %% Versioned Package dependency
CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, Name)), CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, Name)),
@ -151,15 +178,15 @@ parse_dep(Parent, {Name, _Vsn, Source}, DepsDir, IsLock, State) when is_tuple(So
parse_dep(Parent, {Name, _Vsn, Source, Opts}, DepsDir, IsLock, State) when is_tuple(Source) -> parse_dep(Parent, {Name, _Vsn, Source, Opts}, DepsDir, IsLock, State) when is_tuple(Source) ->
?WARN("Dependency option list ~p in ~p is not supported and will be ignored", [Opts, Name]), ?WARN("Dependency option list ~p in ~p is not supported and will be ignored", [Opts, Name]),
dep_to_app(Parent, DepsDir, Name, [], Source, IsLock, State); dep_to_app(Parent, DepsDir, Name, [], Source, IsLock, State);
parse_dep(Parent, {_Name, {pkg, Name, Vsn}, Level}, DepsDir, IsLock, State) when is_integer(Level) ->
CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, Name)),
parse_dep(Parent, {Name, {pkg, PkgName, Vsn}, Level}, DepsDir, IsLock, State) when is_integer(Level) ->
CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, PkgName)),
case rebar_app_info:discover(CheckoutsDir) of case rebar_app_info:discover(CheckoutsDir) of
{ok, _App} -> {ok, _App} ->
dep_to_app(root, DepsDir, Name, [], [], IsLock, State); dep_to_app(root, DepsDir, Name, [], [], IsLock, State);
not_found -> not_found ->
%% Verify package actually exists. This will throw a missing_package exception %% Verify package actually exists. This will throw a missing_package exception
rebar_packages:deps(Name, Vsn, State),
Source = {pkg, Name, Vsn},
rebar_packages:deps(PkgName, Vsn, State),
Source = {pkg, PkgName, Vsn},
rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State), pkg) rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State), pkg)
end; end;
parse_dep(Parent, {Name, Source, Level}, DepsDir, IsLock, State) when is_tuple(Source) parse_dep(Parent, {Name, Source, Level}, DepsDir, IsLock, State) when is_tuple(Source)

+ 9
- 0
src/rebar_config.erl View File

@ -128,11 +128,20 @@ find_newly_added(ConfigDeps, LockedDeps) ->
check_newly_added({_, _}=Dep, LockedDeps) -> check_newly_added({_, _}=Dep, LockedDeps) ->
check_newly_added_(Dep, LockedDeps); check_newly_added_(Dep, LockedDeps);
check_newly_added({_, _, {pkg, _}}=Dep, LockedDeps) ->
check_newly_added_(Dep, LockedDeps);
check_newly_added({Name, _, Source}, LockedDeps) -> check_newly_added({Name, _, Source}, LockedDeps) ->
check_newly_added_({Name, Source}, LockedDeps); check_newly_added_({Name, Source}, LockedDeps);
check_newly_added(Dep, LockedDeps) -> check_newly_added(Dep, LockedDeps) ->
check_newly_added_(Dep, LockedDeps). check_newly_added_(Dep, LockedDeps).
check_newly_added_({Name, Vsn, Source}, LockedDeps) ->
case check_newly_added_(Name, LockedDeps) of
{true, Name1} ->
{true, {Name1, Vsn, Source}};
false ->
false
end;
check_newly_added_({Name, Source}, LockedDeps) -> check_newly_added_({Name, Source}, LockedDeps) ->
case check_newly_added_(Name, LockedDeps) of case check_newly_added_(Name, LockedDeps) of
{true, Name1} -> {true, Name1} ->

+ 2
- 2
src/rebar_prv_install_deps.erl View File

@ -251,7 +251,6 @@ update_unseen_dep(AppInfo, Profile, Level, Deps, Apps, State, Upgrade, Seen, Loc
handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) -> handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) ->
Profiles = rebar_state:current_profiles(State), Profiles = rebar_state:current_profiles(State),
Name = rebar_app_info:name(AppInfo), Name = rebar_app_info:name(AppInfo),
Vsn = rebar_app_info:original_vsn(AppInfo),
%% Deps may be under a sub project app, find it and use its state if so %% Deps may be under a sub project app, find it and use its state if so
S = rebar_app_info:state(AppInfo), S = rebar_app_info:state(AppInfo),
@ -273,7 +272,8 @@ handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) ->
%% Upgrade lock level to be the level the dep will have in this dep tree %% Upgrade lock level to be the level the dep will have in this dep tree
case rebar_app_info:resource_type(AppInfo1) of case rebar_app_info:resource_type(AppInfo1) of
pkg -> pkg ->
NewDeps = rebar_packages:deps(Name, Vsn, S5),
{pkg, PkgName, PkgVsn} = rebar_app_info:source(AppInfo1),
NewDeps = rebar_packages:deps(PkgName, PkgVsn, S5),
NewDeps1 = rebar_app_utils:parse_deps(Name, DepsDir, NewDeps, S5, Locks, Level+1), NewDeps1 = rebar_app_utils:parse_deps(Name, DepsDir, NewDeps, S5, Locks, Level+1),
{rebar_app_info:deps(AppInfo1, NewDeps), NewDeps1, State}; {rebar_app_info:deps(AppInfo1, NewDeps), NewDeps1, State};
_ -> _ ->

Loading…
Cancel
Save