summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/rebar.erl14
-rw-r--r--src/rebar_config.erl16
-rw-r--r--src/rebar_core.erl188
-rw-r--r--src/rebar_erlc_compiler.erl45
-rw-r--r--src/rebar_file_utils.erl6
-rw-r--r--src/rebar_qc.erl5
-rw-r--r--src/rebar_rel_utils.erl8
-rw-r--r--src/rebar_reltool.erl33
-rw-r--r--src/rebar_require_vsn.erl5
-rw-r--r--src/rebar_shell.erl55
-rw-r--r--src/rebar_utils.erl8
11 files changed, 241 insertions, 142 deletions
diff --git a/src/rebar.erl b/src/rebar.erl
index 618cce8..a43da5f 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -207,9 +207,18 @@ help() ->
" ~p~n"
" ~p~n"
" ~p~n"
- " ~p~n",
+ " ~p~n"
+ " ~p~n"
+ " ~p~n"
+ " ~p~n"
+ "Core command line options:~n"
+ " apps=app1,app2 (specify apps to process)~n"
+ " skip_apps=app1,app2 (specify apps to skip)~n",
[
{recursive_cmds, []},
+ {require_erts_vsn, ".*"},
+ {require_otp_vsn, ".*"},
+ {require_min_otp_vsn, ".*"},
{lib_dirs, []},
{sub_dirs, ["dir1", "dir2"]},
{plugins, [plugin1, plugin2]},
@@ -400,6 +409,9 @@ qc Test QuickCheck properties
xref Run cross reference analysis
+shell Start a shell similar to
+ 'erl -pa ebin -pa deps/*/ebin'
+
help Show the program options
version Show version information
">>,
diff --git a/src/rebar_config.erl b/src/rebar_config.erl
index 10c6483..1c90d22 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -39,13 +39,21 @@
-include("rebar.hrl").
+-ifdef(namespaced_types).
+% dict:dict() exists starting from Erlang 17.
+-type rebar_dict() :: dict:dict().
+-else.
+% dict() has been obsoleted in Erlang 17 and deprecated in 18.
+-type rebar_dict() :: dict().
+-endif.
+
-record(config, { dir :: file:filename(),
opts = [] :: list(),
- globals = new_globals() :: dict(),
- envs = new_env() :: dict(),
+ globals = new_globals() :: rebar_dict(),
+ envs = new_env() :: rebar_dict(),
%% cross-directory/-command config
- skip_dirs = new_skip_dirs() :: dict(),
- xconf = new_xconf() :: dict() }).
+ skip_dirs = new_skip_dirs() :: rebar_dict(),
+ xconf = new_xconf() :: rebar_dict() }).
-export_type([config/0]).
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 81b9a6d..3a4f205 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -88,7 +88,7 @@ process_commands([Command | Rest], ParentConfig) ->
%% path from inside a subdirectory.
true = rebar_utils:expand_code_path(),
{ParentConfig2, _DirSet} = process_dir(rebar_utils:get_cwd(),
- ParentConfig1, Command,
+ Command, ParentConfig1,
sets:new()),
case get_operations(ParentConfig2) of
Operations ->
@@ -117,18 +117,13 @@ process_commands([Command | Rest], ParentConfig) ->
end,
process_commands(Rest, ParentConfig4).
-process_dir(Dir, ParentConfig, Command, DirSet) ->
+process_dir(Dir, Command, ParentConfig, DirSet) ->
case filelib:is_dir(Dir) of
false ->
?WARN("Skipping non-existent sub-dir: ~p\n", [Dir]),
{ParentConfig, DirSet};
true ->
- maybe_process_dir(Dir, ParentConfig, Command, DirSet)
- end.
-
-maybe_process_dir(Dir, ParentConfig, Command, DirSet) ->
- case should_cd_into_dir(Dir, ParentConfig, Command) of
- true ->
+ WouldCd = would_cd_into_dir(Dir, Command, ParentConfig),
ok = file:set_cwd(Dir),
Config = maybe_load_local_config(Dir, ParentConfig),
@@ -143,63 +138,89 @@ maybe_process_dir(Dir, ParentConfig, Command, DirSet) ->
%% set of modules to process this dir.
{ok, AvailModuleSets} = application:get_env(rebar, modules),
ModuleSet = choose_module_set(AvailModuleSets, Dir),
- skip_or_process_dir(ModuleSet, Config, CurrentCodePath,
- Dir, Command, DirSet);
+ skip_or_process_dir(Dir, Command, Config, DirSet, CurrentCodePath,
+ ModuleSet, WouldCd)
+ end.
+
+would_cd_into_dir(Dir, Command, Config) ->
+ case would_cd_into_dir1(Dir, Command, Config) of
+ true ->
+ would_cd;
false ->
- {ParentConfig, DirSet}
+ would_not_cd
end.
-should_cd_into_dir(Dir, Config, Command) ->
+would_cd_into_dir1(Dir, Command, Config) ->
rebar_utils:processing_base_dir(Config, Dir) orelse
rebar_config:is_recursive(Config) orelse
- is_recursive_command(Config, Command).
+ is_recursive_command(Command, Config) orelse
+ is_generate_in_rel_dir(Command, Dir).
-is_recursive_command(Config, Command) ->
+%% Check whether the command is part of the built-in (or extended via
+%% rebar.config) list of default-recursive commands.
+is_recursive_command(Command, Config) ->
{ok, AppCmds} = application:get_env(rebar, recursive_cmds),
ConfCmds = rebar_config:get_local(Config, recursive_cmds, []),
RecursiveCmds = AppCmds ++ ConfCmds,
lists:member(Command, RecursiveCmds).
-skip_or_process_dir({[], undefined}=ModuleSet, Config, CurrentCodePath,
- Dir, Command, DirSet) ->
- process_dir1(Dir, Command, DirSet, Config, CurrentCodePath, ModuleSet);
-skip_or_process_dir({_, ModuleSetFile}=ModuleSet, Config, CurrentCodePath,
- Dir, Command, DirSet) ->
- case lists:suffix(".app.src", ModuleSetFile)
- orelse lists:suffix(".app", ModuleSetFile) of
+%% If the directory we're about to process contains
+%% reltool.config[.script] and the command to be applied is
+%% 'generate', then it's safe to process. We do this to retain the
+%% behavior of specifying {sub_dirs, ["rel"]} and have "rebar generate"
+%% pick up rel/reltool.config[.script]. Without this workaround you'd
+%% have to run "rebar -r generate" (which you don't want to do if you
+%% have deps or other sub_dirs) or "cd rel && rebar generate".
+is_generate_in_rel_dir(generate, Dir) ->
+ case rebar_rel_utils:is_rel_dir(Dir) of
+ {true, _} ->
+ true;
+ false ->
+ false
+ end;
+is_generate_in_rel_dir(_, _) ->
+ false.
+
+skip_or_process_dir(Dir, Command, Config, DirSet, CurrentCodePath,
+ {[], undefined}=ModuleSet, WouldCd) ->
+ process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, ModuleSet,
+ WouldCd);
+skip_or_process_dir(Dir, Command, Config, DirSet, CurrentCodePath,
+ {_, File}=ModuleSet, WouldCd) ->
+ case lists:suffix(".app.src", File)
+ orelse lists:suffix(".app", File) of
true ->
%% .app or .app.src file, check if is_skipped_app
- skip_or_process_dir1(ModuleSetFile, ModuleSet,
- Config, CurrentCodePath, Dir,
- Command, DirSet);
+ skip_or_process_dir1(Dir, Command, Config, DirSet, CurrentCodePath,
+ ModuleSet, WouldCd, File);
false ->
%% not an app dir, no need to consider apps=/skip_apps=
- process_dir1(Dir, Command, DirSet, Config,
- CurrentCodePath, ModuleSet)
+ process_dir1(Dir, Command, Config, DirSet, CurrentCodePath,
+ ModuleSet, WouldCd)
end.
-skip_or_process_dir1(AppFile, ModuleSet, Config, CurrentCodePath,
- Dir, Command, DirSet) ->
+skip_or_process_dir1(Dir, Command, Config, DirSet, CurrentCodePath, ModuleSet,
+ WouldCd, AppFile) ->
case rebar_app_utils:is_skipped_app(Config, AppFile) of
{Config1, {true, _SkippedApp}} when Command == 'update-deps' ->
%% update-deps does its own app skipping. Unfortunately there's no
%% way to signal this to rebar_core, so we have to explicitly do it
%% here... Otherwise if you use app=, it'll skip the toplevel
%% directory and nothing will be updated.
- process_dir1(Dir, Command, DirSet, Config1,
- CurrentCodePath, ModuleSet);
+ process_dir1(Dir, Command, Config1, DirSet, CurrentCodePath,
+ ModuleSet, WouldCd);
{Config1, {true, SkippedApp}} ->
?DEBUG("Skipping app: ~p~n", [SkippedApp]),
- Config2 = increment_operations(Config1),
- {Config2, DirSet};
+ {increment_operations(Config1), DirSet};
{Config1, false} ->
- process_dir1(Dir, Command, DirSet, Config1,
- CurrentCodePath, ModuleSet)
+ process_dir1(Dir, Command, Config1, DirSet, CurrentCodePath,
+ ModuleSet, WouldCd)
end.
-process_dir1(Dir, Command, DirSet, Config, CurrentCodePath,
- {DirModules, ModuleSetFile}) ->
+process_dir1(Dir, Command, Config, DirSet, CurrentCodePath,
+ {DirModules, File}, WouldCd) ->
Config0 = rebar_config:set_xconf(Config, current_command, Command),
+
%% Get the list of modules for "any dir". This is a catch-all list
%% of modules that are processed in addition to modules associated
%% with this directory type. These any_dir modules are processed
@@ -210,8 +231,7 @@ process_dir1(Dir, Command, DirSet, Config, CurrentCodePath,
%% Invoke 'preprocess' on the modules -- this yields a list of other
%% directories that should be processed _before_ the current one.
- {Config1, Predirs} = acc_modules(Modules, preprocess, Config0,
- ModuleSetFile),
+ {Config1, Predirs} = acc_modules(Modules, preprocess, Config0, File),
%% Remember associated pre-dirs (used for plugin lookup)
PredirsAssoc = remember_cwd_predirs(Dir, Predirs),
@@ -219,55 +239,33 @@ process_dir1(Dir, Command, DirSet, Config, CurrentCodePath,
%% Get the list of plug-in modules from rebar.config. These
%% modules may participate in preprocess and postprocess.
{ok, PluginModules} = plugin_modules(Config1, PredirsAssoc),
+ AllModules = Modules ++ PluginModules,
- {Config2, PluginPredirs} = acc_modules(PluginModules, preprocess,
- Config1, ModuleSetFile),
+ {Config2, PluginPredirs} = acc_modules(PluginModules, preprocess, Config1,
+ File),
AllPredirs = Predirs ++ PluginPredirs,
?DEBUG("Predirs: ~p\n", [AllPredirs]),
- {Config3, DirSet2} = process_each(AllPredirs, Command, Config2,
- ModuleSetFile, DirSet),
+ {Config3, DirSet2} = process_each(AllPredirs, Command, Config2, DirSet,
+ File),
%% Make sure the CWD is reset properly; processing the dirs may have
%% caused it to change
ok = file:set_cwd(Dir),
- %% Check that this directory is not on the skip list
- Config7 = case rebar_config:is_skip_dir(Config3, Dir) of
- true ->
- %% Do not execute the command on the directory, as some
- %% module has requested a skip on it.
- ?INFO("Skipping ~s in ~s\n", [Command, Dir]),
- Config3;
-
- false ->
- %% Check for and get command specific environments
- {Config4, Env} = setup_envs(Config3, Modules),
-
- %% Execute any before_command plugins on this directory
- Config5 = execute_pre(Command, PluginModules,
- Config4, ModuleSetFile, Env),
-
- %% Execute the current command on this directory
- Config6 = execute(Command, Modules ++ PluginModules,
- Config5, ModuleSetFile, Env),
-
- %% Execute any after_command plugins on this directory
- execute_post(Command, PluginModules,
- Config6, ModuleSetFile, Env)
- end,
+ %% Maybe apply command to Dir
+ Config4 = maybe_execute(Dir, Command, Config3, Modules, PluginModules,
+ AllModules, File, WouldCd),
%% Mark the current directory as processed
DirSet3 = sets:add_element(Dir, DirSet2),
%% Invoke 'postprocess' on the modules. This yields a list of other
%% directories that should be processed _after_ the current one.
- {Config8, Postdirs} = acc_modules(Modules ++ PluginModules, postprocess,
- Config7, ModuleSetFile),
+ {Config5, Postdirs} = acc_modules(AllModules, postprocess, Config4, File),
?DEBUG("Postdirs: ~p\n", [Postdirs]),
- Res = process_each(Postdirs, Command, Config8,
- ModuleSetFile, DirSet3),
+ Res = process_each(Postdirs, Command, Config5, DirSet3, File),
%% Make sure the CWD is reset properly; processing the dirs may have
%% caused it to change
@@ -280,6 +278,33 @@ process_dir1(Dir, Command, DirSet, Config, CurrentCodePath,
%% Return the updated {config, dirset} as result
Res.
+maybe_execute(Dir, Command, Config, Modules, PluginModules, AllModules, File,
+ would_cd) ->
+ %% Check that this directory is not on the skip list
+ case rebar_config:is_skip_dir(Config, Dir) of
+ true ->
+ %% Do not execute the command on the directory, as some
+ %% module has requested a skip on it.
+ ?INFO("Skipping ~s in ~s\n", [Command, Dir]),
+ Config;
+
+ false ->
+ %% Check for and get command specific environments
+ {Config1, Env} = setup_envs(Config, Modules),
+
+ %% Execute any before_command plugins on this directory
+ Config2 = execute_pre(Command, PluginModules, Config1, File, Env),
+
+ %% Execute the current command on this directory
+ Config3 = execute(Command, AllModules, Config2, File, Env),
+
+ %% Execute any after_command plugins on this directory
+ execute_post(Command, PluginModules, Config3, File, Env)
+ end;
+maybe_execute(_Dir, _Command, Config, _Modules, _PluginModules, _AllModules,
+ _File, would_not_cd) ->
+ Config.
+
remember_cwd_predirs(Cwd, Predirs) ->
Store = fun(Dir, Dict) ->
case dict:find(Dir, Dict) of
@@ -310,21 +335,21 @@ maybe_load_local_config(Dir, ParentConfig) ->
%% Given a list of directories and a set of previously processed directories,
%% process each one we haven't seen yet
%%
-process_each([], _Command, Config, _ModuleSetFile, DirSet) ->
+process_each([], _Command, Config, DirSet, _File) ->
%% reset cached (setup_env) envs
Config1 = rebar_config:reset_envs(Config),
{Config1, DirSet};
-process_each([Dir | Rest], Command, Config, ModuleSetFile, DirSet) ->
+process_each([Dir | Rest], Command, Config, DirSet, File) ->
case sets:is_element(Dir, DirSet) of
true ->
?DEBUG("Skipping ~s; already processed!\n", [Dir]),
- process_each(Rest, Command, Config, ModuleSetFile, DirSet);
+ process_each(Rest, Command, Config, DirSet, File);
false ->
- {Config1, DirSet2} = process_dir(Dir, Config, Command, DirSet),
+ {Config1, DirSet2} = process_dir(Dir, Command, Config, DirSet),
Config2 = rebar_config:clean_config(Config, Config1),
%% reset cached (setup_env) envs
Config3 = rebar_config:reset_envs(Config2),
- process_each(Rest, Command, Config3, ModuleSetFile, DirSet2)
+ process_each(Rest, Command, Config3, DirSet2, File)
end.
%%
@@ -358,20 +383,21 @@ execute_post(Command, Modules, Config, ModuleFile, Env) ->
execute_plugin_hook(Hook, Command, Modules, Config, ModuleFile, Env) ->
HookFunction = list_to_atom(Hook ++ atom_to_list(Command)),
- execute(HookFunction, Modules, Config, ModuleFile, Env).
+ execute(HookFunction, hook, Modules, Config, ModuleFile, Env).
%%
%% Execute a command across all applicable modules
%%
execute(Command, Modules, Config, ModuleFile, Env) ->
+ execute(Command, not_a_hook, Modules, Config, ModuleFile, Env).
+
+execute(Command, Type, Modules, Config, ModuleFile, Env) ->
case select_modules(Modules, Command, []) of
[] ->
- Cmd = atom_to_list(Command),
- case lists:prefix("pre_", Cmd)
- orelse lists:prefix("post_", Cmd) of
- true ->
+ case Type of
+ hook ->
ok;
- false ->
+ not_a_hook ->
?WARN("'~p' command does not apply to directory ~s\n",
[Command, rebar_utils:get_cwd()])
end,
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index 75d47fb..5f541d9 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -47,6 +47,14 @@
info = {[], []} :: erlc_info()
}).
+-ifdef(namespaced_types).
+% digraph:digraph() exists starting from Erlang 17.
+-type rebar_digraph() :: digraph:digraph().
+-else.
+% digraph() has been obsoleted in Erlang 17 and deprecated in 18.
+-type rebar_digraph() :: digraph().
+-endif.
+
%% ===================================================================
%% Public API
%% ===================================================================
@@ -134,12 +142,13 @@ test_compile(Config, Cmd, OutDir) ->
%% Obtain all the test modules for inclusion in the compile stage.
TestErls = rebar_utils:find_files("test", ".*\\.erl\$"),
+ ErlOpts = rebar_utils:erl_opts(Config),
+ {Config1, ErlOpts1} = test_compile_config_and_opts(Config, ErlOpts, Cmd),
+
%% Copy source files to eunit dir for cover in case they are not directly
%% in src but in a subdirectory of src. Cover only looks in cwd and ../src
%% for source files. Also copy files from src_dirs.
- ErlOpts = rebar_utils:erl_opts(Config),
-
- SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts)),
+ SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts1)),
SrcErls = lists:foldl(
fun(Dir, Acc) ->
Files = rebar_utils:find_files(Dir, ".*\\.erl\$"),
@@ -172,8 +181,7 @@ test_compile(Config, Cmd, OutDir) ->
%% Compile erlang code to OutDir, using a tweaked config
%% with appropriate defines for eunit, and include all the test modules
%% as well.
- ok = doterl_compile(test_compile_config(Config, ErlOpts, Cmd),
- OutDir, TestErls, ErlOpts),
+ ok = doterl_compile(Config1, OutDir, TestErls, ErlOpts1),
{ok, SrcErls}.
@@ -217,21 +225,22 @@ info_help(Description) ->
{yrl_first_files, []}
]).
-test_compile_config(Config, ErlOpts, Cmd) ->
+test_compile_config_and_opts(Config, ErlOpts, Cmd) ->
{Config1, TriqOpts} = triq_opts(Config),
{Config2, PropErOpts} = proper_opts(Config1),
{Config3, EqcOpts} = eqc_opts(Config2),
OptsAtom = list_to_atom(Cmd ++ "_compile_opts"),
- EunitOpts = rebar_config:get_list(Config3, OptsAtom, []),
+ TestOpts = rebar_config:get_list(Config3, OptsAtom, []),
Opts0 = [{d, 'TEST'}] ++
- ErlOpts ++ EunitOpts ++ TriqOpts ++ PropErOpts ++ EqcOpts,
+ ErlOpts ++ TestOpts ++ TriqOpts ++ PropErOpts ++ EqcOpts,
Opts = [O || O <- Opts0, O =/= no_debug_info],
Config4 = rebar_config:set(Config3, erl_opts, Opts),
FirstFilesAtom = list_to_atom(Cmd ++ "_first_files"),
FirstErls = rebar_config:get_list(Config4, FirstFilesAtom, []),
- rebar_config:set(Config4, erl_first_files, FirstErls).
+ Config5 = rebar_config:set(Config4, erl_first_files, FirstErls),
+ {Config5, Opts}.
triq_opts(Config) ->
{NewConfig, IsAvail} = is_lib_avail(Config, is_triq_avail, triq,
@@ -408,17 +417,17 @@ init_erlcinfo(Config, Erls) ->
update_erlcinfo(G, Source, Dirs) ->
case digraph:vertex(G, Source) of
{_, LastUpdated} ->
- LastModified = filelib:last_modified(Source),
- if LastModified == 0 ->
+ case filelib:last_modified(Source) of
+ 0 ->
%% The file doesn't exist anymore,
%% erase it from the graph.
%% All the edges will be erased automatically.
digraph:del_vertex(G, Source),
modified;
- LastUpdated < LastModified ->
- modify_erlcinfo(G, Source, Dirs);
+ LastModified when LastUpdated < LastModified ->
+ modify_erlcinfo(G, Source, Dirs),
modified;
- true ->
+ _ ->
unmodified
end;
false ->
@@ -521,24 +530,24 @@ expand_file_names(Files, Dirs) ->
end
end, Files).
--spec get_parents(digraph(), file:filename()) -> [file:filename()].
+-spec get_parents(rebar_digraph(), file:filename()) -> [file:filename()].
get_parents(G, Source) ->
%% Return all files which the Source depends upon.
digraph_utils:reachable_neighbours([Source], G).
--spec get_children(digraph(), file:filename()) -> [file:filename()].
+-spec get_children(rebar_digraph(), file:filename()) -> [file:filename()].
get_children(G, Source) ->
%% Return all files dependent on the Source.
digraph_utils:reaching_neighbours([Source], G).
-spec internal_erl_compile(rebar_config:config(), file:filename(),
file:filename(), list(),
- digraph()) -> 'ok' | 'skipped'.
+ rebar_digraph()) -> 'ok' | 'skipped'.
internal_erl_compile(Config, Source, OutDir, ErlOpts, G) ->
%% Determine the target name and includes list by inspecting the source file
Module = filename:basename(Source, ".erl"),
Parents = get_parents(G, Source),
- log_files(?FMT("~s depends on", [Source]), Parents),
+ log_files(?FMT("Dependencies of ~s", [Source]), Parents),
%% Construct the target filename
Target = filename:join([OutDir | string:tokens(Module, ".")]) ++ ".beam",
diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl
index fcd9c5e..9ddbf27 100644
--- a/src/rebar_file_utils.erl
+++ b/src/rebar_file_utils.erl
@@ -46,7 +46,7 @@ rm_rf(Target) ->
{unix, _} ->
EscTarget = escape_spaces(Target),
{ok, []} = rebar_utils:sh(?FMT("rm -rf ~s", [EscTarget]),
- [{use_stdout, false}, return_on_error]),
+ [{use_stdout, false}, abort_on_error]),
ok;
{win32, _} ->
Filelist = filelib:wildcard(Target),
@@ -67,7 +67,7 @@ cp_r(Sources, Dest) ->
SourceStr = string:join(EscSources, " "),
{ok, []} = rebar_utils:sh(?FMT("cp -R ~s \"~s\"",
[SourceStr, Dest]),
- [{use_stdout, false}, return_on_error]),
+ [{use_stdout, false}, abort_on_error]),
ok;
{win32, _} ->
lists:foreach(fun(Src) -> ok = cp_r_win32(Src,Dest) end, Sources),
@@ -81,7 +81,7 @@ mv(Source, Dest) ->
EscSource = escape_spaces(Source),
EscDest = escape_spaces(Dest),
{ok, []} = rebar_utils:sh(?FMT("mv ~s ~s", [EscSource, EscDest]),
- [{use_stdout, false}, return_on_error]),
+ [{use_stdout, false}, abort_on_error]),
ok;
{win32, _} ->
{ok, R} = rebar_utils:sh(
diff --git a/src/rebar_qc.erl b/src/rebar_qc.erl
index 99d37a2..1976722 100644
--- a/src/rebar_qc.erl
+++ b/src/rebar_qc.erl
@@ -73,7 +73,10 @@ info(help, qc) ->
[
{qc_compile_opts, []},
{qc_first_files, []}
- ]).
+ ]);
+info(help, clean) ->
+ Description = ?FMT("Delete QuickCheck test dir (~s)", [?QC_DIR]),
+ ?CONSOLE("~s.~n", [Description]).
-define(TRIQ_MOD, triq).
-define(EQC_MOD, eqc).
diff --git a/src/rebar_rel_utils.erl b/src/rebar_rel_utils.erl
index 085dbd9..5d99948 100644
--- a/src/rebar_rel_utils.erl
+++ b/src/rebar_rel_utils.erl
@@ -37,6 +37,7 @@
get_rel_file_path/2,
load_config/2,
get_sys_tuple/1,
+ get_excl_lib_tuple/1,
get_target_dir/2,
get_root_dir/2,
get_target_parent_dir/2]).
@@ -144,6 +145,13 @@ get_sys_tuple(ReltoolConfig) ->
end.
%%
+%% Look for the {excl_lib, ...} tuple in sys tuple of the reltool.config file.
+%% Without this present, return false.
+%%
+get_excl_lib_tuple(ReltoolConfig) ->
+ lists:keyfind(excl_lib, 1, element(2, get_sys_tuple(ReltoolConfig))).
+
+%%
%% Look for {target_dir, TargetDir} in the reltool config file; if none is
%% found, use the name of the release as the default target directory.
%%
diff --git a/src/rebar_reltool.erl b/src/rebar_reltool.erl
index 9f9488e..fdaa7e0 100644
--- a/src/rebar_reltool.erl
+++ b/src/rebar_reltool.erl
@@ -147,15 +147,12 @@ process_overlay(Config, ReltoolConfig) ->
OverlayVars1),
%% Finally, overlay the files specified by the overlay section
- case lists:keyfind(overlay, 1, ReltoolConfig) of
- {overlay, Overlay} when is_list(Overlay) ->
+ case overlay_files(ReltoolConfig) of
+ [] ->
+ ok;
+ Overlay ->
execute_overlay(Overlay, OverlayVars, rebar_utils:get_cwd(),
- TargetDir);
- false ->
- ?INFO("No {overlay, [...]} found in reltool.config.\n", []);
- _ ->
- ?ABORT("{overlay, [...]} entry in reltool.config "
- "must be a list.\n", [])
+ TargetDir)
end.
%%
@@ -292,6 +289,26 @@ dump_spec(Config, Spec) ->
end.
+overlay_files(ReltoolConfig) ->
+ Original = case lists:keyfind(overlay, 1, ReltoolConfig) of
+ {overlay, Overlay} when is_list(Overlay) ->
+ Overlay;
+ false ->
+ ?INFO("No {overlay, [...]} found in reltool.config.\n", []),
+ [];
+ _ ->
+ ?ABORT("{overlay, [...]} entry in reltool.config "
+ "must be a list.\n", [])
+ end,
+ SlimAddition = case rebar_rel_utils:get_excl_lib_tuple(ReltoolConfig) of
+ {excl_lib, otp_root} ->
+ [{create, "releases/{{rel_vsn}}/runner_script.data",
+ "slim\n"}];
+ false ->
+ []
+ end,
+ Original ++ SlimAddition.
+
%% TODO: Merge functionality here with rebar_templater
execute_overlay([], _Vars, _BaseDir, _TargetDir) ->
diff --git a/src/rebar_require_vsn.erl b/src/rebar_require_vsn.erl
index 385f55c..af805c8 100644
--- a/src/rebar_require_vsn.erl
+++ b/src/rebar_require_vsn.erl
@@ -34,7 +34,8 @@
eunit/2]).
%% for internal use only
--export([info/2]).
+-export([info/2,
+ version_tuple/2]).
%% ===================================================================
%% Public API
@@ -110,7 +111,7 @@ check_versions(Config) ->
end.
version_tuple(OtpRelease, Type) ->
- case re:run(OtpRelease, "R(\\d+)B?-?(\\d+)?", [{capture, all, list}]) of
+ case re:run(OtpRelease, "R?(\\d+)B?-?(\\d+)?", [{capture, all, list}]) of
{match, [_Full, Maj, Min]} ->
{list_to_integer(Maj), list_to_integer(Min)};
{match, [_Full, Maj]} ->
diff --git a/src/rebar_shell.erl b/src/rebar_shell.erl
index 2dbf4a0..348e540 100644
--- a/src/rebar_shell.erl
+++ b/src/rebar_shell.erl
@@ -30,27 +30,40 @@
-include("rebar.hrl").
--export([shell/2]).
+-export([shell/2, info/2]).
+
+%% NOTE:
+%% this is an attempt to replicate `erl -pa ./ebin -pa deps/*/ebin`. it is
+%% mostly successful but does stop and then restart the user io system to get
+%% around issues with rebar being an escript and starting in `noshell` mode.
+%% it also lacks the ctrl-c interrupt handler that `erl` features. ctrl-c will
+%% immediately kill the script. ctrl-g, however, works fine
shell(_Config, _AppFile) ->
- ?CONSOLE("NOTICE: Using experimental 'shell' command~n", []),
- %% backwards way to say we only want this executed
- %% for the "top level" directory
- case is_deps_dir(rebar_utils:get_cwd()) of
- false ->
- true = code:add_pathz(rebar_utils:ebin_dir()),
- user_drv:start(),
- %% this call never returns (until user quits shell)
- shell:server(false, false);
- true ->
- ok
- end,
- ok.
+ true = code:add_pathz(rebar_utils:ebin_dir()),
+ %% terminate the current user
+ ok = supervisor:terminate_child(kernel_sup, user),
+ %% start a new shell (this also starts a new user under the correct group)
+ user_drv:start(),
+ %% enable error_logger's tty output
+ ok = error_logger:swap_handler(tty),
+ %% disable the simple error_logger (which may have been added multiple
+ %% times). removes at most the error_logger added by init and the
+ %% error_logger added by the tty handler
+ ok = remove_error_handler(3),
+ %% this call never returns (until user quits shell)
+ timer:sleep(infinity).
+
+info(help, shell) ->
+ ?CONSOLE(
+ "Start a shell with project and deps preloaded similar to~n"
+ "'erl -pa ebin -pa deps/*/ebin'.~n",
+ []).
-is_deps_dir(Dir) ->
- case lists:reverse(filename:split(Dir)) of
- [_, "deps" | _] ->
- true;
- _V ->
- false
- end.
+remove_error_handler(0) ->
+ ?WARN("Unable to remove simple error_logger handler~n", []);
+remove_error_handler(N) ->
+ case gen_event:delete_handler(error_logger, error_logger, []) of
+ {error, module_not_found} -> ok;
+ {error_logger, _} -> remove_error_handler(N-1)
+ end. \ No newline at end of file
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 6b8e874..c02d200 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -335,7 +335,8 @@ processing_base_dir(Config) ->
processing_base_dir(Config, Cwd).
processing_base_dir(Config, Dir) ->
- Dir =:= base_dir(Config).
+ AbsDir = filename:absname(Dir),
+ AbsDir =:= base_dir(Config).
%% ====================================================================
%% Internal functions
@@ -417,8 +418,9 @@ log_msg_and_abort(Message) ->
-spec log_and_abort(string(), {integer(), string()}) -> no_return().
log_and_abort(Command, {Rc, Output}) ->
- ?ABORT("~s failed with error: ~w and output:~n~s~n",
- [Command, Rc, Output]).
+ ?ABORT("sh(~s)~n"
+ "failed with return code ~w and the following output:~n"
+ "~s~n", [Command, Rc, Output]).
sh_loop(Port, Fun, Acc) ->
receive