diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_app_discover.erl | 2 | ||||
-rw-r--r-- | src/rebar_app_info.erl | 17 | ||||
-rw-r--r-- | src/rebar_packages.erl | 10 | ||||
-rw-r--r-- | src/rebar_prv_do.erl | 5 | ||||
-rw-r--r-- | src/rebar_prv_help.erl | 2 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 30 | ||||
-rw-r--r-- | src/rebar_state.erl | 3 | ||||
-rw-r--r-- | src/rebar_topo.erl | 14 |
8 files changed, 39 insertions, 44 deletions
diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index a51252e..ae4916e 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -48,9 +48,11 @@ app_dirs(LibDir) -> find_unbuilt_apps(LibDirs) -> find_apps(LibDirs, invalid). +-spec find_apps([file:filename_all()]) -> [rebar_app_info:t()]. find_apps(LibDirs) -> find_apps(LibDirs, valid). +-spec find_apps([file:filename_all()], valid | invalid | all) -> [rebar_app_info:t()]. find_apps(LibDirs, Validate) -> rebar_utils:filtermap(fun(AppDir) -> find_app(AppDir, Validate) diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index ac668e2..7a33811 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -1,7 +1,6 @@ -module(rebar_app_info). --export([new/0, - new/1, +-export([new/1, new/2, new/3, new/4, @@ -36,7 +35,7 @@ app_file_src :: file:filename_all() | undefined, app_file :: file:filename_all() | undefined, config :: rebar_state:t() | undefined, - original_vsn :: string() | undefined, + original_vsn :: binary() | string() | undefined, app_details=[] :: list(), deps=[] :: list(), dep_level :: integer(), @@ -54,23 +53,19 @@ %% ============================================================================ %% @doc Build a new, empty, app info value. This is not of a lot of use and you %% probably wont be doing this much. --spec new() -> {ok, t()}. -new() -> - {ok, #app_info_t{}}. - -spec new(atom() | binary() | string()) -> {ok, t()}. new(AppName) -> {ok, #app_info_t{name=ec_cnv:to_binary(AppName)}}. --spec new(atom() | binary() | string(), string()) -> +-spec new(atom() | binary() | string(), binary() | string()) -> {ok, t()}. new(AppName, Vsn) -> {ok, #app_info_t{name=ec_cnv:to_binary(AppName), original_vsn=Vsn}}. %% @doc build a complete version of the app info with all fields set. --spec new(atom() | binary() | string(), string(), file:name()) -> +-spec new(atom() | binary() | string(), binary() | string(), file:name()) -> {ok, t()}. new(AppName, Vsn, Dir) -> {ok, #app_info_t{name=ec_cnv:to_binary(AppName), @@ -78,7 +73,7 @@ new(AppName, Vsn, Dir) -> dir=Dir}}. %% @doc build a complete version of the app info with all fields set. --spec new(atom() | binary() | string(), string(), file:name(), list()) -> +-spec new(atom() | binary() | string(), binary() | string(), file:name(), list()) -> {ok, t()}. new(AppName, Vsn, Dir, Deps) -> {ok, #app_info_t{name=ec_cnv:to_binary(AppName), @@ -96,7 +91,7 @@ discover(Dir) -> not_found end. --spec name(t()) -> atom(). +-spec name(t()) -> binary(). name(#app_info_t{name=Name}) -> Name. diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl index b3a7542..cd979fa 100644 --- a/src/rebar_packages.erl +++ b/src/rebar_packages.erl @@ -4,7 +4,7 @@ -include("rebar.hrl"). --spec get_packages(rebar_state:t()) -> {rebar_dict(), tuple()}. +-spec get_packages(rebar_state:t()) -> {rebar_dict(), rlx_depsolver:t()}. get_packages(State) -> RebarDir = rebar_state:get(State, global_rebar_dir, filename:join(os:getenv("HOME"), ".rebar")), PackagesFile = filename:join(RebarDir, "packages"), @@ -12,13 +12,13 @@ get_packages(State) -> true -> try {ok, Binary} = file:read_file(PackagesFile), - {List, Graph} = binary_to_term(Binary), - {List, Graph} + {Dict, Graph} = binary_to_term(Binary), + {Dict, Graph} catch _:_ -> ?ERROR("Bad packages index, try to fix with `rebar update`~n", []), - {[], rlx_depsolver:new_graph()} + {dict:new(), rlx_depsolver:new_graph()} end; false -> - {[], rlx_depsolver:new_graph()} + {dict:new(), rlx_depsolver:new_graph()} end. diff --git a/src/rebar_prv_do.erl b/src/rebar_prv_do.erl index c8f383d..5f6e751 100644 --- a/src/rebar_prv_do.erl +++ b/src/rebar_prv_do.erl @@ -32,14 +32,13 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> Tasks = args_to_tasks(rebar_state:command_args(State)), - State1 = lists:foldl(fun(TaskArgs, {ok, StateAcc}) -> + lists:foldl(fun(TaskArgs, {ok, StateAcc}) -> [TaskStr | Args] = string:tokens(TaskArgs, " "), Task = list_to_atom(TaskStr), StateAcc1 = rebar_state:set(StateAcc, task, Task), StateAcc2 = rebar_state:command_args(StateAcc1, Args), rebar_core:process_command(StateAcc2, Task) - end, {ok, State}, Tasks), - {ok, State1}. + end, {ok, State}, Tasks). args_to_tasks(Args) -> [string:strip(T) || T <- string:tokens(string:join(Args, " "), ",")]. diff --git a/src/rebar_prv_help.erl b/src/rebar_prv_help.erl index 690ca7d..c2e1cd7 100644 --- a/src/rebar_prv_help.erl +++ b/src/rebar_prv_help.erl @@ -41,7 +41,7 @@ do(State) -> Name -> Providers = rebar_state:providers(State), case providers:get_provider(list_to_atom(Name), Providers) of - [] -> + not_found -> {error, io_lib:format("Unknown task ~s", [Name])}; Provider -> providers:help(Provider), diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 654a5fb..d752fb9 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -96,7 +96,7 @@ get_deps_dir(DepsDir, App) -> handle_deps(State, Deps) -> handle_deps(State, Deps, false). --spec handle_deps(rebar_state:t(), [dep()], false | {true, integer()}) -> {ok, rebar_state:t()}. +-spec handle_deps(rebar_state:t(), [dep()], boolean() | {true, binary(), integer()}) -> {ok, rebar_state:t()}. handle_deps(State, [], _) -> {ok, State}; handle_deps(State, Deps, Update) -> @@ -113,7 +113,7 @@ handle_deps(State, Deps, Update) -> State2 = update_src_deps(0, State1, Update), Solved = case rebar_state:pkg_deps(State2) of [] -> %% No pkg deps - []; + []; PkgDeps1 -> %% Find pkg deps needed {ok, S} = rlx_depsolver:solve(Graph, PkgDeps1), @@ -123,7 +123,6 @@ handle_deps(State, Deps, Update) -> ,Packages ,Pkg), maybe_fetch(AppInfo, Update)] - end, AllDeps = lists:ukeymerge(2 @@ -137,20 +136,21 @@ handle_deps(State, Deps, Update) -> %% Internal functions %% =================================================================== --spec package_to_app(file:filename_all(), rebar_dict(), - rlx_depsolver:pkg()) -> [rebar_app_info:t()]. +%-spec package_to_app(any(), ) -> []. % [rebar_app_info:t()]. package_to_app(DepsDir, Packages, Pkg={_, Vsn}) -> Name = ec_cnv:to_binary(rlx_depsolver:dep_pkg(Pkg)), FmtVsn = iolist_to_binary(rlx_depsolver:format_version(Vsn)), - {ok, P} = dict:find({Name, FmtVsn}, Packages), - PkgDeps = proplists:get_value(<<"deps">>, P), - Link = proplists:get_value(<<"link">>, P), - - {ok, AppInfo} = rebar_app_info:new(Name, FmtVsn), - AppInfo1 = rebar_app_info:deps(AppInfo, PkgDeps), - AppInfo2 = - rebar_app_info:dir(AppInfo1, get_deps_dir(DepsDir, Name)), - [rebar_app_info:source(AppInfo2, Link)]. + case dict:find({Name, FmtVsn}, Packages) of + error -> + []; + {ok, P} -> + PkgDeps = proplists:get_value(<<"deps">>, P, []), + Link = proplists:get_value(<<"link">>, P, ""), + {ok, AppInfo} = rebar_app_info:new(Name, FmtVsn), + AppInfo1 = rebar_app_info:deps(AppInfo, PkgDeps), + AppInfo2 = rebar_app_info:dir(AppInfo1, get_deps_dir(DepsDir, Name)), + [rebar_app_info:source(AppInfo2, Link)] + end. -spec update_src_deps(integer(), rebar_state:t(), boolean()) -> rebar_state:t(). update_src_deps(Level, State, Update) -> @@ -216,7 +216,7 @@ handle_dep(DepsDir, AppInfo) -> {SrcDeps, PkgDeps} = parse_deps(DepsDir, Deps), {AppInfo1, SrcDeps, PkgDeps}. --spec maybe_fetch(rebar_app_info:t(), boolean()) -> boolean(). +-spec maybe_fetch(rebar_app_info:t(), boolean() | {true, binary(), integer()}) -> boolean(). maybe_fetch(AppInfo, Update) -> AppDir = ec_cnv:to_list(rebar_app_info:dir(AppInfo)), Apps = rebar_app_discover:find_apps(["_checkouts"], all), diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 2d9266a..130f08d 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -28,7 +28,7 @@ src_deps = [], src_apps = [], - pkg_deps = [], + pkg_deps = [] :: [rlx_depsolver:constraint()], project_apps = [], providers = []}). @@ -103,6 +103,7 @@ deps_names(State) -> ec_cnv:to_binary(Dep) end, Deps). +-spec pkg_deps(t()) -> [rlx_depsolver:constraint()]. pkg_deps(#state_t{pkg_deps=PkgDeps}) -> PkgDeps. diff --git a/src/rebar_topo.erl b/src/rebar_topo.erl index e4a3e26..26ebbc4 100644 --- a/src/rebar_topo.erl +++ b/src/rebar_topo.erl @@ -94,7 +94,7 @@ names_to_apps(Names, Apps) -> -spec find_app_by_name(atom(), [rebar_app_info:t()]) -> {ok, rebar_app_info:t()} | error. find_app_by_name(Name, Apps) -> ec_lists:find(fun(App) -> - rebar_app_info:name(App) =:= Name + ec_cnv:to_atom(rebar_app_info:name(App)) =:= ec_cnv:to_atom(Name) end, Apps). -spec apps_to_pairs([rebar_app_info:t()]) -> [pair()]. @@ -103,20 +103,20 @@ apps_to_pairs(Apps) -> -spec app_to_pairs(rebar_app_info:t()) -> [pair()]. app_to_pairs(App) -> - [{ec_cnv:to_binary(DepApp), rebar_app_info:name(App)} || + [{ec_cnv:to_atom(DepApp), ec_cnv:to_atom(rebar_app_info:name(App))} || DepApp <- rebar_app_info:deps(App)]. %% @doc Iterate over the system. @private -spec iterate([pair()], [name()], [name()]) -> - {ok, [name()]} | relx:error(). + {ok, [name()]} | {error, iolist()}. iterate([], L, All) -> {ok, remove_duplicates(L ++ subtract(All, L))}; iterate(Pairs, L, All) -> case subtract(lhs(Pairs), rhs(Pairs)) of [] -> - format_error({cycle, Pairs}); + {error, format_error({cycle, Pairs})}; Lhs -> iterate(remove_pairs(Lhs, Pairs), L ++ Lhs, All) end. @@ -186,15 +186,13 @@ topo_2_test() -> topo_pairs_cycle_test() -> Pairs = [{app2, app1}, {app1, app2}, {stdlib, app1}], - ?assertMatch({error, {_, {cycle, [{app2, app1}, {app1, app2}]}}}, - sort(Pairs)). + ?assertMatch({error, _}, sort(Pairs)). topo_apps_cycle_test() -> {ok, App1} = rebar_app_info:new(app1, "0.1", "/no-dir", [app2]), {ok, App2} = rebar_app_info:new(app2, "0.1", "/no-dir", [app1]), Apps = [App1, App2], - ?assertMatch({error, {_, {cycle, [{app2,app1},{app1,app2}]}}}, - sort_apps(Apps)). + ?assertMatch({error, _}, sort_apps(Apps)). topo_apps_good_test() -> Apps = [App || |