summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar_prv_packages.erl32
-rw-r--r--src/rebar_prv_path.erl8
-rw-r--r--src/rebar_prv_shell.erl18
3 files changed, 43 insertions, 15 deletions
diff --git a/src/rebar_prv_packages.erl b/src/rebar_prv_packages.erl
index 998320c..7217ab8 100644
--- a/src/rebar_prv_packages.erl
+++ b/src/rebar_prv_packages.erl
@@ -28,22 +28,19 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
rebar_packages:packages(State),
- print_packages(),
+ case rebar_state:command_args(State) of
+ [Name] ->
+ print_packages(get_packages(iolist_to_binary(Name)));
+ _ ->
+ print_packages(sort_packages())
+ end,
{ok, State}.
-spec format_error(any()) -> iolist().
format_error(load_registry_fail) ->
"Failed to load package regsitry. Try running 'rebar3 update' to fix".
-print_packages() ->
- SortedPkgs = ets:foldl(fun({package_index_version, _}, Acc) ->
- Acc;
- ({Pkg, Vsns}, Acc) ->
- orddict:store(Pkg, Vsns, Acc);
- (_, Acc) ->
- Acc
- end, orddict:new(), ?PACKAGE_TABLE),
-
+print_packages(Pkgs) ->
orddict:map(fun(Name, Vsns) ->
SortedVsns = lists:sort(fun(A, B) ->
ec_semver:lte(ec_semver:parse(A)
@@ -51,7 +48,20 @@ print_packages() ->
end, Vsns),
VsnStr = join(SortedVsns, <<", ">>),
?CONSOLE("~s:~n Versions: ~s~n", [Name, VsnStr])
- end, SortedPkgs).
+ end, Pkgs).
+
+sort_packages() ->
+ ets:foldl(fun({package_index_version, _}, Acc) ->
+ Acc;
+ ({Pkg, Vsns}, Acc) ->
+ orddict:store(Pkg, Vsns, Acc);
+ (_, Acc) ->
+ Acc
+ end, orddict:new(), ?PACKAGE_TABLE).
+
+get_packages(Name) ->
+ ets:lookup(?PACKAGE_TABLE, Name).
+
-spec join([binary()], binary()) -> binary().
join([Bin], _Sep) ->
diff --git a/src/rebar_prv_path.erl b/src/rebar_prv_path.erl
index 37c9834..4e88496 100644
--- a/src/rebar_prv_path.erl
+++ b/src/rebar_prv_path.erl
@@ -95,10 +95,14 @@ print_paths_if_exist(Paths, State) ->
project_deps(State) ->
Profiles = rebar_state:current_profiles(State),
- List = lists:foldl(fun(Profile, Acc) -> rebar_state:get(State, {deps, Profile}, []) ++ Acc end, [], Profiles),
- Deps = [normalize(Name) || {Name, _} <- List],
+ DepList = lists:foldl(fun(Profile, Acc) -> rebar_state:get(State, {deps, Profile}, []) ++ Acc end, [], Profiles),
+ LockList = lists:foldl(fun(Profile, Acc) -> rebar_state:get(State, {locks, Profile}, []) ++ Acc end, [], Profiles),
+ Deps = [normalize(name(Dep)) || Dep <- DepList++LockList],
lists:usort(Deps).
+name(App) when is_tuple(App) -> element(1, App);
+name(Name) when is_binary(Name); is_list(Name); is_atom(Name) -> Name.
+
normalize(AppName) when is_list(AppName) -> AppName;
normalize(AppName) when is_atom(AppName) -> atom_to_list(AppName);
normalize(AppName) when is_binary(AppName) -> binary_to_list(AppName).
diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl
index 430d1e8..d67f940 100644
--- a/src/rebar_prv_shell.erl
+++ b/src/rebar_prv_shell.erl
@@ -133,11 +133,25 @@ kill_old_user() ->
%% fully die
[P] = [P || P <- element(2,process_info(whereis(user), links)), is_port(P)],
user ! {'EXIT', P, normal}, % pretend the port died, then the port can die!
+ exit(P, kill),
+ wait_for_port_death(1000, P),
OldUser.
+wait_for_port_death(N, _) when N < 0 ->
+ %% This risks displaying a warning!
+ whatever;
+wait_for_port_death(N, P) ->
+ case erlang:port_info(P) of
+ undefined ->
+ ok;
+ _ ->
+ timer:sleep(10),
+ wait_for_port_death(N-10, P)
+ end.
+
setup_new_shell() ->
- %% terminate the current user supervision structure
- ok = supervisor:terminate_child(kernel_sup, user),
+ %% terminate the current user supervision structure, if any
+ _ = supervisor:terminate_child(kernel_sup, user),
%% start a new shell (this also starts a new user under the correct group)
_ = user_drv:start(),
%% wait until user_drv and user have been registered (max 3 seconds)