summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar3.erl5
-rw-r--r--src/rebar_erlc_compiler.erl25
-rw-r--r--src/rebar_file_utils.erl15
-rw-r--r--src/rebar_prv_common_test.erl5
-rw-r--r--src/rebar_prv_xref.erl3
-rw-r--r--src/rebar_utils.erl10
6 files changed, 45 insertions, 18 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index c665f20..47dc25a 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -286,10 +286,11 @@ handle_error({error, Error}) when is_list(Error) ->
handle_error(Error) ->
%% Nothing should percolate up from rebar_core;
%% Dump this error to console
- ?CRASHDUMP("Error: ~p~n~p~n~n", [Error, erlang:get_stacktrace()]),
+ StackTrace = erlang:get_stacktrace(),
+ ?CRASHDUMP("Error: ~p~n~p~n~n", [Error, StackTrace]),
?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace or consult rebar3.crashdump", []),
?DEBUG("Uncaught error: ~p", [Error]),
- case erlang:get_stacktrace() of
+ case StackTrace of
[] -> ok;
Trace ->
?DEBUG("Stack trace to the error location:~n~p", [Trace])
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index b148172..36a247e 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -203,8 +203,8 @@ compile_dirs(RebarOpts, BaseDir, SrcDirs, OutDir, Opts) ->
G = init_erlcinfo(include_abs_dirs(ErlOpts, BaseDir), AllErlFiles, BaseDir, OutDir),
{ParseTransforms, Rest} = split_source_files(AllErlFiles, ErlOpts),
- NeededErlFiles = case needed_files(G, ErlOpts, BaseDir, OutDir, ParseTransforms) of
- [] -> needed_files(G, ErlOpts, BaseDir, OutDir, Rest);
+ NeededErlFiles = case needed_files(G, ErlOpts, RebarOpts, BaseDir, OutDir, ParseTransforms) of
+ [] -> needed_files(G, ErlOpts, RebarOpts, BaseDir, OutDir, Rest);
%% at least one parse transform in the opts needs updating, so recompile all
_ -> AllErlFiles
end,
@@ -224,7 +224,7 @@ compile_dirs(RebarOpts, BaseDir, SrcDirs, OutDir, Opts) ->
true -> ErlOptsFirst;
false -> ErlOpts
end,
- internal_erl_compile(C, BaseDir, S, OutDir, ErlOpts1)
+ internal_erl_compile(C, BaseDir, S, OutDir, ErlOpts1, RebarOpts)
end)
after
true = digraph:delete(SubGraph),
@@ -312,13 +312,15 @@ filename_to_atom(F) -> list_to_atom(filename:rootname(filename:basename(F))).
%% Get subset of SourceFiles which need to be recompiled, respecting
%% dependencies induced by given graph G.
-needed_files(G, ErlOpts, Dir, OutDir, SourceFiles) ->
+needed_files(G, ErlOpts, RebarOpts, Dir, OutDir, SourceFiles) ->
lists:filter(fun(Source) ->
TargetBase = target_base(OutDir, Source),
Target = TargetBase ++ ".beam",
+ PrivIncludes = [{i, filename:join(Dir, Src)}
+ || Src <- rebar_dir:all_src_dirs(RebarOpts, ["src"], [])],
AllOpts = [{outdir, filename:dirname(Target)}
,{i, filename:join(Dir, "include")}
- ,{i, Dir}] ++ ErlOpts,
+ ,{i, Dir}] ++ PrivIncludes ++ ErlOpts,
digraph:vertex(G, Source) > {Source, filelib:last_modified(Target)}
orelse opts_changed(AllOpts, TargetBase)
orelse erl_compiler_opts_set()
@@ -518,12 +520,15 @@ expand_file_names(Files, Dirs) ->
end, Files).
-spec internal_erl_compile(rebar_dict(), file:filename(), file:filename(),
- file:filename(), list()) -> ok | {ok, any()} | {error, any(), any()}.
-internal_erl_compile(Opts, Dir, Module, OutDir, ErlOpts) ->
+ file:filename(), list(), rebar_dict()) ->
+ ok | {ok, any()} | {error, any(), any()}.
+internal_erl_compile(Opts, Dir, Module, OutDir, ErlOpts, RebarOpts) ->
Target = target_base(OutDir, Module) ++ ".beam",
ok = filelib:ensure_dir(Target),
- AllOpts = [{outdir, filename:dirname(Target)}] ++ ErlOpts ++
- [{i, filename:join(Dir, "include")}, {i, Dir}, return],
+ PrivIncludes = [{i, filename:join(Dir, Src)}
+ || Src <- rebar_dir:all_src_dirs(RebarOpts, ["src"], [])],
+ AllOpts = [{outdir, filename:dirname(Target)}] ++ ErlOpts ++ PrivIncludes ++
+ [{i, filename:join(Dir, "include")}, {i, Dir}, return],
case compile:file(Module, AllOpts) of
{ok, _Mod} ->
ok;
@@ -668,6 +673,8 @@ process_attr(include_lib, Form, Includes, Dir) ->
[FileNode] = erl_syntax:attribute_arguments(Form),
RawFile = erl_syntax:string_value(FileNode),
maybe_expand_include_lib_path(RawFile, Dir) ++ Includes;
+process_attr(behavior, Form, Includes, _Dir) ->
+ process_attr(behaviour, Form, Includes, _Dir);
process_attr(behaviour, Form, Includes, _Dir) ->
[FileNode] = erl_syntax:attribute_arguments(Form),
File = module_to_erl(erl_syntax:atom_value(FileNode)),
diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl
index 437780d..6721b5a 100644
--- a/src/rebar_file_utils.erl
+++ b/src/rebar_file_utils.erl
@@ -72,11 +72,16 @@ consult_config(State, Filename) ->
[T] -> T;
[] -> []
end,
- SubConfigs = [consult_config(State, Entry ++ ".config") ||
- Entry <- Config, is_list(Entry)
- ],
-
- [Config | lists:merge(SubConfigs)].
+ JoinedConfig = lists:flatmap(
+ fun (SubConfig) when is_list(SubConfig) ->
+ case lists:suffix(".config", SubConfig) of
+ false -> consult_config(State, SubConfig ++ ".config");
+ true -> consult_config(State, SubConfig)
+ end;
+ (Entry) -> [Entry]
+ end, Config),
+ %% Backwards compatibility
+ [JoinedConfig].
format_error({bad_term_file, AppFile, Reason}) ->
io_lib:format("Error reading file ~s: ~s", [AppFile, file:format_error(Reason)]).
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index 1e0632e..46bd1a7 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -221,8 +221,13 @@ select_tests(State, ProjectApps, CmdOpts, CfgOpts) ->
Configs = lists:flatmap(fun(Filename) ->
rebar_file_utils:consult_config(State, Filename)
end, SysConfigs),
+ %% NB: load the applications (from user directories too) to support OTP < 17
+ %% to our best ability.
+ OldPath = code:get_path(),
+ code:add_pathsa(rebar_state:code_paths(State, all_deps)),
[application:load(Application) || Config <- Configs, {Application, _} <- Config],
rebar_utils:reread_config(Configs),
+ code:set_path(OldPath),
Merged = lists:ukeymerge(1,
lists:ukeysort(1, CmdOpts),
diff --git a/src/rebar_prv_xref.erl b/src/rebar_prv_xref.erl
index 45badd3..3d74c9a 100644
--- a/src/rebar_prv_xref.erl
+++ b/src/rebar_prv_xref.erl
@@ -165,7 +165,8 @@ keyall(Key, List) ->
lists:flatmap(fun({K, L}) when Key =:= K -> L; (_) -> [] end, List).
get_behaviour_callbacks(exports_not_used, Attributes) ->
- [B:behaviour_info(callbacks) || B <- keyall(behaviour, Attributes)];
+ [B:behaviour_info(callbacks) || B <- keyall(behaviour, Attributes) ++
+ keyall(behavior, Attributes)];
get_behaviour_callbacks(_XrefCheck, _Attributes) ->
[].
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index aa9e268..f55f40f 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -414,8 +414,16 @@ user_agent() ->
?FMT("Rebar/~s (OTP/~s)", [Vsn, otp_release()]).
reread_config(ConfigList) ->
+ %% NB: we attempt to mimic -config here, which survives app reload,
+ %% hence {persistent, true}.
+ SetEnv = case version_tuple(?MODULE:otp_release()) of
+ {X, _, _} when X =< 17 ->
+ fun application:set_env/3;
+ _ ->
+ fun (App, Key, Val) -> application:set_env(App, Key, Val, [{persistent, true}]) end
+ end,
try
- [application:set_env(Application, Key, Val)
+ [SetEnv(Application, Key, Val)
|| Config <- ConfigList,
{Application, Items} <- Config,
{Key, Val} <- Items]