summaryrefslogtreecommitdiff
path: root/src/rebar_app_utils.erl
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2018-09-13 19:36:00 -0600
committerGitHub <noreply@github.com>2018-09-13 19:36:00 -0600
commit56b7d88975aa8da6446857cfd92de0825024bf63 (patch)
tree7e5b5de9b64b4b709775925c935bd20e4576457d /src/rebar_app_utils.erl
parent5e678754d7951a1700e2fcca4e1eb91ecc862e1a (diff)
support for hex v2, multiple repository fetching, private organizations (#1884)
* update to hex_core for hex-v2 repo support (#1865) * update to hex_core for hex-v2 repo support This patch adds only single repo hex-v2 support through hex_core. Packages no longer filtered out by buildtool metadata and the package index is updated per-package instead of fetched as one large ets dump. * tell travis to also build hex_core branch * support list of repos for hex packages (#1866) * support list of repos for hex packages repos are defined under the hex key in rebar configs. They can be defined at the top level of a project or globally, but not in profiles and the repos configured in dependencies are also ignored. Searching for packages involves first checking for a match in the local repo index cache, in the order repos are defined. If not found each repo is checked through the hex api for any known versions of the package and the first repo with a version that fits the constraint is used. * add {repos, replace, []} for overriding the global & default repos * add hex auth handling for repos (#1874) auth token are kept in a hex.config file that is modified by the rebar3 hex plugin. Repo names that have a : separating a parent and child are considered organizations. The parent repo's auth will be included with the child. So an organization named hexpm:rebar3_test will include any hexpm auth tokens found in the rebar3_test organization's configuration. * move packages to top level of of hexpm cache dir (#1876) * move packages to top level of of hexpm cache dir * append organization name to parent's repo_url when parsing repos * only eval config scripts and apply overrides once per app (#1879) * only eval config scripts and apply overrides once per app * move new resource behaviour to rebar_resource_v2 and keep v1 * cleanup use of rebar_resource module and unused functions * cleanup error messages and unused code * when discovering apps support mix packages as unbuilt apps (#1882) * use hex_core tarball unpacking support in pkg resource (#1883) * use hex_core tarball unpacking support in pkg resource * ignore etag if package doesn't exist and delete if checksum fails * add back tests for bad package checksums * improve bad registry checksum error message
Diffstat (limited to 'src/rebar_app_utils.erl')
-rw-r--r--src/rebar_app_utils.erl109
1 files changed, 39 insertions, 70 deletions
diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl
index 1d7ef5b..35e908c 100644
--- a/src/rebar_app_utils.erl
+++ b/src/rebar_app_utils.erl
@@ -217,26 +217,23 @@ parse_dep(_, Dep, _, _, _) ->
dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State) ->
CheckoutsDir = rebar_utils:to_list(rebar_dir:checkouts_dir(State, Name)),
AppInfo = case rebar_app_info:discover(CheckoutsDir) of
- {ok, App} ->
- rebar_app_info:source(rebar_app_info:is_checkout(App, true), checkout);
- not_found ->
- Dir = rebar_utils:to_list(filename:join(DepsDir, Name)),
- {ok, AppInfo0} =
- case rebar_app_info:discover(Dir) of
- {ok, App} ->
- {ok, rebar_app_info:parent(App, Parent)};
- not_found ->
- rebar_app_info:new(Parent, Name, Vsn, Dir, [])
- end,
- rebar_app_info:source(AppInfo0, Source)
- end,
- C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
- AppInfo1 = rebar_app_info:update_opts(AppInfo, rebar_app_info:opts(AppInfo), C),
- Overrides = rebar_state:get(State, overrides, []),
- AppInfo2 = rebar_app_info:set(AppInfo1, overrides, rebar_app_info:get(AppInfo, overrides, [])++Overrides),
- AppInfo3 = rebar_app_info:apply_overrides(rebar_app_info:get(AppInfo2, overrides, []), AppInfo2),
- AppInfo4 = rebar_app_info:apply_profiles(AppInfo3, [default, prod]),
- AppInfo5 = rebar_app_info:profiles(AppInfo4, [default]),
+ {ok, App} ->
+ rebar_app_info:source(rebar_app_info:is_checkout(App, true), checkout);
+ not_found ->
+ Dir = rebar_utils:to_list(filename:join(DepsDir, Name)),
+ {ok, AppInfo0} =
+ case rebar_app_info:discover(Dir) of
+ {ok, App} ->
+ {ok, rebar_app_info:is_available(rebar_app_info:parent(App, Parent),
+ true)};
+ not_found ->
+ rebar_app_info:new(Parent, Name, Vsn, Dir, [])
+ end,
+ rebar_app_info:source(AppInfo0, Source)
+ end,
+ Overrides = rebar_app_info:get(AppInfo, overrides, []) ++ rebar_state:get(State, overrides, []),
+ AppInfo2 = rebar_app_info:set(AppInfo, overrides, Overrides),
+ AppInfo5 = rebar_app_info:profiles(AppInfo2, [default]),
rebar_app_info:is_lock(AppInfo5, IsLock).
%% @doc Takes a given application app_info record along with the project.
@@ -250,52 +247,36 @@ expand_deps_sources(Dep, State) ->
%% around version if required.
-spec update_source(rebar_app_info:t(), Source, rebar_state:t()) ->
rebar_app_info:t() when
- Source :: tuple() | atom() | binary(). % TODO: meta to source()
+ Source :: rebar_resource_v2:source().
update_source(AppInfo, {pkg, PkgName, PkgVsn, Hash}, State) ->
- {PkgName1, PkgVsn1} = case PkgVsn of
- undefined ->
- get_package(PkgName, "0", State);
- <<"~>", Vsn/binary>> ->
- [Vsn1] = [X || X <- binary:split(Vsn, [<<" ">>], [global]), X =/= <<>>],
- get_package(PkgName, Vsn1, State);
- _ ->
- {PkgName, PkgVsn}
- end,
- %% store the expected hash for the dependency
- Hash1 = case Hash of
- undefined -> % unknown, define the hash since we know the dep
- fetch_checksum(PkgName1, PkgVsn1, Hash, State);
- _ -> % keep as is
- Hash
- end,
- AppInfo1 = rebar_app_info:source(AppInfo, {pkg, PkgName1, PkgVsn1, Hash1}),
- Deps = rebar_packages:deps(PkgName1
- ,PkgVsn1
- ,State),
- AppInfo2 = rebar_app_info:resource_type(rebar_app_info:deps(AppInfo1, Deps), pkg),
- rebar_app_info:original_vsn(AppInfo2, PkgVsn1);
+ case rebar_packages:resolve_version(PkgName, PkgVsn, Hash,
+ ?PACKAGE_TABLE, State) of
+ {ok, Package, RepoConfig} ->
+ #package{key={_, PkgVsn1, _},
+ checksum=Hash1,
+ dependencies=Deps} = Package,
+ AppInfo1 = rebar_app_info:source(AppInfo, {pkg, PkgName, PkgVsn1, Hash1, RepoConfig}),
+ AppInfo2 = rebar_app_info:update_opts_deps(AppInfo1, Deps),
+ rebar_app_info:original_vsn(AppInfo2, PkgVsn1);
+ not_found ->
+ throw(?PRV_ERROR({missing_package, PkgName, PkgVsn}));
+ {error, {invalid_vsn, InvalidVsn}} ->
+ throw(?PRV_ERROR({invalid_vsn, PkgName, InvalidVsn}))
+ end;
update_source(AppInfo, Source, _State) ->
rebar_app_info:source(AppInfo, Source).
-%% @doc grab the checksum for a given package
--spec fetch_checksum(atom(), string(), iodata() | undefined, rebar_state:t()) ->
- iodata() | no_return().
-fetch_checksum(PkgName, PkgVsn, Hash, State) ->
- try
- rebar_packages:registry_checksum({pkg, PkgName, PkgVsn, Hash}, State)
- catch
- _:_ ->
- ?INFO("Package ~ts-~ts not found. Fetching registry updates and trying again...", [PkgName, PkgVsn]),
- {ok, _} = rebar_prv_update:do(State),
- rebar_packages:registry_checksum({pkg, PkgName, PkgVsn, Hash}, State)
- end.
-
%% @doc convert a given exception's payload into an io description.
-spec format_error(any()) -> iolist().
-format_error({missing_package, Package}) ->
- io_lib:format("Package not found in registry: ~ts", [Package]);
+format_error({missing_package, Name, undefined}) ->
+ io_lib:format("Package not found in any repo: ~ts.", [rebar_utils:to_binary(Name)]);
+format_error({missing_package, Name, Vsn}) ->
+ io_lib:format("Package not found in any repo: ~ts-~ts.", [rebar_utils:to_binary(Name),
+ rebar_utils:to_binary(Vsn)]);
format_error({parse_dep, Dep}) ->
io_lib:format("Failed parsing dep ~p", [Dep]);
+format_error({invalid_vsn, Dep, InvalidVsn}) ->
+ io_lib:format("Dep ~ts has invalid version ~ts", [Dep, InvalidVsn]);
format_error(Error) ->
io_lib:format("~p", [Error]).
@@ -303,18 +284,6 @@ format_error(Error) ->
%% Internal functions
%% ===================================================================
-%% @private find the correct version of a package based on the version
-%% and name passed in.
--spec get_package(binary(), binary() | string(), rebar_state:t()) ->
- term() | no_return().
-get_package(Dep, Vsn, State) ->
- case rebar_packages:find_highest_matching(Dep, Vsn, ?PACKAGE_TABLE, State) of
- {ok, HighestDepVsn} ->
- {Dep, HighestDepVsn};
- none ->
- throw(?PRV_ERROR({missing_package, rebar_utils:to_binary(Dep)}))
- end.
-
%% @private checks that all the beam files have been properly
%% created.
-spec has_all_beams(file:filename_all(), [module()]) ->