diff options
-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 | ||||
-rw-r--r-- | test/mock_pkg_resource.erl | 8 | ||||
-rw-r--r-- | test/rebar_pkg_SUITE.erl | 2 | ||||
-rw-r--r-- | test/rebar_test_utils.erl | 2 |
7 files changed, 37 insertions, 23 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. diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl index eda863b..e5c5645 100644 --- a/test/mock_pkg_resource.erl +++ b/test/mock_pkg_resource.erl @@ -35,7 +35,7 @@ mock(Opts) -> unmock() -> meck:unload(?MOD), - meck:unload(rebar_packages). + meck:unload(rebar_state). %%%%%%%%%%%%%%% %%% Private %%% @@ -115,10 +115,10 @@ mock_pkg_index(Opts) -> Dict = find_parts(Deps, Skip), GraphParts = to_graph_parts(Dict), Digraph = rebar_digraph:restore_graph(GraphParts), - meck:new(rebar_packages, [passthrough, no_link]), - meck:expect(rebar_packages, registry, + meck:new(rebar_state, [passthrough, no_link]), + meck:expect(rebar_state, registry, fun(_State) -> {ok, to_registry(Deps)} end), - meck:expect(rebar_packages, get_packages, + meck:expect(rebar_state, packages, fun(_State) -> {Dict, Digraph} end). %%%%%%%%%%%%%%% diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl index 85bd6f0..e99e787 100644 --- a/test/rebar_pkg_SUITE.erl +++ b/test/rebar_pkg_SUITE.erl @@ -171,7 +171,7 @@ mock_config(Name, Config) -> %% The state returns us a fake registry meck:new(rebar_state, [passthrough]), meck:expect(rebar_state, registry, - fun(_State) -> {ok, fake_registry} end), + fun(_State) -> {ok, T} end), meck:expect(rebar_state, get, fun(_State, rebar_packages_cdn, _Default) -> "http://test.com/" diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index 8e00483..c07df68 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -25,7 +25,9 @@ init_rebar_state(Config, Name) -> ok = ec_file:mkdir_p(CheckoutsDir), Verbosity = rebar3:log_level(), rebar_log:init(command_line, Verbosity), + GlobalDir = filename:join([DataDir, "cache"]), State = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])} + ,{global_rebar_dir, GlobalDir} ,{root_dir, AppsDir}]), [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, State} | Config]. |