summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar_app_info.erl10
-rw-r--r--src/rebar_packages.erl20
-rw-r--r--src/rebar_pkg_resource.erl2
-rw-r--r--src/rebar_state.erl6
-rw-r--r--src/rebar_utils.erl11
5 files changed, 32 insertions, 17 deletions
diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl
index b1c6243..9dfe278 100644
--- a/src/rebar_app_info.erl
+++ b/src/rebar_app_info.erl
@@ -124,14 +124,14 @@ new(AppName) ->
{ok, t()}.
new(AppName, Vsn) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName),
- original_vsn=rebar_utils:to_binary(Vsn)}}.
+ original_vsn=Vsn}}.
%% @doc build a complete version of the app info with all fields set.
-spec new(atom() | binary() | string(), binary() | string(), file:name()) ->
{ok, t()}.
new(AppName, Vsn, Dir) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName),
- original_vsn=rebar_utils:to_binary(Vsn),
+ original_vsn=Vsn,
dir=rebar_utils:to_list(Dir),
out_dir=rebar_utils:to_list(Dir),
ebin_dir=filename:join(rebar_utils:to_list(Dir), "ebin")}}.
@@ -141,7 +141,7 @@ new(AppName, Vsn, Dir) ->
{ok, t()}.
new(AppName, Vsn, Dir, Deps) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName),
- original_vsn=rebar_utils:to_binary(Vsn),
+ original_vsn=Vsn,
dir=rebar_utils:to_list(Dir),
out_dir=rebar_utils:to_list(Dir),
ebin_dir=filename:join(rebar_utils:to_list(Dir), "ebin"),
@@ -153,7 +153,7 @@ new(AppName, Vsn, Dir, Deps) ->
new(Parent, AppName, Vsn, Dir, Deps) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName),
parent=Parent,
- original_vsn=rebar_utils:to_binary(Vsn),
+ original_vsn=Vsn,
dir=rebar_utils:to_list(Dir),
out_dir=rebar_utils:to_list(Dir),
ebin_dir=filename:join(rebar_utils:to_list(Dir), "ebin"),
@@ -390,7 +390,7 @@ original_vsn(#app_info_t{original_vsn=Vsn}) ->
%% asking for a semver)
-spec original_vsn(t(), binary() | string()) -> t().
original_vsn(AppInfo=#app_info_t{}, Vsn) ->
- AppInfo#app_info_t{original_vsn=rebar_utils:to_binary(Vsn)}.
+ AppInfo#app_info_t{original_vsn=Vsn}.
%% @doc returns the list of applications the app depends on.
-spec applications(t()) -> list().
diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl
index 096948c..757eb86 100644
--- a/src/rebar_packages.erl
+++ b/src/rebar_packages.erl
@@ -55,11 +55,13 @@ get_all_names(State) ->
_='_'},
[], ['$1']}])).
--spec get_package_versions(unicode:unicode_binary(), unicode:unicode_binary(),
+-spec get_package_versions(unicode:unicode_binary(), ec_semver:semver(),
+ unicode:unicode_binary(),
ets:tid(), rebar_state:t()) -> [vsn()].
-get_package_versions(Dep, Repo, Table, State) ->
+get_package_versions(Dep, {_, AlphaInfo}, Repo, Table, State) ->
?MODULE:verify_table(State),
- AllowPreRelease = rebar_state:get(State, deps_allow_prerelease, false),
+ AllowPreRelease = rebar_state:get(State, deps_allow_prerelease, false)
+ orelse AlphaInfo =/= {[],[]},
ets:select(Table, [{#package{key={Dep, {'$1', '$2'}, Repo},
_='_'},
[{'==', '$2', {{[],[]}}} || not AllowPreRelease], [{{'$1', '$2'}}]}]).
@@ -180,7 +182,7 @@ find_highest_matching(Dep, Constraint, Repo, Table, State) ->
end.
find_highest_matching_(Dep, Constraint, #{name := Repo}, Table, State) ->
- try get_package_versions(Dep, Repo, Table, State) of
+ try get_package_versions(Dep, Constraint, Repo, Table, State) of
[Vsn] ->
handle_single_vsn(Vsn, Constraint);
Vsns ->
@@ -292,7 +294,7 @@ resolve_version(Dep, DepVsn, Hash, HexRegistry, State) when is_binary(Hash) ->
end;
resolve_version(Dep, undefined, Hash, HexRegistry, State) ->
Fun = fun(Repo) ->
- case highest_matching(Dep, "0", Repo, HexRegistry, State) of
+ case highest_matching(Dep, {0,{[],[]}}, Repo, HexRegistry, State) of
none ->
not_found;
{ok, Vsn} ->
@@ -360,9 +362,9 @@ resolve_version_(Dep, DepVsn, Repo, HexRegistry, State) ->
end.
rm_ws(<<" ", R/binary>>) ->
- rm_ws(R);
+ ec_semver:parse(rm_ws(R));
rm_ws(R) ->
- R.
+ ec_semver:parse(R).
valid_vsn(Vsn) ->
%% Regepx from https://github.com/sindresorhus/semver-regex/blob/master/index.js
@@ -375,7 +377,7 @@ highest_matching(Dep, Vsn, Repo, HexRegistry, State) ->
find_highest_matching_(Dep, Vsn, #{name => Repo}, HexRegistry, State).
cmp(Dep, Vsn, Repo, HexRegistry, State, CmpFun) ->
- case get_package_versions(Dep, Repo, HexRegistry, State) of
+ case get_package_versions(Dep, Vsn, Repo, HexRegistry, State) of
[] ->
none;
Vsns ->
@@ -398,7 +400,7 @@ cmp_(BestMatch, MinVsn, [Vsn | R], CmpFun) ->
%% We need to treat this differently since we want a version that is LOWER but
%% the higest possible one.
cmpl(Dep, Vsn, Repo, HexRegistry, State, CmpFun) ->
- case get_package_versions(Dep, Repo, HexRegistry, State) of
+ case get_package_versions(Dep, Vsn, Repo, HexRegistry, State) of
[] ->
none;
Vsns ->
diff --git a/src/rebar_pkg_resource.erl b/src/rebar_pkg_resource.erl
index 97eabb6..823b7fc 100644
--- a/src/rebar_pkg_resource.erl
+++ b/src/rebar_pkg_resource.erl
@@ -60,7 +60,7 @@ lock(AppInfo, _) ->
Res :: boolean().
needs_update(AppInfo, _) ->
{pkg, _Name, Vsn, _Hash, _} = rebar_app_info:source(AppInfo),
- case rebar_app_info:original_vsn(AppInfo) =:= rebar_utils:to_binary(Vsn) of
+ case rebar_utils:to_binary(rebar_app_info:original_vsn(AppInfo)) =:= rebar_utils:to_binary(Vsn) of
true ->
false;
false ->
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index c8a9400..31d3a08 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -43,7 +43,7 @@
project_builders/1, add_project_builder/3,
- create_resources/2,
+ create_resources/2, set_resources/2,
resources/1, resources/2, add_resource/2,
providers/1, providers/2, add_provider/2,
allow_provider_overrides/1, allow_provider_overrides/2
@@ -368,6 +368,10 @@ namespace(State=#state_t{}, Namespace) ->
resources(#state_t{resources=Resources}) ->
Resources.
+-spec set_resources(t(), [{rebar_resource_v2:type(), module()}]) -> t().
+set_resources(State, Resources) ->
+ State#state_t{resources=Resources}.
+
-spec resources(t(), [{rebar_resource_v2:type(), module()}]) -> t().
resources(State, NewResources) ->
lists:foldl(fun(Resource, StateAcc) ->
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 419802a..1769b79 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -715,6 +715,15 @@ escript_foldl(Fun, Acc, File) ->
Error
end.
+%% TODO: this is just for rebar3_hex and maybe other plugins
+%% but eventually it should be dropped
+vcs_vsn(OriginalVsn, Dir, Resources) when is_list(Dir) ,
+ is_list(Resources) ->
+ ?WARN("Using deprecated rebar_utils:vcs_vsn/3. Please upgrade your plugins.", []),
+ FakeState = rebar_state:new(),
+ {ok, AppInfo} = rebar_app_info:new(fake, OriginalVsn, Dir),
+ vcs_vsn(AppInfo, OriginalVsn,
+ rebar_state:set_resources(FakeState, Resources));
vcs_vsn(AppInfo, Vcs, State) ->
case vcs_vsn_cmd(AppInfo, Vcs, State) of
{plain, VsnString} ->
@@ -728,7 +737,7 @@ vcs_vsn(AppInfo, Vcs, State) ->
end.
%% Temp work around for repos like relx that use "semver"
-vcs_vsn_cmd(_AppInfo, Vsn, _) when is_binary(Vsn) ->
+vcs_vsn_cmd(_, Vsn, _) when is_binary(Vsn) ->
{plain, Vsn};
vcs_vsn_cmd(AppInfo, VCS, State) when VCS =:= semver ; VCS =:= "semver" ->
vcs_vsn_cmd(AppInfo, git, State);