summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar3.erl12
-rw-r--r--src/rebar_config.erl37
-rw-r--r--src/rebar_otp_app.erl1
-rw-r--r--src/rebar_plugins.erl16
-rw-r--r--src/rebar_prv_compile.erl44
5 files changed, 69 insertions, 41 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 5a49ca8..e8a9983 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -142,15 +142,7 @@ init_config() ->
rebar_config:consult_file(ConfigFile)
end,
- Config1 = case rebar_config:consult_file(?LOCK_FILE) of
- [D] ->
- %% We want the top level deps only from the lock file.
- %% This ensures deterministic overrides for configs.
- Deps = [X || X <- D, element(3, X) =:= 0],
- [{{locks, default}, D}, {{deps, default}, Deps} | Config];
- _ ->
- Config
- end,
+ Config1 = rebar_config:merge_locks(Config, rebar_config:consult_file(?LOCK_FILE)),
%% If $HOME/.config/rebar3/config exists load and use as global config
GlobalConfigFile = rebar_dir:global_config(),
@@ -228,8 +220,6 @@ version() ->
?CONSOLE("rebar ~s on Erlang/OTP ~s Erts ~s",
[Vsn, erlang:system_info(otp_release), erlang:system_info(version)]).
-
-
%% TODO: Actually make it 'global'
%%
%% set global flag based on getopt option boolean value
diff --git a/src/rebar_config.erl b/src/rebar_config.erl
index 949d6d4..43730ea 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -27,7 +27,9 @@
-module(rebar_config).
-export([consult/1
- ,consult_file/1]).
+ ,consult_file/1
+
+ ,merge_locks/2]).
-include("rebar.hrl").
@@ -58,6 +60,18 @@ consult_file(File) ->
end
end.
+merge_locks(Config, []) ->
+ Config;
+merge_locks(Config, [Locks]) ->
+ {deps, ConfigDeps} = lists:keyfind(deps, 1, Config),
+ %% We want the top level deps only from the lock file.
+ %% This ensures deterministic overrides for configs.
+ %% Then check if any new deps have been added to the config
+ %% since it was locked.
+ Deps = [X || X <- Locks, element(3, X) =:= 0],
+ NewDeps = find_newly_added(ConfigDeps, Locks),
+ [{{locks, default}, Locks}, {{deps, default}, NewDeps++Deps} | Config].
+
%% ===================================================================
%% Internal functions
%% ===================================================================
@@ -84,3 +98,24 @@ bs(Vars) ->
lists:foldl(fun({K,V}, Bs) ->
erl_eval:add_binding(K, V, Bs)
end, erl_eval:new_bindings(), Vars).
+
+%% Find deps that have been added to the config after the lock was created
+find_newly_added(ConfigDeps, LockedDeps) ->
+ [Dep || Dep <- ConfigDeps,
+ begin
+ NewDep = ec_cnv:to_binary(element(1, Dep)),
+ case lists:keyfind(NewDep, 1, LockedDeps) of
+ false ->
+ true;
+ Match ->
+ case element(3, Match) of
+ 0 ->
+ true;
+ _ ->
+ ?WARN("Newly added dep ~s is locked at a lower level. "
+ "If you really want to unlock it, use 'rebar3 upgrade ~s'",
+ [NewDep, NewDep]),
+ false
+ end
+ end
+ end].
diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl
index e5e2361..272d950 100644
--- a/src/rebar_otp_app.erl
+++ b/src/rebar_otp_app.erl
@@ -54,6 +54,7 @@ compile(State, App) ->
validate_app(State2, App1).
+
format_error({file_read, File, Reason}) ->
io_lib:format("Failed to read ~s for processing: ~p", [File, Reason]);
format_error({invalid_name, File, AppName}) ->
diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl
index 45cb5c9..333d8a1 100644
--- a/src/rebar_plugins.erl
+++ b/src/rebar_plugins.erl
@@ -32,14 +32,7 @@ handle_plugin(Plugin, State) ->
Apps = rebar_state:all_deps(State1),
ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Apps),
- lists:foreach(fun(AppInfo) ->
- AppDir = rebar_app_info:dir(AppInfo),
- C = rebar_config:consult(AppDir),
- S = rebar_state:new(rebar_state:new(), C, AppDir),
- rebar_prv_compile:build(S, AppInfo),
- true = code:add_patha(filename:join(AppDir, "ebin"))
- end, ToBuild),
-
+ [build_plugin(AppInfo) || AppInfo <- ToBuild],
plugin_providers(Plugin)
catch
C:T ->
@@ -48,6 +41,13 @@ handle_plugin(Plugin, State) ->
false
end.
+build_plugin(AppInfo) ->
+ AppDir = rebar_app_info:dir(AppInfo),
+ C = rebar_config:consult(AppDir),
+ S = rebar_state:new(rebar_state:new(), C, AppDir),
+ rebar_prv_compile:compile(S, AppInfo),
+ true = code:add_patha(filename:join(AppDir, "ebin")).
+
plugin_providers({Plugin, _, _}) when is_atom(Plugin) ->
validate_plugin(Plugin);
plugin_providers({Plugin, _}) when is_atom(Plugin) ->
diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl
index 073394c..c4cca16 100644
--- a/src/rebar_prv_compile.erl
+++ b/src/rebar_prv_compile.erl
@@ -6,7 +6,7 @@
do/1,
format_error/1]).
--export([build/2]).
+-export([compile/2]).
-include("rebar.hrl").
@@ -55,34 +55,36 @@ do(State) ->
%% Use the project State for building project apps
%% Set hooks to empty so top-level hooks aren't run for each project app
State2 = rebar_state:set(rebar_state:set(State1, post_hooks, []), pre_hooks, []),
- build_apps(State2, ProjectApps),
+ ProjectApps1 = build_apps(State2, ProjectApps),
rebar_hooks:run_compile_hooks(Cwd, post_hooks, compile, State1),
- {ok, State1}.
+ {ok, rebar_state:project_apps(State1, ProjectApps1)}.
-spec format_error(any()) -> iolist().
format_error(Reason) ->
io_lib:format("~p", [Reason]).
build_apps(State, Apps) ->
- lists:foreach(fun(AppInfo) ->
- AppDir = rebar_app_info:dir(AppInfo),
- S = case rebar_app_info:state(AppInfo) of
- undefined ->
- C = rebar_config:consult(AppDir),
- rebar_state:new(State, C, AppDir);
- AppState ->
- AppState
- end,
-
- %% Legacy hook support
- rebar_hooks:run_compile_hooks(AppDir, pre_hooks, compile, S),
- build(S, AppInfo),
- rebar_hooks:run_compile_hooks(AppDir, post_hooks, compile, S),
- true = code:add_patha(filename:join(AppDir, "ebin"))
- end, Apps).
-
-build(State, AppInfo) ->
+ [build_app(State, AppInfo) || AppInfo <- Apps].
+
+build_app(State, AppInfo) ->
+ AppDir = rebar_app_info:dir(AppInfo),
+ S = case rebar_app_info:state(AppInfo) of
+ undefined ->
+ C = rebar_config:consult(AppDir),
+ rebar_state:new(State, C, AppDir);
+ AppState ->
+ AppState
+ end,
+
+ %% Legacy hook support
+ rebar_hooks:run_compile_hooks(AppDir, pre_hooks, compile, S),
+ AppInfo1 = compile(S, AppInfo),
+ rebar_hooks:run_compile_hooks(AppDir, post_hooks, compile, S),
+ true = code:add_patha(filename:join(AppDir, "ebin")),
+ AppInfo1.
+
+compile(State, AppInfo) ->
?INFO("Compiling ~s", [rebar_app_info:name(AppInfo)]),
rebar_erlc_compiler:compile(State, ec_cnv:to_list(rebar_app_info:dir(AppInfo))),
case rebar_otp_app:compile(State, AppInfo) of