diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_packages.erl | 11 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 5 | ||||
-rw-r--r-- | src/rebar_prv_packages.erl | 2 | ||||
-rw-r--r-- | src/rebar_state.erl | 30 |
4 files changed, 30 insertions, 18 deletions
diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl index e21f1fd..ca3b676 100644 --- a/src/rebar_packages.erl +++ b/src/rebar_packages.erl @@ -1,6 +1,6 @@ -module(rebar_packages). --export([get_packages/1 +-export([packages/1 ,registry/1 ,package_dir/1 ,check_registry/3 @@ -15,8 +15,9 @@ -type vsn() :: binary(). -type package() :: pkg_name() | {pkg_name(), vsn()}. --spec get_packages(rebar_state:t()) -> {rebar_dict(), rebar_digraph()}. -get_packages(State) -> +-spec packages(rebar_state:t()) -> {rebar_dict(), rebar_digraph()}. +%% DON'T USE IT! Use rebar_state:packages(State) instead. +packages(State) -> RegistryDir = package_dir(State), DictFile = filename:join(RegistryDir, "dict"), Edges = filename:join(RegistryDir, "edges"), @@ -42,6 +43,8 @@ get_packages(State) -> {dict:new(), digraph:new()} end. +-spec registry(rebar_state:t()) -> {ok, ets:tid()} | {error, any()}. +%% DON'T USE IT! Use rebar_state:registry(State) instead. registry(State) -> RegistryDir = package_dir(State), HexFile = filename:join(RegistryDir, "registry"), @@ -78,7 +81,7 @@ check_registry(Pkg, Vsn, State) -> end. registry_checksum({pkg, Name, Vsn}, State) -> - {ok, Registry} = registry(State), + {ok, Registry} = rebar_state:registry(State), case ets:lookup(Registry, {Name, Vsn}) of [{{_, _}, [_, Checksum | _]}] -> Checksum; diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 8fb3b47..3a5a7cd 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -186,7 +186,7 @@ handle_profile_pkg_level([], AllApps, _Seen, _Upgrade, _Locks, State) -> handle_profile_pkg_level(PkgDeps, AllApps, Seen, Upgrade, Locks, State) -> %% Read in package index and dep graph {Packages, Graph} = rebar_state:packages(State), - Registry = rebar_packages:registry(State), + Registry = rebar_state:registry(State), State1 = rebar_state:packages(rebar_state:registry(State, Registry) ,{Packages, Graph}), @@ -366,7 +366,8 @@ handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) -> Name = rebar_app_info:name(AppInfo), %% Deps may be under a sub project app, find it and use its state if so - S = rebar_app_info:state(AppInfo), + S0 = rebar_app_info:state(AppInfo), + S = rebar_state:registry(S0, rebar_state:registry(State)), C = rebar_config:consult(rebar_app_info:dir(AppInfo)), S1 = rebar_state:new(S, C, rebar_app_info:dir(AppInfo)), S2 = rebar_state:apply_overrides(S1, Name), diff --git a/src/rebar_prv_packages.erl b/src/rebar_prv_packages.erl index 880d4a6..82ed2f7 100644 --- a/src/rebar_prv_packages.erl +++ b/src/rebar_prv_packages.erl @@ -27,7 +27,7 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - {Dict, _} = rebar_packages:get_packages(State), + {Dict, _} = rebar_state:packages(State), print_packages(Dict), {ok, State}. diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 59a9588..7616151 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -88,9 +88,16 @@ new(Config) when is_list(Config) -> Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins} | Config], true = rebar_config:verify_config_format(Terms), Opts = dict:from_list(Terms), - BaseState#state_t { dir = rebar_dir:get_cwd(), - default = Opts, - opts = Opts }. + load_package_registry( + BaseState#state_t { dir = rebar_dir:get_cwd(), + default = Opts, + opts = Opts }). + +load_package_registry(Config0) -> + Registry = rebar_packages:registry(Config0), + Packages = rebar_packages:packages(Config0), + Config0#state_t{registry = Registry, + packages = Packages}. -spec new(t() | atom(), list()) -> t(). new(Profile, Config) when is_atom(Profile) @@ -102,10 +109,11 @@ new(Profile, Config) when is_atom(Profile) Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins} | Config], true = rebar_config:verify_config_format(Terms), Opts = dict:from_list(Terms), - BaseState#state_t { dir = rebar_dir:get_cwd(), - current_profiles = [Profile], - default = Opts, - opts = Opts }; + load_package_registry( + BaseState#state_t { dir = rebar_dir:get_cwd(), + current_profiles = [Profile], + default = Opts, + opts = Opts }); new(ParentState=#state_t{}, Config) -> %% Load terms from rebar.config, if it exists Dir = rebar_dir:get_cwd(), @@ -438,16 +446,16 @@ namespace(#state_t{namespace=Namespace}) -> namespace(State=#state_t{}, Namespace) -> State#state_t{namespace=Namespace}. -packages(State=#state_t{packages=undefined}) -> - rebar_packages:get_packages(State); +packages(#state_t{packages=undefined}) -> + throw(packages_usage_error); packages(#state_t{packages=Packages}) -> Packages. packages(State, Packages) -> State#state_t{packages=Packages}. -registry(State=#state_t{registry=undefined}) -> - rebar_packages:registry(State); +registry(#state_t{registry=undefined}) -> + throw(registry_usage_error); registry(#state_t{registry=Registry}) -> Registry. |