diff options
-rw-r--r-- | src/rebar_app_discover.erl | 10 | ||||
-rw-r--r-- | src/rebar_file_utils.erl | 6 | ||||
-rw-r--r-- | src/rebar_packages.erl | 27 | ||||
-rw-r--r-- | src/rebar_prv_update.erl | 13 | ||||
-rw-r--r-- | src/rebar_state.erl | 26 | ||||
-rw-r--r-- | test/rebar_pkg_SUITE.erl | 1 |
6 files changed, 50 insertions, 33 deletions
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index 8b1e58e..2b1c767 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -26,12 +26,13 @@ do(State, LibDirs) -> State1 = lists:foldl(fun(Profile, StateAcc) -> ProfileDeps = rebar_state:get(StateAcc, {deps, Profile}, []), ProfileDeps2 = rebar_utils:tup_dedup(rebar_utils:tup_sort(ProfileDeps)), + StateAcc1 = rebar_state:set(StateAcc, {deps, Profile}, ProfileDeps2), ParsedDeps = parse_profile_deps(Profile ,TopLevelApp ,ProfileDeps2 - ,StateAcc - ,StateAcc), - rebar_state:set(StateAcc, {parsed_deps, Profile}, ParsedDeps) + ,StateAcc1 + ,StateAcc1), + rebar_state:set(StateAcc1, {parsed_deps, Profile}, ParsedDeps) end, State, lists:reverse(CurrentProfiles)), %% Handle sub project apps deps @@ -109,7 +110,8 @@ handle_profile(Profile, Name, AppState, State) -> %% to be included in the parsed deps NewDeps = ProfileDeps2 -- TopLevelProfileDeps, ParsedDeps = parse_profile_deps(Profile, Name, NewDeps, AppState, State1), - rebar_state:set(State1, {parsed_deps, Profile}, TopParsedDeps++ParsedDeps). + State2 = rebar_state:set(State1, {deps, Profile}, ProfileDeps2), + rebar_state:set(State2, {parsed_deps, Profile}, TopParsedDeps++ParsedDeps). parse_profile_deps(Profile, Name, Deps, AppState, State) -> DepsDir = rebar_prv_install_deps:profile_dep_dir(State, Profile), diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl index 07c63f1..4f8eff5 100644 --- a/src/rebar_file_utils.erl +++ b/src/rebar_file_utils.erl @@ -27,6 +27,7 @@ -module(rebar_file_utils). -export([try_consult/1, + replace_home_dir/1, format_error/1, symlink_or_copy/2, rm_rf/1, @@ -59,6 +60,10 @@ try_consult(File) -> throw(?PRV_ERROR({bad_term_file, File, Reason})) end. +replace_home_dir(Dir) -> + HomeDir = rebar_dir:home_dir(), + re:replace(Dir, [$^ | HomeDir], "~", [{return, list}]). + format_error({bad_term_file, AppFile, Reason}) -> io_lib:format("Error reading file ~s: ~s", [AppFile, file:format_error(Reason)]). @@ -318,4 +323,3 @@ cp_r_win32(Source,Dest) -> ok = cp_r_win32({filelib:is_dir(Src), Src}, Dst) end, filelib:wildcard(Source)), ok. - diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl index 43df872..e3346ae 100644 --- a/src/rebar_packages.erl +++ b/src/rebar_packages.erl @@ -4,6 +4,7 @@ ,close_packages/0 ,load_and_verify_version/1 ,deps/3 + ,registry_dir/1 ,package_dir/1 ,registry_checksum/2 ,find_highest_matching/4 @@ -34,7 +35,7 @@ close_packages() -> catch ets:delete(?PACKAGE_TABLE). load_and_verify_version(State) -> - RegistryDir = package_dir(State), + RegistryDir = registry_dir(State), case ets:file2tab(filename:join(RegistryDir, ?INDEX_FILE)) of {ok, _} -> case ets:lookup_element(?PACKAGE_TABLE, package_index_version, 2) of @@ -57,13 +58,25 @@ deps(Name, Vsn, State) -> throw(?PRV_ERROR({missing_package, ec_cnv:to_binary(Name), ec_cnv:to_binary(Vsn)})) end. -package_dir(State) -> +registry_dir(State) -> CacheDir = rebar_dir:global_cache_dir(State), - CDN = rebar_state:get(State, rebar_packages_cdn, ?DEFAULT_CDN), - {ok, {_, _, Host, _, Path, _}} = http_uri:parse(CDN), - CDNHostPath = lists:reverse(string:tokens(Host, ".")), - CDNPath = tl(filename:split(Path)), - PackageDir = filename:join([CacheDir, "hex"] ++ CDNHostPath ++ CDNPath ++ ["packages"]), + case rebar_state:get(State, rebar_packages_cdn, ?DEFAULT_CDN) of + ?DEFAULT_CDN -> + RegistryDir = filename:join([CacheDir, "hex", "default"]), + ok = filelib:ensure_dir(filename:join(RegistryDir, "placeholder")), + RegistryDir; + CDN -> + {ok, {_, _, Host, _, Path, _}} = http_uri:parse(CDN), + CDNHostPath = lists:reverse(string:tokens(Host, ".")), + CDNPath = tl(filename:split(Path)), + RegistryDir = filename:join([CacheDir, "hex"] ++ CDNHostPath ++ CDNPath), + ok = filelib:ensure_dir(filename:join(RegistryDir, "placeholder")), + RegistryDir + end. + +package_dir(State) -> + RegistryDir = registry_dir(State), + PackageDir = filename:join([RegistryDir, "packages"]), ok = filelib:ensure_dir(filename:join(PackageDir, "placeholder")), PackageDir. diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index fcfb6f7..10faf4d 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -35,11 +35,11 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - ?INFO("Updating package index...", []), try - RegistryDir = rebar_packages:package_dir(State), + RegistryDir = rebar_packages:registry_dir(State), filelib:ensure_dir(filename:join(RegistryDir, "dummy")), HexFile = filename:join(RegistryDir, "registry"), + ?INFO("Updating package registry...", []), TmpDir = ec_file:insecure_mkdtemp(), TmpFile = filename:join(TmpDir, "packages.gz"), @@ -50,7 +50,7 @@ do(State) -> {ok, Data} = file:read_file(TmpFile), Unzipped = zlib:gunzip(Data), ok = file:write_file(HexFile, Unzipped), - + ?INFO("Writing registry to ~s", [rebar_file_utils:replace_home_dir(HexFile)]), hex_to_index(State), ok catch @@ -71,11 +71,13 @@ is_supported(<<"rebar3">>) -> true; is_supported(_) -> false. hex_to_index(State) -> - RegistryDir = rebar_packages:package_dir(State), + RegistryDir = rebar_packages:registry_dir(State), HexFile = filename:join(RegistryDir, "registry"), try ets:file2tab(HexFile) of {ok, Registry} -> try + PackageIndex = filename:join(RegistryDir, "packages.idx"), + ?INFO("Generating package index...", []), (catch ets:delete(?PACKAGE_TABLE)), ets:new(?PACKAGE_TABLE, [named_table, public]), ets:foldl(fun({{Pkg, PkgVsn}, [Deps, Checksum, BuildTools | _]}, _) when is_list(BuildTools) -> @@ -93,7 +95,8 @@ hex_to_index(State) -> end, true, Registry), ets:insert(?PACKAGE_TABLE, {package_index_version, ?PACKAGE_INDEX_VERSION}), - ets:tab2file(?PACKAGE_TABLE, filename:join(RegistryDir, "packages.idx")), + ?INFO("Writing index to ~s", [rebar_file_utils:replace_home_dir(PackageIndex)]), + ets:tab2file(?PACKAGE_TABLE, PackageIndex), true after catch ets:delete(Registry) diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 213eb2f..f365293 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -78,11 +78,7 @@ new() -> -spec new(list()) -> t(). new(Config) when is_list(Config) -> BaseState = base_state(), - Deps = proplists:get_value(deps, Config, []), - Plugins = proplists:get_value(plugins, Config, []), - Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins} | Config], - true = rebar_config:verify_config_format(Terms), - Opts = dict:from_list(Terms), + Opts = base_opts(Config), BaseState#state_t { dir = rebar_dir:get_cwd(), default = Opts, opts = Opts }. @@ -91,12 +87,7 @@ new(Config) when is_list(Config) -> new(Profile, Config) when is_atom(Profile) , is_list(Config) -> BaseState = base_state(), - Deps = proplists:get_value(deps, Config, []), - - Plugins = proplists:get_value(plugins, Config, []), - Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins} | Config], - true = rebar_config:verify_config_format(Terms), - Opts = dict:from_list(Terms), + Opts = base_opts(Config), BaseState#state_t { dir = rebar_dir:get_cwd(), current_profiles = [Profile], default = Opts, @@ -119,11 +110,7 @@ new(ParentState, Config, Dir) -> true = rebar_config:verify_config_format(Terms), dict:from_list(Terms); _ -> - D = proplists:get_value(deps, Config, []), - Plugins = proplists:get_value(plugins, Config, []), - Terms = [{{deps, default}, D}, {{plugins, default}, Plugins} | Config], - true = rebar_config:verify_config_format(Terms), - dict:from_list(Terms) + base_opts(Config) end, NewOpts = merge_opts(LocalOpts, Opts), @@ -141,6 +128,13 @@ base_state() -> end, #state_t{resources=Resources}. +base_opts(Config) -> + Deps = proplists:get_value(deps, Config, []), + Plugins = proplists:get_value(plugins, Config, []), + Terms = [{{deps, default}, Deps}, {{plugins, default}, Plugins} | Config], + true = rebar_config:verify_config_format(Terms), + dict:from_list(Terms). + get(State, Key) -> {ok, Value} = dict:find(Key, State#state_t.opts), Value. diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl index 3a9aa53..b0b7eda 100644 --- a/test/rebar_pkg_SUITE.erl +++ b/test/rebar_pkg_SUITE.erl @@ -183,6 +183,7 @@ mock_config(Name, Config) -> meck:expect(rebar_dir, global_cache_dir, fun(_) -> CacheRoot end), meck:new(rebar_packages, [passthrough]), + meck:expect(rebar_packages, registry_dir, fun(_) -> CacheDir end), meck:expect(rebar_packages, package_dir, fun(_) -> CacheDir end), rebar_prv_update:hex_to_index(rebar_state:new()), |