From 99136c38b588beaa975f9b1d1895db4ee91f836e Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 23 Aug 2014 15:33:05 -0500 Subject: simplify dep download and building --- src/rebar_core.erl | 2 +- src/rebar_ct.erl | 4 ++-- src/rebar_prv_app_builder.erl | 28 +++++++++++++--------------- src/rebar_prv_deps.erl | 19 +++++++------------ src/rebar_prv_update.erl | 4 ++-- 5 files changed, 25 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index d4daff7..675b272 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -39,7 +39,7 @@ process_command(State, Command) -> LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS), DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIRS), _UpdatedCodePaths = update_code_path([DepsDir | LibDirs]), - rebar_deps:setup_env(State), + rebar_prv_deps:setup_env(State), TargetProviders = rebar_provider:get_target_providers(Command, State), diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl index 781f7da..abd29cc 100644 --- a/src/rebar_ct.erl +++ b/src/rebar_ct.erl @@ -225,7 +225,7 @@ make_cmd(TestDir, RawLogDir, State) -> %% that are part of the root Erlang install are filtered out to %% avoid duplication Apps = rebar_state:apps_to_build(State), - DepsDir = rebar_deps:get_deps_dir(State), + DepsDir = rebar_prv_deps:get_deps_dir(State), DepsDirEbin = filename:join([DepsDir, "*", "ebin"]), AppDirs = [filename:join(rebar_app_info:dir(A), "ebin") || A <- Apps], CodeDirs = [io_lib:format("\"~s\"", [Dir]) || Dir <- [DepsDirEbin | AppDirs]], @@ -311,7 +311,7 @@ get_cover_config(State, Cwd) -> end. collect_glob(State, Cwd, Glob) -> - DepsDir = rebar_deps:get_deps_dir(State), + DepsDir = rebar_prv_deps:get_deps_dir(State), CwdParts = filename:split(Cwd), filelib:fold_files(Cwd, Glob, true, fun(F, Acc) -> %% Ignore any specs under the deps/ directory. Do this pulling diff --git a/src/rebar_prv_app_builder.erl b/src/rebar_prv_app_builder.erl index 90de4fb..f9ba1c4 100644 --- a/src/rebar_prv_app_builder.erl +++ b/src/rebar_prv_app_builder.erl @@ -28,15 +28,14 @@ init(State) -> {ok, State1}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | relx:error(). -do(Config) -> - Apps = rebar_state:apps_to_build(Config), - Config1 = - lists:foldl(fun(AppInfo, ConfigAcc) -> - ?INFO("Compiling ~p ~s~n", [rebar_app_info:name(AppInfo) - ,rebar_app_info:original_vsn(AppInfo)]), - {_AppInfo1, ConfigAcc1} = build(ConfigAcc, AppInfo), - ConfigAcc1 - end, Config, Apps), +do(State) -> + Apps = rebar_state:apps_to_build(State), + + lists:foreach(fun(AppInfo) -> + ?INFO("Compiling ~p ~s~n", [rebar_app_info:name(AppInfo) + ,rebar_app_info:original_vsn(AppInfo)]), + _AppInfo1 = build(State, AppInfo) + end, Apps), %% DepsDir = get_deps_dir(Config1), %% LockDeps = lists:map(fun({Name, Vsn, Source}) -> @@ -44,13 +43,12 @@ do(Config) -> %% rebar_fetch:new(Dir, Name, Vsn, Source) %% end, rebar_state:deps(Config)), %% ok = file:write_file("./rebar.lock", io_lib:format("~p.~n", [LockDeps])), - {ok, Config1}. + {ok, State}. -build(Config, AppInfo) -> - {ok, AppInfo1} = rebar_otp_app:compile(Config, AppInfo), - Config1 = rebar_state:apps_to_build(Config, AppInfo1), - rebar_erlc_compiler:compile(Config, rebar_app_info:dir(AppInfo1)), - {AppInfo1, Config1}. +build(State, AppInfo) -> + {ok, AppInfo1} = rebar_otp_app:compile(State, AppInfo), + rebar_erlc_compiler:compile(State, rebar_app_info:dir(AppInfo1)), + AppInfo1. %% =================================================================== %% Internal functions diff --git a/src/rebar_prv_deps.erl b/src/rebar_prv_deps.erl index 0efc39d..7f487cf 100644 --- a/src/rebar_prv_deps.erl +++ b/src/rebar_prv_deps.erl @@ -144,7 +144,7 @@ download_missing_deps(State, DepsDir, Found, Unbuilt, Deps) -> to_binary(dep_name(X)) =:= to_binary(rebar_app_info:name(F)) end, Found++Unbuilt) end, Deps), - lists:foreach(fun({DepName, _DepVsn, DepSource}) -> + ec_plists:map(fun({DepName, _DepVsn, DepSource}) -> TargetDir = get_deps_dir(DepsDir, DepName), case filelib:is_dir(TargetDir) of true -> @@ -152,22 +152,17 @@ download_missing_deps(State, DepsDir, Found, Unbuilt, Deps) -> false -> ?INFO("Fetching ~s ~s~n", [element(1, DepSource) ,element(2, DepSource)]), - rebar_fetch:download_source(TargetDir, DepSource) - end - end, Missing), - - State1 = lists:foldl(fun(X, StateAcc) -> - TargetDir = get_deps_dir(DepsDir, dep_name(X)), + rebar_fetch:download_source(TargetDir, DepSource), case rebar_app_discover:find_unbuilt_apps([TargetDir]) of [AppSrc] -> - {_AppInfo1, StateAcc1} = rebar_prv_app_builder:build(StateAcc, AppSrc), - StateAcc1; + _AppInfo1 = rebar_prv_app_builder:build(State, AppSrc); [] -> - StateAcc + [] end - end, State, Missing), + end + end, Missing), - {State1, []}. + {State, []}. %% set REBAR_DEPS_DIR and ERL_LIBS environment variables setup_env(State) -> diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index c1aa14b..834e03f 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -35,10 +35,10 @@ do(State) -> [Name] -> ?INFO("Updating ~s~n", [Name]), - DepsDir = rebar_deps:get_deps_dir(State), + DepsDir = rebar_prv_deps:get_deps_dir(State), Deps = rebar_state:get_local(State, deps, []), {_, _, Source} = lists:keyfind(list_to_atom(Name), 1, Deps), - TargetDir = rebar_deps:get_deps_dir(DepsDir, Name), + TargetDir = rebar_prv_deps:get_deps_dir(DepsDir, Name), rebar_fetch:update_source1(TargetDir, Source), [App] = rebar_app_discover:find_apps([TargetDir]), -- cgit v1.1