From 52fcf0278d0e603f04a6b6181a61c84af1eebe5e Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 19 Sep 2014 18:54:22 -0500 Subject: add rebar providers create and plugin inclusion with providers --- src/rebar3.erl | 4 +++- src/rebar_provider.erl | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/rebar3.erl b/src/rebar3.erl index dcd78f7..ec464fb 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -136,10 +136,12 @@ run_aux(State, Args) -> State1 = init_config1(State), + code:add_pathsa([filename:join(rebar_utils:get_cwd(), "plugins")]), %% Process each command, resetting any state between each one State2 = rebar_state:set(State1, base_dir, filename:absname(rebar_state:dir(State1))), {ok, Providers} = application:get_env(rebar, providers), - State3 = rebar_state:create_logic_providers(Providers, State2), + Plugins = rebar_state:get(State2, plugins, []), + State3 = rebar_state:create_logic_providers(Providers++Plugins, State2), Task = rebar_state:get(State3, task, "help"), rebar_core:process_command(rebar_state:command_args(State3, Args), list_to_atom(Task)), ok. diff --git a/src/rebar_provider.erl b/src/rebar_provider.erl index e5d7520..69ee22b 100644 --- a/src/rebar_provider.erl +++ b/src/rebar_provider.erl @@ -1,7 +1,8 @@ -module(rebar_provider). %% API --export([new/2, +-export([create/1, + new/2, do/2, impl/1, get_provider/2, @@ -59,6 +60,17 @@ new(ModuleName, State0) when is_atom(ModuleName) -> ModuleName:init(State0) end. +-spec create([{atom(), any()}]) -> t(). +create(Attrs) -> + #provider{name=proplists:get_value(name, Attrs, undefined) + ,provider_impl=proplists:get_value(provider_impl, Attrs, undefined) + ,bare=proplists:get_value(bare, Attrs, false) + ,deps=proplists:get_value(deps, Attrs, []) + ,desc=proplists:get_value(desc, Attrs, "") + ,short_desc=proplists:get_value(short_desc, Attrs, "") + ,example=proplists:get_value(example, Attrs, "") + ,opts=proplists:get_value(opts, Attrs, [])}. + %% @doc Manipulate the state of the system, that new state %% %% @param Provider the provider object @@ -109,7 +121,7 @@ get_target_providers(Target, State) -> Providers = rebar_state:providers(State), TargetProviders = lists:filter(fun(#provider{name=T}) when T =:= Target-> true; - (#provider{name=T}) -> + (_) -> false end, Providers), process_deps(TargetProviders, Providers). -- cgit v1.1 From f4f96a356fcefaa2ad388eb5469c7da901846f21 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 19 Sep 2014 22:05:40 -0500 Subject: install plugins to plugins/ --- src/rebar3.erl | 5 +++-- src/rebar_plugins.erl | 9 ++++++++- src/rebar_prv_install_deps.erl | 36 +++++++++++++++++++++--------------- 3 files changed, 32 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/rebar3.erl b/src/rebar3.erl index ec464fb..39babeb 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -140,8 +140,9 @@ run_aux(State, Args) -> %% Process each command, resetting any state between each one State2 = rebar_state:set(State1, base_dir, filename:absname(rebar_state:dir(State1))), {ok, Providers} = application:get_env(rebar, providers), - Plugins = rebar_state:get(State2, plugins, []), - State3 = rebar_state:create_logic_providers(Providers++Plugins, State2), + + rebar_plugins:install(State2), + State3 = rebar_state:create_logic_providers(Providers, State2), Task = rebar_state:get(State3, task, "help"), rebar_core:process_command(rebar_state:command_args(State3, Args), list_to_atom(Task)), ok. diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index 0fdbc6d..e9ab0b2 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -3,10 +3,17 @@ -module(rebar_plugins). --export([]). +-export([install/1]). -include("rebar.hrl"). %% =================================================================== %% Public API %% =================================================================== + +install(State) -> + BaseDir = rebar_state:get(State, base_dir, ""), + State1 = rebar_state:set(State, base_dir, "plugins"), + Plugins = rebar_state:get(State1, plugins, []), + {ok, State2} = rebar_prv_install_deps:handle_deps(State1, Plugins), + {ok, rebar_state:set(State2, base_dir, BaseDir)}. diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index d20f2b5..0752f0a 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -33,7 +33,8 @@ -include("rebar.hrl"). --export([setup_env/1]). +-export([setup_env/1, + handle_deps/2]). %% for internal use only -export([get_deps_dir/1]). @@ -65,12 +66,18 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()}. do(State) -> - case rebar_state:get(State, locks, []) of - [] -> - handle_deps(State, ordsets:from_list(rebar_state:get(State, deps, []))); - Locks -> - handle_deps(State, ordsets:from_list(Locks)) - end. + ProjectApps = rebar_state:project_apps(State), + {ok, State1} = case rebar_state:get(State, locks, []) of + [] -> + handle_deps(State, ordsets:from_list(rebar_state:get(State, deps, []))); + Locks -> + handle_deps(State, ordsets:from_list(Locks)) + end, + + Source = ProjectApps ++ ordsets:to_list(rebar_state:src_deps(State1)), + {ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(Source)), + {ok, rebar_state:set(State1, deps_to_build, lists:dropwhile(fun is_valid/1, Sort -- ProjectApps))}. + %% set REBAR_DEPS_DIR and ERL_LIBS environment variables setup_env(State) -> @@ -99,17 +106,12 @@ get_deps_dir(State) -> get_deps_dir(DepsDir, App) -> filename:join(DepsDir, App). -%% =================================================================== -%% Internal functions -%% =================================================================== - -spec handle_deps(rebar_state:t(), [dep()]) -> {ok, rebar_state:t()}. handle_deps(State, []) -> {ok, State}; handle_deps(State, Deps) -> %% Read in package index and dep graph {Packages, Graph} = rebar_packages:get_packages(State), - ProjectApps = rebar_state:project_apps(State), %% Split source deps form binary deps, needed to keep backwards compatibility DepsDir = get_deps_dir(State), @@ -136,14 +138,18 @@ handle_deps(State, Deps) -> end, S) end, - Source = ProjectApps ++ ordsets:to_list(rebar_state:src_deps(State2)), AllDeps = ordsets:union([ordsets:to_list(rebar_state:src_deps(State2)) ,ordsets:from_list(Solved)]), %% Sort all apps to build order State3 = rebar_state:set(State2, all_deps, AllDeps), - {ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(Source)), - {ok, rebar_state:set(State3, deps_to_build, lists:dropwhile(fun is_valid/1, Sort -- ProjectApps))}. + + {ok, State3}. + + +%% =================================================================== +%% Internal functions +%% =================================================================== -spec is_valid(rebar_app_info:t()) -> boolean(). is_valid(App) -> -- cgit v1.1 From 989a1bfe8d991846f81331a94eb65ffc10883cf5 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 08:20:05 -0500 Subject: add plugin template --- src/rebar_core.erl | 3 ++- src/rebar_templater.erl | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index cb021e3..ce3816d 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -35,7 +35,8 @@ 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_prv_install_deps:setup_env(State), + + %% ? rebar_prv_install_deps:setup_env(State), TargetProviders = rebar_provider:get_target_providers(Command, State), diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index a795b66..048991b 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -47,6 +47,8 @@ new(app, DirName, State) -> create1(State, DirName, "otp_app"); new(lib, DirName, State) -> create1(State, DirName, "otp_lib"); +new(plugin, DirName, State) -> + create1(State, DirName, "plugin"); new(rel, DirName, State) -> create1(State, DirName, "otp_rel"). -- cgit v1.1 From 51f1cf4aae5a22fe8974edcdf10da4e8a7b05255 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 09:01:03 -0500 Subject: install plugins to plugins/ --- src/rebar3.erl | 10 ++++++---- src/rebar_core.erl | 20 ++++++++++++-------- src/rebar_plugins.erl | 24 +++++++++++++++++++++--- src/rebar_prv_install_deps.erl | 27 ++++----------------------- 4 files changed, 43 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/rebar3.erl b/src/rebar3.erl index 39babeb..44d7d98 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -141,10 +141,12 @@ run_aux(State, Args) -> State2 = rebar_state:set(State1, base_dir, filename:absname(rebar_state:dir(State1))), {ok, Providers} = application:get_env(rebar, providers), - rebar_plugins:install(State2), - State3 = rebar_state:create_logic_providers(Providers, State2), - Task = rebar_state:get(State3, task, "help"), - rebar_core:process_command(rebar_state:command_args(State3, Args), list_to_atom(Task)), + {ok, PluginProviders, State3} = rebar_plugins:install(State2), + rebar_core:update_code_path(State), + + State4 = rebar_state:create_logic_providers(Providers++PluginProviders, State3), + Task = rebar_state:get(State4, task, "help"), + rebar_core:process_command(rebar_state:command_args(State4, Args), list_to_atom(Task)), ok. %% diff --git a/src/rebar_core.erl b/src/rebar_core.erl index ce3816d..24b376f 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -26,16 +26,12 @@ %% ------------------------------------------------------------------- -module(rebar_core). --export([process_command/2]). +-export([process_command/2 + ,update_code_path/1]). -include("rebar.hrl"). process_command(State, Command) -> - true = rebar_utils:expand_code_path(), - 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_prv_install_deps:setup_env(State), TargetProviders = rebar_provider:get_target_providers(Command, State), @@ -47,13 +43,21 @@ process_command(State, Command) -> Conf1 end, State, TargetProviders). +update_code_path(State) -> + true = rebar_utils:expand_code_path(), + LibDirs = rebar_state:get(State, lib_dirs, ?DEFAULT_LIB_DIRS), + DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR), + PluginsDir = rebar_state:get(State, plugins_dir, ?DEFAULT_PLUGINS_DIR), + _UpdatedCodePaths = update_code_path_([DepsDir, PluginsDir | LibDirs]). + + %% =================================================================== %% Internal functions %% =================================================================== -update_code_path([]) -> +update_code_path_([]) -> no_change; -update_code_path(Paths) -> +update_code_path_(Paths) -> LibPaths = expand_lib_dirs(Paths, rebar_utils:get_cwd(), []), ok = code:add_pathsa(LibPaths), %% track just the paths we added, so we can remove them without diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index e9ab0b2..3e51f7f 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -12,8 +12,26 @@ %% =================================================================== install(State) -> - BaseDir = rebar_state:get(State, base_dir, ""), - State1 = rebar_state:set(State, base_dir, "plugins"), + State1 = rebar_state:set(State, deps_dir, "plugins"), + Plugins = rebar_state:get(State1, plugins, []), {ok, State2} = rebar_prv_install_deps:handle_deps(State1, Plugins), - {ok, rebar_state:set(State2, base_dir, BaseDir)}. + + Apps = rebar_state:get(State2, all_deps), + lists:foreach(fun(AppInfo) -> + C = rebar_config:consult(rebar_app_info:dir(AppInfo)), + S = rebar_state:new(rebar_state:new(), C, rebar_app_info:dir(AppInfo)), + rebar_prv_compile:build(S, AppInfo) + end, Apps), + + PluginProviders = plugin_providers(Plugins), + {ok, PluginProviders, rebar_state:set(State2, deps_dir, ?DEFAULT_DEPS_DIR)}. + +plugin_providers(Plugins) -> + lists:map(fun({Plugin, _, _}) when is_atom(Plugin) -> + Plugin; + ({Plugin, _}) when is_atom(Plugin) -> + Plugin; + (Plugin) when is_atom(Plugin) -> + Plugin + end, Plugins). diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 0752f0a..81acf22 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -33,8 +33,7 @@ -include("rebar.hrl"). --export([setup_env/1, - handle_deps/2]). +-export([handle_deps/2]). %% for internal use only -export([get_deps_dir/1]). @@ -78,29 +77,11 @@ do(State) -> {ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(Source)), {ok, rebar_state:set(State1, deps_to_build, lists:dropwhile(fun is_valid/1, Sort -- ProjectApps))}. - -%% set REBAR_DEPS_DIR and ERL_LIBS environment variables -setup_env(State) -> - DepsDir = get_deps_dir(State), - %% include rebar's DepsDir in ERL_LIBS - Separator = case os:type() of - {win32, nt} -> - ";"; - _ -> - ":" - end, - ERL_LIBS = case os:getenv("ERL_LIBS") of - false -> - {"ERL_LIBS", DepsDir}; - PrevValue -> - {"ERL_LIBS", DepsDir ++ Separator ++ PrevValue} - end, - [{"REBAR_DEPS_DIR", DepsDir}, ERL_LIBS]. - -spec get_deps_dir(rebar_state:t()) -> file:filename_all(). get_deps_dir(State) -> BaseDir = rebar_state:get(State, base_dir, ""), - get_deps_dir(BaseDir, "deps"). + DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR), + get_deps_dir(BaseDir, DepsDir). -spec get_deps_dir(file:filename_all(), rebar_state:t()) -> file:filename_all(). get_deps_dir(DepsDir, App) -> @@ -113,7 +94,7 @@ handle_deps(State, Deps) -> %% Read in package index and dep graph {Packages, Graph} = rebar_packages:get_packages(State), - %% Split source deps form binary deps, needed to keep backwards compatibility + %% Split source deps from binary deps, needed to keep backwards compatibility DepsDir = get_deps_dir(State), {SrcDeps, BinaryDeps} = parse_deps(DepsDir, Deps), State1 = rebar_state:src_deps(rebar_state:binary_deps(State, BinaryDeps), -- cgit v1.1 From 6f9ea13dd423d7ff0307265140496fb36c62d924 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 09:08:24 -0500 Subject: move deps and plugins to _ prefixed --- src/rebar_plugins.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index 3e51f7f..d8422d8 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -12,7 +12,7 @@ %% =================================================================== install(State) -> - State1 = rebar_state:set(State, deps_dir, "plugins"), + State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR), Plugins = rebar_state:get(State1, plugins, []), {ok, State2} = rebar_prv_install_deps:handle_deps(State1, Plugins), -- cgit v1.1 From 6c6480fa077065d1db77b78a49c79d9f6cf08035 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 09:12:36 -0500 Subject: only compile invalid plugins --- src/rebar_plugins.erl | 3 ++- src/rebar_prv_install_deps.erl | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index d8422d8..9fc0b23 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -18,11 +18,12 @@ install(State) -> {ok, State2} = rebar_prv_install_deps:handle_deps(State1, Plugins), Apps = rebar_state:get(State2, all_deps), + ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Apps), lists:foreach(fun(AppInfo) -> C = rebar_config:consult(rebar_app_info:dir(AppInfo)), S = rebar_state:new(rebar_state:new(), C, rebar_app_info:dir(AppInfo)), rebar_prv_compile:build(S, AppInfo) - end, Apps), + end, ToBuild), PluginProviders = plugin_providers(Plugins), {ok, PluginProviders, rebar_state:set(State2, deps_dir, ?DEFAULT_DEPS_DIR)}. diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 81acf22..c86d2d1 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -124,7 +124,6 @@ handle_deps(State, Deps) -> %% Sort all apps to build order State3 = rebar_state:set(State2, all_deps, AllDeps), - {ok, State3}. -- cgit v1.1 From 1046f4c5d75965dec5e3155194e34540aadeddd0 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 09:58:35 -0500 Subject: handle no plugins as [] list of plugins --- src/rebar_plugins.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index 9fc0b23..b180ede 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -17,7 +17,7 @@ install(State) -> Plugins = rebar_state:get(State1, plugins, []), {ok, State2} = rebar_prv_install_deps:handle_deps(State1, Plugins), - Apps = rebar_state:get(State2, all_deps), + Apps = rebar_state:get(State2, all_deps, []), ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Apps), lists:foreach(fun(AppInfo) -> C = rebar_config:consult(rebar_app_info:dir(AppInfo)), -- cgit v1.1 From 1dabd217dbfbebae2f5375160551c35cd1f2a972 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 13:51:14 -0500 Subject: inefficient way, but safer, of checking if an app is already downloaded --- src/rebar_app_discover.erl | 1 + src/rebar_app_utils.erl | 14 +++++++++++++- src/rebar_prv_install_deps.erl | 19 ++++++++++--------- src/rebar_prv_update.erl | 7 +++++-- 4 files changed, 29 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index c90a8df..7aaba21 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -55,6 +55,7 @@ find_apps(LibDirs, Validate) -> find_app(AppDir, Validate) end, all_app_dirs(LibDirs)). +-spec find_app(list(), boolean()) -> rebar_app_info:t() | false. find_app(AppDir, Validate) -> AppFile = filelib:wildcard(filename:join([AppDir, "ebin", "*.app"])), AppSrcFile = filelib:wildcard(filename:join([AppDir, "src", "*.app.src"])), diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index 1c53743..8c78850 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -26,7 +26,8 @@ %% ------------------------------------------------------------------- -module(rebar_app_utils). --export([is_app_dir/0, is_app_dir/1, +-export([find/2, + is_app_dir/0, is_app_dir/1, is_app_src/1, app_src_to_app/1, app_name/2, @@ -42,6 +43,17 @@ %% Public API %% =================================================================== +-spec find(binary(), [rebar_app_info:t()]) -> {ok, rebar_app_info:t()} | error. +find(Name, Apps) -> + ec_lists:find(fun(App) -> rebar_app_info:name(App) =:= Name end, Apps). + +-spec find(binary(), binary(), [rebar_app_info:t()]) -> {ok, rebar_app_info:t()} | error. +find(Name, Vsn, Apps) -> + ec_lists:find(fun(App) -> + rebar_app_info:name(App) =:= Name + andalso rebar_app_info:original_vsn(App) =:= Vsn + end, Apps). + is_app_dir() -> is_app_dir(rebar_utils:get_cwd()). diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index c86d2d1..607aeb7 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -114,7 +114,7 @@ handle_deps(State, Deps) -> ,Packages ,Name ,Vsn), - ok = maybe_fetch(AppInfo), + ok = maybe_fetch(AppInfo, State2), AppInfo end, S) end, @@ -154,7 +154,7 @@ update_src_deps(State) -> SrcDeps = rebar_state:src_deps(State), DepsDir = get_deps_dir(State), case lists:foldl(fun(AppInfo, {SrcDepsAcc, BinaryDepsAcc}) -> - ok = maybe_fetch(AppInfo), + ok = maybe_fetch(AppInfo, State), {AppInfo1, NewSrcDeps, NewBinaryDeps} = handle_dep(DepsDir, AppInfo), {ordsets:union(ordsets:add_element(AppInfo1, SrcDepsAcc), NewSrcDeps) ,NewBinaryDeps++BinaryDepsAcc} @@ -175,16 +175,17 @@ handle_dep(DepsDir, AppInfo) -> {SrcDeps, BinaryDeps} = parse_deps(DepsDir, Deps), {AppInfo1, SrcDeps, BinaryDeps}. --spec maybe_fetch(rebar_app_info:t()) -> ok. -maybe_fetch(AppInfo) -> +-spec maybe_fetch(rebar_app_info:t(), rebar_state:t()) -> ok. +maybe_fetch(AppInfo, State) -> AppDir = rebar_app_info:dir(AppInfo), - case filelib:is_dir(AppDir) of - false -> + Apps = rebar_app_discover:find_apps([get_deps_dir(State)], all), + case rebar_app_utils:find(rebar_app_info:name(AppInfo), Apps) of + {ok, _} -> + ok; + _ -> ?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]), Source = rebar_app_info:source(AppInfo), - rebar_fetch:download_source(AppDir, Source); - true -> - ok + rebar_fetch:download_source(AppDir, Source) end. -spec parse_deps(binary(), [dep()]) -> {ordsets:ordset(rebar_app_info:t()), [binary_dep()]}. diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index e19041a..f4b25f0 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -11,7 +11,7 @@ -include("rebar.hrl"). -define(PROVIDER, update). --define(DEPS, []). +-define(DEPS, [install_deps]). %% =================================================================== %% Public API @@ -29,11 +29,14 @@ init(State) -> opts = []}), {ok, State1}. --spec do(rebar_state:t()) -> {ok, rebar_state:t()} | relx:error(). +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | rebar:error(). do(State) -> case rebar_state:command_args(State) of [Name] -> ?ERROR("NOT IMPLEMENTED: Updating ~s~n", [Name]), + AllDeps = rebar_state:get(State, all_deps, []), + {ok, App} = rebar_app_utils:find(list_to_binary(Name), AllDeps), + rebar_prv_install_deps:handle_deps(State, [list_to_binary(Name)]), {ok, State}; [] -> ?INFO("Updating package index...~n", []), -- cgit v1.1 From 3924908f64dec6fdd9c8195b826453602f7b34f1 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 14:01:22 -0500 Subject: more efficient check for existing dep --- src/rebar_app_utils.erl | 3 +++ src/rebar_prv_install_deps.erl | 22 ++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index 8c78850..d1487fb 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -27,6 +27,7 @@ -module(rebar_app_utils). -export([find/2, + find/3, is_app_dir/0, is_app_dir/1, is_app_src/1, app_src_to_app/1, @@ -54,9 +55,11 @@ find(Name, Vsn, Apps) -> andalso rebar_app_info:original_vsn(App) =:= Vsn end, Apps). +-spec is_app_dir() -> {true, file:name()} | false. is_app_dir() -> is_app_dir(rebar_utils:get_cwd()). +-spec is_app_dir(file:name()) -> {true, file:name()} | false. is_app_dir(Dir) -> SrcDir = filename:join([Dir, "src"]), AppSrc = filename:join([SrcDir, "*.app.src"]), diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 607aeb7..ef08754 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -176,16 +176,22 @@ handle_dep(DepsDir, AppInfo) -> {AppInfo1, SrcDeps, BinaryDeps}. -spec maybe_fetch(rebar_app_info:t(), rebar_state:t()) -> ok. -maybe_fetch(AppInfo, State) -> - AppDir = rebar_app_info:dir(AppInfo), - Apps = rebar_app_discover:find_apps([get_deps_dir(State)], all), - case rebar_app_utils:find(rebar_app_info:name(AppInfo), Apps) of - {ok, _} -> +maybe_fetch(AppInfo, _State) -> + AppDir = ec_cnv:to_list(rebar_app_info:dir(AppInfo)), + %Apps = rebar_app_discover:find_apps([get_deps_dir(State)], all), + %case rebar_app_utils:find(rebar_app_info:name(AppInfo), Apps) of + case rebar_app_utils:is_app_dir(filename:absname(AppDir)++"-*") of + {true, _} -> ok; _ -> - ?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]), - Source = rebar_app_info:source(AppInfo), - rebar_fetch:download_source(AppDir, Source) + case rebar_app_utils:is_app_dir(filename:absname(AppDir)) of + {true, _} -> + ok; + _ -> + ?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]), + Source = rebar_app_info:source(AppInfo), + rebar_fetch:download_source(AppDir, Source) + end end. -spec parse_deps(binary(), [dep()]) -> {ordsets:ordset(rebar_app_info:t()), [binary_dep()]}. -- cgit v1.1 From 0649be271bd8b2db2549dbc3228bd2d6b83e8954 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 14:19:02 -0500 Subject: wip: update dep --- src/rebar_prv_install_deps.erl | 56 +++++++++++++++++++++++++----------------- src/rebar_prv_update.erl | 2 +- 2 files changed, 35 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index ef08754..3b78fd1 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -33,7 +33,8 @@ -include("rebar.hrl"). --export([handle_deps/2]). +-export([handle_deps/2, + handle_deps/3]). %% for internal use only -export([get_deps_dir/1]). @@ -88,9 +89,13 @@ get_deps_dir(DepsDir, App) -> filename:join(DepsDir, App). -spec handle_deps(rebar_state:t(), [dep()]) -> {ok, rebar_state:t()}. -handle_deps(State, []) -> - {ok, State}; handle_deps(State, Deps) -> + handle_deps(State, Deps, false). + +-spec handle_deps(rebar_state:t(), [dep()], boolean()) -> {ok, rebar_state:t()}. +handle_deps(State, [], _) -> + {ok, State}; +handle_deps(State, Deps, Update) -> %% Read in package index and dep graph {Packages, Graph} = rebar_packages:get_packages(State), @@ -101,7 +106,7 @@ handle_deps(State, Deps) -> SrcDeps), %% Fetch transitive src deps - State2 = update_src_deps(State1), + State2 = update_src_deps(State1, Update), Solved = case rebar_state:binary_deps(State2) of [] -> %% No binary deps []; @@ -114,7 +119,7 @@ handle_deps(State, Deps) -> ,Packages ,Name ,Vsn), - ok = maybe_fetch(AppInfo, State2), + ok = maybe_fetch(AppInfo, Update), AppInfo end, S) end, @@ -149,12 +154,12 @@ package_to_app(DepsDir, Packages, Name, Vsn) -> rebar_app_info:dir(AppInfo1, get_deps_dir(DepsDir, <>)), rebar_app_info:source(AppInfo2, Link). --spec update_src_deps(rebar_state:t()) -> rebat_state:t(). -update_src_deps(State) -> +-spec update_src_deps(rebar_state:t(), boolean()) -> rebat_state:t(). +update_src_deps(State, Update) -> SrcDeps = rebar_state:src_deps(State), DepsDir = get_deps_dir(State), case lists:foldl(fun(AppInfo, {SrcDepsAcc, BinaryDepsAcc}) -> - ok = maybe_fetch(AppInfo, State), + ok = maybe_fetch(AppInfo, Update), {AppInfo1, NewSrcDeps, NewBinaryDeps} = handle_dep(DepsDir, AppInfo), {ordsets:union(ordsets:add_element(AppInfo1, SrcDepsAcc), NewSrcDeps) ,NewBinaryDeps++BinaryDepsAcc} @@ -163,7 +168,7 @@ update_src_deps(State) -> rebar_state:src_deps(rebar_state:binary_deps(State, NewBinaryDeps), NewSrcDeps); {NewSrcDeps, NewBinaryDeps} -> State1 = rebar_state:src_deps(rebar_state:binary_deps(State, NewBinaryDeps), NewSrcDeps), - update_src_deps(State1) + update_src_deps(State1, Update) end. -spec handle_dep(binary(), rebar_state:t()) -> {[rebar_app_info:t()], [binary_dep()]}. @@ -175,23 +180,30 @@ handle_dep(DepsDir, AppInfo) -> {SrcDeps, BinaryDeps} = parse_deps(DepsDir, Deps), {AppInfo1, SrcDeps, BinaryDeps}. --spec maybe_fetch(rebar_app_info:t(), rebar_state:t()) -> ok. -maybe_fetch(AppInfo, _State) -> +-spec maybe_fetch(rebar_app_info:t(), boolean()) -> ok. +maybe_fetch(AppInfo, Update) -> AppDir = ec_cnv:to_list(rebar_app_info:dir(AppInfo)), %Apps = rebar_app_discover:find_apps([get_deps_dir(State)], all), %case rebar_app_utils:find(rebar_app_info:name(AppInfo), Apps) of - case rebar_app_utils:is_app_dir(filename:absname(AppDir)++"-*") of - {true, _} -> - ok; + Exists = case rebar_app_utils:is_app_dir(filename:absname(AppDir)++"-*") of + {true, _} -> + true; + _ -> + case rebar_app_utils:is_app_dir(filename:absname(AppDir)) of + {true, _} -> + true; + _ -> + false + end + end, + + case not Exists orelse Update of + true -> + ?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]), + Source = rebar_app_info:source(AppInfo), + rebar_fetch:download_source(AppDir, Source); _ -> - case rebar_app_utils:is_app_dir(filename:absname(AppDir)) of - {true, _} -> - ok; - _ -> - ?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]), - Source = rebar_app_info:source(AppInfo), - rebar_fetch:download_source(AppDir, Source) - end + ok end. -spec parse_deps(binary(), [dep()]) -> {ordsets:ordset(rebar_app_info:t()), [binary_dep()]}. diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl index f4b25f0..4a02664 100644 --- a/src/rebar_prv_update.erl +++ b/src/rebar_prv_update.erl @@ -36,7 +36,7 @@ do(State) -> ?ERROR("NOT IMPLEMENTED: Updating ~s~n", [Name]), AllDeps = rebar_state:get(State, all_deps, []), {ok, App} = rebar_app_utils:find(list_to_binary(Name), AllDeps), - rebar_prv_install_deps:handle_deps(State, [list_to_binary(Name)]), + rebar_prv_install_deps:handle_deps(State, [list_to_atom(Name)], true), {ok, State}; [] -> ?INFO("Updating package index...~n", []), -- cgit v1.1 From f4ab647c95ea54b46623d6ada75104f2e71dea8a Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 14:19:27 -0500 Subject: fix for wrong function call to depsolver new for empty graph --- src/rebar_packages.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl index 103d3a3..9cfcebb 100644 --- a/src/rebar_packages.erl +++ b/src/rebar_packages.erl @@ -16,8 +16,8 @@ get_packages(State) -> catch _:_ -> ?ERROR("Bad packages index, try to fix with `rebar update`~n", []), - {[], rlx_depsolver:new()} + {[], rlx_depsolver:new_graph()} end; false -> - {[], rlx_depsolver:new()} + {[], rlx_depsolver:new_graph()} end. -- cgit v1.1 From c8772ff398e43a535d6c145ce3ed0d31952f907e Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 22:02:02 -0500 Subject: wip: updating handling of src deps to include level in lock --- src/rebar_app_info.erl | 9 ++++++ src/rebar_prv_install_deps.erl | 63 ++++++++++++++++++++++++------------------ src/rebar_prv_lock.erl | 3 +- src/rebar_state.erl | 14 ++++++++-- 4 files changed, 59 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index 008bfd2..44394b3 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -21,6 +21,8 @@ ebin_dir/1, deps/1, deps/2, + dep_level/1, + dep_level/2, dir/1, dir/2, source/1, @@ -37,6 +39,7 @@ original_vsn :: string(), app_details=[] :: list(), deps=[] :: list(), + dep_level :: integer(), dir :: file:name(), source :: string() | undefined, valid :: boolean()}). @@ -166,6 +169,12 @@ deps(#app_info_t{deps=Deps}) -> deps(AppInfo=#app_info_t{}, Deps) -> AppInfo#app_info_t{deps=Deps}. +dep_level(AppInfo=#app_info_t{}, Level) -> + AppInfo#app_info_t{dep_level=Level}. + +dep_level(AppInfo=#app_info_t{dep_level=Level}) -> + Level. + -spec dir(t()) -> file:name(). dir(#app_info_t{dir=Dir}) -> Dir. diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 3b78fd1..03dfce4 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -69,13 +69,13 @@ do(State) -> ProjectApps = rebar_state:project_apps(State), {ok, State1} = case rebar_state:get(State, locks, []) of [] -> - handle_deps(State, ordsets:from_list(rebar_state:get(State, deps, []))); + handle_deps(State, rebar_state:get(State, deps, [])); Locks -> - handle_deps(State, ordsets:from_list(Locks)) + handle_deps(State, Locks) end, - Source = ProjectApps ++ ordsets:to_list(rebar_state:src_deps(State1)), - {ok, Sort} = rebar_topo:sort_apps(ordsets:to_list(Source)), + Source = ProjectApps ++ rebar_state:src_deps(State1), + {ok, Sort} = rebar_topo:sort_apps(Source), {ok, rebar_state:set(State1, deps_to_build, lists:dropwhile(fun is_valid/1, Sort -- ProjectApps))}. -spec get_deps_dir(rebar_state:t()) -> file:filename_all(). @@ -106,7 +106,7 @@ handle_deps(State, Deps, Update) -> SrcDeps), %% Fetch transitive src deps - State2 = update_src_deps(State1, Update), + State2 = update_src_deps(0, State1, Update), Solved = case rebar_state:binary_deps(State2) of [] -> %% No binary deps []; @@ -124,9 +124,10 @@ handle_deps(State, Deps, Update) -> end, S) end, - AllDeps = ordsets:union([ordsets:to_list(rebar_state:src_deps(State2)) - ,ordsets:from_list(Solved)]), - + AllDeps = lists:keymerge(2 + ,rebar_state:src_apps(State2) + ,Solved), + io:format("All ~p~n", [AllDeps]), %% Sort all apps to build order State3 = rebar_state:set(State2, all_deps, AllDeps), {ok, State3}. @@ -154,21 +155,28 @@ package_to_app(DepsDir, Packages, Name, Vsn) -> rebar_app_info:dir(AppInfo1, get_deps_dir(DepsDir, <>)), rebar_app_info:source(AppInfo2, Link). --spec update_src_deps(rebar_state:t(), boolean()) -> rebat_state:t(). -update_src_deps(State, Update) -> +-spec update_src_deps(integer(), rebar_state:t(), boolean()) -> rebat_state:t(). +update_src_deps(Level, State, Update) -> SrcDeps = rebar_state:src_deps(State), DepsDir = get_deps_dir(State), - case lists:foldl(fun(AppInfo, {SrcDepsAcc, BinaryDepsAcc}) -> - ok = maybe_fetch(AppInfo, Update), - {AppInfo1, NewSrcDeps, NewBinaryDeps} = handle_dep(DepsDir, AppInfo), - {ordsets:union(ordsets:add_element(AppInfo1, SrcDepsAcc), NewSrcDeps) - ,NewBinaryDeps++BinaryDepsAcc} - end, {ordsets:new(), rebar_state:binary_deps(State)}, SrcDeps) of - {NewSrcDeps, NewBinaryDeps} when length(SrcDeps) =:= length(NewSrcDeps) -> - rebar_state:src_deps(rebar_state:binary_deps(State, NewBinaryDeps), NewSrcDeps); - {NewSrcDeps, NewBinaryDeps} -> - State1 = rebar_state:src_deps(rebar_state:binary_deps(State, NewBinaryDeps), NewSrcDeps), - update_src_deps(State1, Update) + case lists:foldl(fun(AppInfo, {SrcDepsAcc, BinaryDepsAcc, StateAcc}) -> + case maybe_fetch(AppInfo, Update) of + true -> + {AppInfo1, NewSrcDeps, NewBinaryDeps} = + handle_dep(DepsDir, AppInfo), + AppInfo2 = rebar_app_info:dep_level(AppInfo1, Level), + {NewSrcDeps ++ SrcDepsAcc + ,NewBinaryDeps++BinaryDepsAcc + ,rebar_state:src_apps(StateAcc, AppInfo2)}; + false -> + {SrcDepsAcc, BinaryDepsAcc, State} + end + end, {[], rebar_state:binary_deps(State), State}, SrcDeps) of + {NewSrcDeps, NewBinaryDeps, State1} when length(SrcDeps) =:= length(NewSrcDeps) -> + rebar_state:src_deps(rebar_state:binary_deps(State1, NewBinaryDeps), NewSrcDeps); + {NewSrcDeps, NewBinaryDeps, State1} -> + State2 = rebar_state:src_deps(rebar_state:binary_deps(State1, NewBinaryDeps), NewSrcDeps), + update_src_deps(Level+1, State2, Update) end. -spec handle_dep(binary(), rebar_state:t()) -> {[rebar_app_info:t()], [binary_dep()]}. @@ -180,7 +188,7 @@ handle_dep(DepsDir, AppInfo) -> {SrcDeps, BinaryDeps} = parse_deps(DepsDir, Deps), {AppInfo1, SrcDeps, BinaryDeps}. --spec maybe_fetch(rebar_app_info:t(), boolean()) -> ok. +-spec maybe_fetch(rebar_app_info:t(), boolean()) -> boolean(). maybe_fetch(AppInfo, Update) -> AppDir = ec_cnv:to_list(rebar_app_info:dir(AppInfo)), %Apps = rebar_app_discover:find_apps([get_deps_dir(State)], all), @@ -201,12 +209,13 @@ maybe_fetch(AppInfo, Update) -> true -> ?INFO("Fetching ~s~n", [rebar_app_info:name(AppInfo)]), Source = rebar_app_info:source(AppInfo), - rebar_fetch:download_source(AppDir, Source); + rebar_fetch:download_source(AppDir, Source), + true; _ -> - ok + false end. --spec parse_deps(binary(), [dep()]) -> {ordsets:ordset(rebar_app_info:t()), [binary_dep()]}. +-spec parse_deps(binary(), [dep()]) -> {[rebar_app_info:t()], [binary_dep()]}. parse_deps(DepsDir, Deps) -> lists:foldl(fun({Name, Vsn}, {SrcDepsAcc, BinaryDepsAcc}) -> {SrcDepsAcc, [parse_goal(ec_cnv:to_binary(Name) @@ -222,8 +231,8 @@ parse_deps(DepsDir, Deps) -> rebar_app_info:new(Name, Vsn, Dir) end, Dep1 = rebar_app_info:source(Dep, Source), - {ordsets:add_element(Dep1, SrcDepsAcc), BinaryDepsAcc} - end, {ordsets:new(), []}, Deps). + {[Dep1 | SrcDepsAcc], BinaryDepsAcc} + end, {[], []}, Deps). -spec parse_goal(binary(), binary()) -> binary_dep(). parse_goal(Name, Constraint) -> diff --git a/src/rebar_prv_lock.erl b/src/rebar_prv_lock.erl index b4a7d8d..441c46d 100644 --- a/src/rebar_prv_lock.erl +++ b/src/rebar_prv_lock.erl @@ -40,7 +40,8 @@ do(State) -> Source when is_tuple(Source) -> {rebar_app_info:name(Dep) ,rebar_app_info:original_vsn(Dep) - ,rebar_fetch:lock_source(Dir, Source)}; + ,rebar_fetch:lock_source(Dir, Source) + ,rebar_app_info:dep_level(Dep)}; _Source -> {rebar_app_info:name(Dep) ,rebar_app_info:original_vsn(Dep)} diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 706c528..ac6684d 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -13,6 +13,7 @@ deps_names/1, binary_deps/1, binary_deps/2, src_deps/1, src_deps/2, + src_apps/1, src_apps/2, prepend_hook/3, append_hook/3, hooks/2, providers/1, providers/2, add_provider/2]). @@ -35,9 +36,10 @@ envs = new_env() :: rebar_dict(), command_args = [] :: list(), - src_deps = ordsets:new() :: ordsets:ordset(rebar_app_info:t()), + src_deps = [] :: [rebar_app_info:t()], + src_apps = [] :: dict:dict(), binary_deps = [], - project_apps = ordsets:new() :: ordsets:ordset(rebar_app_info:t()), + project_apps = [] :: [rebar_app_info:t()], providers = [], hooks = [], @@ -139,6 +141,14 @@ src_deps(State=#state_t{src_deps=SrcDeps}, NewSrcDeps) when is_list(SrcDeps) -> src_deps(State=#state_t{src_deps=SrcDeps}, SrcDep) -> State#state_t{src_deps=[SrcDep | SrcDeps]}. +src_apps(#state_t{src_apps=SrcApps}) -> + SrcApps. + +src_apps(State=#state_t{src_apps=SrcApps}, NewSrcApps) when is_list(NewSrcApps) -> + State#state_t{src_apps=NewSrcApps}; +src_apps(State=#state_t{src_apps=SrcApps}, NewSrcApp) -> + State#state_t{src_apps=[NewSrcApp | SrcApps]}. + project_apps(#state_t{project_apps=Apps}) -> Apps. -- cgit v1.1 From e1b1152b219cf65c7f8cd3b77db5cf2156fcbab7 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 20 Sep 2014 22:36:54 -0500 Subject: slowly widdling away at dialyzer errors --- src/rebar_app_discover.erl | 8 ++++--- src/rebar_app_info.erl | 9 ++++---- src/rebar_app_utils.erl | 51 +-------------------------------------------- src/rebar_config.erl | 4 ++-- src/rebar_core.erl | 2 -- src/rebar_prv_do.erl | 2 +- src/rebar_prv_escripter.erl | 10 ++++----- src/rebar_prv_help.erl | 2 +- src/rebar_prv_new.erl | 32 ++++++---------------------- src/rebar_prv_release.erl | 2 +- src/rebar_prv_tar.erl | 6 +++--- src/rebar_prv_update.erl | 4 ++-- src/rebar_state.erl | 7 ++++--- 13 files changed, 35 insertions(+), 104 deletions(-) (limited to 'src') diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index 7aaba21..7713ee6 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -105,6 +105,7 @@ find_app(AppDir, Validate) -> app_dir(AppFile) -> filename:join(rebar_utils:droplast(filename:split(filename:dirname(AppFile)))). +-spec create_app_info(file:name(), file:name()) -> rebar_app_info:t() | error. create_app_info(AppDir, AppFile) -> case file:consult(AppFile) of {ok, [{application, AppName, AppDetails}]} -> @@ -122,7 +123,9 @@ create_app_info(AppDir, AppFile) -> AppState1 = rebar_state:set(AppState, base_dir, AbsCwd), AppInfo1 = rebar_app_info:config( rebar_app_info:app_details(AppInfo, AppDetails), AppState1), - rebar_app_info:dir(AppInfo1, AppDir) + rebar_app_info:dir(AppInfo1, AppDir); + _ -> + error end. -spec validate_application_info(rebar_app_info:t()) -> boolean(). @@ -149,8 +152,7 @@ get_modules_list(AppFile, AppDetail) -> {ok, ModulesList} end. --spec has_all_beams(file:name(), list()) -> - ok | {error, Reason::term()}. +-spec has_all_beams(file:name(), list()) -> boolean(). has_all_beams(EbinDir, [Module | ModuleList]) -> BeamFile = filename:join([EbinDir, ec_cnv:to_list(Module) ++ ".beam"]), diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index 44394b3..403a5d1 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -87,13 +87,12 @@ new(AppName, Vsn, Dir, Deps) -> deps=Deps}}. %% @doc discover a complete version of the app info with all fields set. --spec discover(file:name()) -> - {ok, t()}. +-spec discover(file:name()) -> {ok, t()} | not_found. discover(Dir) -> case rebar_app_discover:find_app(Dir, all) of {true, AppInfo} -> {ok, AppInfo}; - _ -> + false -> not_found end. @@ -157,7 +156,7 @@ app_details(AppInfo=#app_info_t{}, AppDetails) -> original_vsn(#app_info_t{original_vsn=Vsn}) -> Vsn. --spec original_vsn(t(), string()) -> string(). +-spec original_vsn(t(), string()) -> t(). original_vsn(AppInfo=#app_info_t{}, Vsn) -> AppInfo#app_info_t{original_vsn=Vsn}. @@ -172,7 +171,7 @@ deps(AppInfo=#app_info_t{}, Deps) -> dep_level(AppInfo=#app_info_t{}, Level) -> AppInfo#app_info_t{dep_level=Level}. -dep_level(AppInfo=#app_info_t{dep_level=Level}) -> +dep_level(#app_info_t{dep_level=Level}) -> Level. -spec dir(t()) -> file:name(). diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl index d1487fb..8fc3df8 100644 --- a/src/rebar_app_utils.erl +++ b/src/rebar_app_utils.erl @@ -33,8 +33,7 @@ app_src_to_app/1, app_name/2, app_applications/2, - app_vsn/2, - is_skipped_app/2]). + app_vsn/2]). -export([load_app_file/2]). % TEMPORARY @@ -124,30 +123,6 @@ app_vsn(Config, AppFile) -> [AppFile, Reason]) end. -is_skipped_app(Config, AppFile) -> - {Config1, ThisApp} = app_name(Config, AppFile), - %% Check for apps global parameter; this is a comma-delimited list - %% of apps on which we want to run commands - Skipped = - case get_apps(Config) of - undefined -> - %% No apps parameter specified, check the skip_apps list.. - case get_skip_apps(Config) of - undefined -> - %% No skip_apps list, run everything.. - false; - SkipApps -> - TargetApps = [list_to_atom(A) || - A <- string:tokens(SkipApps, ",")], - is_skipped(ThisApp, TargetApps) - end; - Apps -> - %% run only selected apps - TargetApps = [list_to_atom(A) || A <- string:tokens(Apps, ",")], - is_selected(ThisApp, TargetApps) - end, - {Config1, Skipped}. - %% =================================================================== %% Internal functions %% =================================================================== @@ -191,27 +166,3 @@ get_value(Key, AppInfo, AppFile) -> Value -> Value end. - -%% apps= for selecting apps -is_selected(ThisApp, TargetApps) -> - case lists:member(ThisApp, TargetApps) of - false -> - {true, ThisApp}; - true -> - false - end. - -%% skip_apps= for filtering apps -is_skipped(ThisApp, TargetApps) -> - case lists:member(ThisApp, TargetApps) of - false -> - false; - true -> - {true, ThisApp} - end. - -get_apps(Config) -> - rebar_config:get_global(Config, apps, undefined). - -get_skip_apps(Config) -> - rebar_config:get_global(Config, skip_apps, undefined). diff --git a/src/rebar_config.erl b/src/rebar_config.erl index a45bef9..b3003d6 100644 --- a/src/rebar_config.erl +++ b/src/rebar_config.erl @@ -35,11 +35,11 @@ %% Public API %% =================================================================== --spec consult(file:name()) -> {ok, any()}. +-spec consult(file:name()) -> [any()]. consult(Dir) -> consult_file(filename:join(Dir, ?DEFAULT_CONFIG_FILE)). --spec consult_file(file:name()) -> {ok, any()}. +-spec consult_file(file:name()) -> [any()]. consult_file(File) when is_binary(File) -> consult_file(binary_to_list(File)); consult_file(File) -> diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 24b376f..ba77dd8 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -55,8 +55,6 @@ update_code_path(State) -> %% Internal functions %% =================================================================== -update_code_path_([]) -> - no_change; update_code_path_(Paths) -> LibPaths = expand_lib_dirs(Paths, rebar_utils:get_cwd(), []), ok = code:add_pathsa(LibPaths), diff --git a/src/rebar_prv_do.erl b/src/rebar_prv_do.erl index a2ac648..435db6f 100644 --- a/src/rebar_prv_do.erl +++ b/src/rebar_prv_do.erl @@ -29,7 +29,7 @@ init(State) -> opts = []}), {ok, State1}. --spec do(rebar_state:t()) -> {ok, rebar_state:t()} | relx:error(). +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. do(State) -> Tasks = args_to_tasks(rebar_state:command_args(State)), State1 = lists:foldl(fun(TaskArgs, StateAcc) -> diff --git a/src/rebar_prv_escripter.erl b/src/rebar_prv_escripter.erl index 418ac6c..9b5a812 100644 --- a/src/rebar_prv_escripter.erl +++ b/src/rebar_prv_escripter.erl @@ -61,7 +61,7 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | relx:error(). do(Config) -> - AppName = rebar_state:get_local(Config, escript_top_level_app, undefined), + AppName = rebar_state:get(Config, escript_top_level_app, undefined), App = rebar_state:get_app(Config, AppName), {ok, Config1} = escriptize(Config, rebar_app_info:app_file(App)), {ok, Config1}. @@ -73,14 +73,14 @@ escriptize(Config0, AppFile) -> AppNameStr = atom_to_list(AppName), %% Get the output filename for the escript -- this may include dirs - Filename = rebar_state:get_local(Config, escript_name, AppName), + Filename = rebar_state:get(Config, escript_name, AppName), ok = filelib:ensure_dir(Filename), %% Look for a list of other applications (dependencies) to include %% in the output file. We then use the .app files for each of these %% to pull in all the .beam files. InclBeams = get_app_beams( - rebar_state:get_local(Config, escript_incl_apps, []), []), + rebar_state:get(Config, escript_incl_apps, []), []), %% Look for a list of extra files to include in the output file. %% For internal rebar-private use only. Do not use outside rebar. @@ -130,7 +130,7 @@ clean(Config0, AppFile) -> {Config, AppName} = rebar_app_utils:app_name(Config0, AppFile), %% Get the output filename for the escript -- this may include dirs - Filename = rebar_state:get_local(Config, escript_name, AppName), + Filename = rebar_state:get(Config, escript_name, AppName), rebar_file_utils:delete_each([Filename]), {ok, Config}. @@ -176,7 +176,7 @@ get_app_beams([App | Rest], Acc) -> end. get_extra(Config) -> - Extra = rebar_state:get_local(Config, escript_incl_extra, []), + Extra = rebar_state:get(Config, escript_incl_extra, []), lists:foldl(fun({Wildcard, Dir}, Files) -> load_files(Wildcard, Dir) ++ Files end, [], Extra). diff --git a/src/rebar_prv_help.erl b/src/rebar_prv_help.erl index a9949e7..e9d89ca 100644 --- a/src/rebar_prv_help.erl +++ b/src/rebar_prv_help.erl @@ -29,7 +29,7 @@ init(State) -> opts = []}), {ok, State1}. --spec do(rebar_state:t()) -> {ok, rebar_state:t()} | relx:error(). +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. do(State) -> help(State), {ok, State}. diff --git a/src/rebar_prv_new.erl b/src/rebar_prv_new.erl index ed3c1b4..a3182fd 100644 --- a/src/rebar_prv_new.erl +++ b/src/rebar_prv_new.erl @@ -22,7 +22,7 @@ init(State) -> deps = ?DEPS, example = "rebar new