diff options
Diffstat (limited to 'src/rebar_app_utils.erl')
-rw-r--r-- | src/rebar_app_utils.erl | 73 |
1 files changed, 26 insertions, 47 deletions
diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index 7239fe7..88b75ac 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -117,33 +117,21 @@ parse_dep(Dep, Parent, DepsDir, State, Locks, Level) -> end end. +parse_dep(Parent, {Name, Vsn, {pkg, PkgName}}, DepsDir, IsLock, State) -> + {PkgName1, PkgVsn} = parse_goal(ec_cnv:to_binary(PkgName), ec_cnv:to_binary(Vsn)), + pkg_to_app(Parent, DepsDir, Name, PkgName1, PkgVsn, IsLock, State); +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), + pkg_to_app(Parent, DepsDir, Name, PkgName1, PkgVsn, IsLock, State); parse_dep(Parent, {Name, Vsn}, DepsDir, IsLock, State) when is_list(Vsn); is_binary(Vsn) -> %% Versioned Package dependency - CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, Name)), - case rebar_app_info:discover(CheckoutsDir) of - {ok, _App} -> - dep_to_app(root, DepsDir, Name, [], [], IsLock, State); - not_found -> - {PkgName, PkgVsn} = parse_goal(ec_cnv:to_binary(Name) - ,ec_cnv:to_binary(Vsn)), - %% Verify package actually exists. This will throw a missing_package exception - rebar_packages:deps(PkgName, PkgVsn, State), - Source = {pkg, PkgName, PkgVsn}, - rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, PkgName, PkgVsn, Source, IsLock, State), pkg) - end; + {PkgName, PkgVsn} = parse_goal(ec_cnv:to_binary(Name), ec_cnv:to_binary(Vsn)), + pkg_to_app(Parent, DepsDir, PkgName, PkgName, PkgVsn, IsLock, State); parse_dep(Parent, Name, DepsDir, IsLock, State) when is_atom(Name); is_binary(Name) -> %% Unversioned package dependency {PkgName, PkgVsn} = get_package(ec_cnv:to_binary(Name), State), - CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, Name)), - 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(PkgName, PkgVsn, State), - Source = {pkg, PkgName, PkgVsn}, - rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, PkgName, PkgVsn, Source, IsLock, State), pkg) - end; + pkg_to_app(Parent, DepsDir, PkgName, PkgName, PkgVsn, IsLock, State); parse_dep(Parent, {Name, Source}, DepsDir, IsLock, State) when is_tuple(Source) -> dep_to_app(Parent, DepsDir, Name, [], Source, IsLock, State); parse_dep(Parent, {Name, _Vsn, Source}, DepsDir, IsLock, State) when is_tuple(Source) -> @@ -151,27 +139,26 @@ 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) -> ?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); -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)), - 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(Name, Vsn, State), - Source = {pkg, Name, Vsn}, - rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State), pkg) - end; +parse_dep(Parent, {Name, {pkg, PkgName, Vsn}, Level}, DepsDir, IsLock, State) when is_integer(Level) -> + pkg_to_app(Parent, DepsDir, Name, PkgName, Vsn, IsLock, State); parse_dep(Parent, {Name, Source, Level}, DepsDir, IsLock, State) when is_tuple(Source) , is_integer(Level) -> dep_to_app(Parent, DepsDir, Name, [], Source, IsLock, State); parse_dep(_, Dep, _, _, _) -> throw(?PRV_ERROR({parse_dep, Dep})). +%% Verify package exists and create the AppInfo record +pkg_to_app(Parent, DepsDir, AppName, PkgName, PkgVsn, IsLock, State) -> + %% Verify package actually exists. This will throw a missing_package exception + Deps = rebar_packages:deps(PkgName, PkgVsn, State), + Source = {pkg, PkgName, PkgVsn}, + AppInfo = dep_to_app(Parent, DepsDir, AppName, PkgVsn, Source, IsLock, State), + rebar_app_info:resource_type(rebar_app_info:deps(AppInfo, Deps), pkg). + dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State) -> CheckoutsDir = ec_cnv:to_list(rebar_dir:checkouts_dir(State, Name)), BaseDir = rebar_state:get(State, base_dir, []), - {ok, Dep} = case rebar_app_info:discover(CheckoutsDir) of + {ok, App1} = case rebar_app_info:discover(CheckoutsDir) of {ok, App} -> {ok, rebar_app_info:is_checkout(App, true)}; not_found -> @@ -180,24 +167,16 @@ dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State) -> {ok, App} -> {ok, App}; not_found -> - rebar_app_info:new(Name, Vsn, - ec_cnv:to_list(filename:join(DepsDir, Name))) + rebar_app_info:new(Parent, Name, Vsn, Dir, []) end end, - C = rebar_config:consult(rebar_app_info:dir(Dep)), - S = rebar_state:new(rebar_state:new(), C, rebar_app_info:dir(Dep)), + C = rebar_config:consult(rebar_app_info:dir(App1)), + S = rebar_state:new(rebar_state:new(), C, App1), Overrides = rebar_state:get(State, overrides, []), ParentOverrides = rebar_state:overrides(State), S1 = rebar_state:set(rebar_state:overrides(S, ParentOverrides++Overrides), base_dir, BaseDir), - Dep1 = rebar_app_info:state(Dep, S1), - AppInfo = rebar_app_info:is_lock(rebar_app_info:source(Dep1, Source), IsLock), - ResourceType = case Source of - {pkg, _, _} -> - pkg; - _ -> - src - end, - rebar_app_info:resource_type(rebar_app_info:parent(AppInfo, Parent), ResourceType). + App2 = rebar_app_info:state(App1, S1), + rebar_app_info:is_lock(rebar_app_info:source(App2, Source), IsLock). format_error({missing_package, Package}) -> io_lib:format("Package not found in registry: ~s", [Package]); |