summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md16
-rw-r--r--inttest/thooks/fish.erl5
-rw-r--r--inttest/thooks/rebar.config7
-rw-r--r--inttest/thooks/thooks_rt.erl40
-rw-r--r--rebar.config.sample36
-rw-r--r--src/rebar_core.erl12
-rw-r--r--src/rebar_deps.erl26
-rw-r--r--src/rebar_eunit.erl9
-rw-r--r--src/rebar_port_compiler.erl17
-rw-r--r--src/rebar_post_script.erl18
-rw-r--r--src/rebar_pre_script.erl18
11 files changed, 147 insertions, 57 deletions
diff --git a/README.md b/README.md
index b683df1..6b66d22 100644
--- a/README.md
+++ b/README.md
@@ -53,22 +53,6 @@ Do not introduce trailing whitespace.
Do not introduce lines longer than 80 characters.
-### Indentation
-
-To have consistent indentation we have vi modeline/emacs local variable
-headers in rebar's source files. This works automatically with vi.
-With Emacs you have to declare <code>'erlang-indent-level</code>
-set to <code>4</code>
-as a safe local variable value. If not configured Emacs will prompt
-you to save this as part of custom-set-variables:
-
- '(safe-local-variable-values (quote ((erlang-indent-level . 4))))
-You can also tell Emacs to ignore file variables:
-
- (setq enable-local-variables nil
- enable-local-eval nil)
-
-
Writing Commit Messages
-----------------------
diff --git a/inttest/thooks/fish.erl b/inttest/thooks/fish.erl
new file mode 100644
index 0000000..739cb94
--- /dev/null
+++ b/inttest/thooks/fish.erl
@@ -0,0 +1,5 @@
+-module(fish).
+
+-compile(export_all).
+
+fish() -> fish.
diff --git a/inttest/thooks/rebar.config b/inttest/thooks/rebar.config
new file mode 100644
index 0000000..6514818
--- /dev/null
+++ b/inttest/thooks/rebar.config
@@ -0,0 +1,7 @@
+%% pre-scripts
+{pre_hooks, [{clean, "echo preclean >> preclean.out"},
+ {compile, "echo precompile >> precompile.out"}]}.
+
+%% post-scripts
+{post_hooks, [{clean, "echo postclean >> postclean.out"},
+ {compile, "echo postcompile >> postcompile.out"}]}.
diff --git a/inttest/thooks/thooks_rt.erl b/inttest/thooks/thooks_rt.erl
new file mode 100644
index 0000000..52af9f5
--- /dev/null
+++ b/inttest/thooks/thooks_rt.erl
@@ -0,0 +1,40 @@
+-module(thooks_rt).
+
+-include_lib("eunit/include/eunit.hrl").
+-compile(export_all).
+
+files() ->
+ [
+ %% dummy lfe files
+ {copy, "../../rebar", "rebar"},
+ {copy, "rebar.config", "rebar.config"},
+ {copy, "fish.erl", "src/fish.erl"},
+ {create, "ebin/fish.app", app(fish, [fish])}
+ ].
+
+run(_Dir) ->
+ ?assertMatch({ok, _}, retest_sh:run("./rebar -v clean compile", [])),
+ ensure_command_ran_only_once("preclean"),
+ ensure_command_ran_only_once("precompile"),
+ ensure_command_ran_only_once("postclean"),
+ ensure_command_ran_only_once("postcompile"),
+ ok.
+
+ensure_command_ran_only_once(Command) ->
+ File = Command ++ ".out",
+ ?assert(filelib:is_regular(File)),
+ %% ensure that this command only ran once (not for each module)
+ {ok, Content} = file:read_file(File),
+ ?assertEqual(Command ++ "\n", binary_to_list(Content)).
+
+%%
+%% Generate the contents of a simple .app file
+%%
+app(Name, Modules) ->
+ App = {application, Name,
+ [{description, atom_to_list(Name)},
+ {vsn, "1"},
+ {modules, Modules},
+ {registered, []},
+ {applications, [kernel, stdlib]}]},
+ io_lib:format("~p.\n", [App]).
diff --git a/rebar.config.sample b/rebar.config.sample
index 184c16d..50ddc17 100644
--- a/rebar.config.sample
+++ b/rebar.config.sample
@@ -8,18 +8,6 @@
%% Additional library directories to add to the code path
{lib_dirs, []}.
-%% Command to run before compiling
-{compile_pre_script, "./script.sh"}.
-
-%% Command to run after compiling
-{compile_post_script, "./script.sh"}.
-
-%% Command to run before cleaning
-{clean_pre_script, "./script.sh"}.
-
-%% Command to run after cleaning
-{clean_post_script, "./script.sh"}.
-
%% == Erlang Compiler ==
%% Erlang files to compile before the rest. Rebar automatically compiles
@@ -54,14 +42,6 @@
%% more info. Default is `[]'
{port_envs, []}.
-%% Tuple which specifies a pre-compilation script to run, and a filename that
-%% exists as a result of the script running.
-{port_pre_script, {"script.sh", "skipfile"}}.
-
-%% String that specifies a script to run during cleanup. Use this to remove
-%% files/directories created by port_pre_script.
-{port_cleanup_script, "cleanup.sh"}.
-
%% Custom name of the port driver .so file. Defaults to `<Application>_drv.so'.
{so_name, "driver.so"}.
@@ -121,7 +101,7 @@
%% Enable validation of the OTP app module list. Default is 'true'
{validate_app_modules, true}.
-%% == Dependancies ==
+%% == Dependencies ==
%% Where to put any downloaded depandencies. Default is `deps'
{deps_dir, ["deps"]}.
@@ -129,12 +109,22 @@
%% What dependancies we have, depandencies can be of 3 forms, an application
%% name as an atom, eg. mochiweb, a name and a version (from the .app file), or
%% an application name, a version and the SCM details on how to fetch it (SCM
-%% type, location and revision). Rebar currently support git, hg, bzr and svn.
+%% type, location and revision). Rebar currently supports git, hg, bzr and svn.
{deps, [application_name,
{application_name, "1.0.*"},
- {application_name, "1.0.*", {hg, "http://bitbucket.org/basho/rebar/", "f3626d5858a6"}}]}.
+ {application_name, "1.0.*",
+ {git, "git://github.com/basho/rebar.git", {branch, "master"}}}]}.
%% == Subdirectories ==
%% Subdirectories?
{sub_dirs, ["dir1", "dir2"]}.
+
+%% == Pre/Post Command Hooks ==
+
+{pre_hooks, [{clean, "./prepare_package_files.sh"},
+ {compile, "escript generate_headers"}]}.
+
+{post_hooks, [{clean, "touch file1.out"},
+ {eunit, "touch file2.out"},
+ {compile, "touch postcompile.out"}]}.
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index d92af34..42f301f 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -223,7 +223,7 @@ execute(Command, Modules, Config, ModuleFile) ->
case select_modules(Modules, Command, []) of
[] ->
?WARN("'~p' command does not apply to directory ~s\n",
- [Command, rebar_utils:get_cwd()]);
+ [Command, rebar_utils:get_cwd()]);
TargetModules ->
%% Provide some info on where we are
@@ -235,9 +235,11 @@ execute(Command, Modules, Config, ModuleFile) ->
erlang:put(operations, erlang:get(operations) + 1),
%% Run the available modules
+ apply_hooks(pre_hooks, Config, Command),
case catch(run_modules(TargetModules, Command,
Config, ModuleFile)) of
ok ->
+ apply_hooks(post_hooks, Config, Command),
ok;
{error, failed} ->
?FAIL;
@@ -302,6 +304,14 @@ run_modules([Module | Rest], Command, Config, File) ->
{Module, Error}
end.
+apply_hooks(Mode, Config, Command) ->
+ Hooks = rebar_config:get_local(Config, Mode, []),
+ lists:foreach(fun apply_hook/1,
+ [Hook || Hook <- Hooks, element(1, Hook) =:= Command]).
+
+apply_hook({Command, Hook}) ->
+ Msg = lists:flatten(io_lib:format("Command [~p] failed!~n", [Command])),
+ rebar_utils:sh(Hook, [{abort_on_error, Msg}]).
acc_modules(Modules, Command, Config, File) ->
acc_modules(select_modules(Modules, Command, []),
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl
index 22ef09e..01cfad3 100644
--- a/src/rebar_deps.erl
+++ b/src/rebar_deps.erl
@@ -162,9 +162,9 @@ get_deps_dir(App) ->
{true, filename:join([BaseDir, DepsDir, App])}.
get_lib_dir(App) ->
- % Find App amongst the reachable lib directories
- % Returns either the found path or a tagged tuple with a boolean
- % to match get_deps_dir's return type
+ %% Find App amongst the reachable lib directories
+ %% Returns either the found path or a tagged tuple with a boolean
+ %% to match get_deps_dir's return type
case code:lib_dir(App) of
{error, bad_name} -> {false, bad_name};
Path -> {true, Path}
@@ -208,23 +208,23 @@ find_deps(_Mode, [Other | _Rest], _Acc) ->
[Other, rebar_utils:get_cwd()]).
find_dep(Dep) ->
- % Find a dep based on its source,
- % e.g. {git, "https://github.com/mochi/mochiweb.git", "HEAD"}
- % Deps with a source must be found (or fetched) locally.
- % Those without a source may be satisfied from lib directories (get_lib_dir).
+ %% Find a dep based on its source,
+ %% e.g. {git, "https://github.com/mochi/mochiweb.git", "HEAD"}
+ %% Deps with a source must be found (or fetched) locally.
+ %% Those without a source may be satisfied from lib dir (get_lib_dir).
find_dep(Dep, Dep#dep.source).
find_dep(Dep, undefined) ->
- % 'source' is undefined. If Dep is not satisfied locally,
- % go ahead and find it amongst the lib_dir's.
+ %% 'source' is undefined. If Dep is not satisfied locally,
+ %% go ahead and find it amongst the lib_dir's.
case find_dep_in_dir(Dep, get_deps_dir(Dep#dep.app)) of
- {avail, Dir} -> {avail, Dir};
+ {avail, _Dir} = Avail -> Avail;
{missing, _} -> find_dep_in_dir(Dep, get_lib_dir(Dep#dep.app))
end;
find_dep(Dep, _Source) ->
- % _Source is defined. Regardless of what it is, we must find it
- % locally satisfied or fetch it from the original source
- % into the project's deps
+ %% _Source is defined. Regardless of what it is, we must find it
+ %% locally satisfied or fetch it from the original source
+ %% into the project's deps
find_dep_in_dir(Dep, get_deps_dir(Dep#dep.app)).
find_dep_in_dir(_Dep, {false, Dir}) ->
diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl
index aee487c..d4ebe0c 100644
--- a/src/rebar_eunit.erl
+++ b/src/rebar_eunit.erl
@@ -191,11 +191,12 @@ eunit_config(Config) ->
eqc_opts() ->
- define_if('PROPER', is_lib_avail(is_eqc_avail, eqc,
- "eqc.hrl", "QuickCheck")).
+ define_if('EQC', is_lib_avail(is_eqc_avail, eqc,
+ "eqc.hrl", "QuickCheck")).
+
proper_opts() ->
- define_if('EQC', is_lib_avail(is_proper_avail, proper,
- "proper.hrl", "PropEr")).
+ define_if('PROPER', is_lib_avail(is_proper_avail, proper,
+ "proper.hrl", "PropEr")).
define_if(Def, true) -> [{d, Def}];
define_if(_Def, false) -> [].
diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index b230af1..a281b29 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -182,6 +182,15 @@ run_precompile_hook(Config, Env) ->
undefined ->
ok;
{Script, BypassFileName} ->
+ ?CONSOLE(
+ <<
+ "WARNING: option deprecated~n"
+ "Config option 'port_pre_script' has been deprecated "
+ "in favor of ~n{pre_hooks, [{compile, \"script\"}]}."
+ "~nskipfile support has also been removed. Add skipfile"
+ " logic to the~nscript instead.~nFuture builds of rebar"
+ " will remove the option 'port_pre_script'.~n~n"
+ >>, []),
case filelib:is_regular(BypassFileName) of
false ->
?CONSOLE("Running ~s\n", [Script]),
@@ -198,6 +207,14 @@ run_cleanup_hook(Config) ->
undefined ->
ok;
Script ->
+ ?CONSOLE(
+ <<
+ "WARNING: option deprecated~n"
+ "Config option 'port_pre_script' has been deprecated "
+ "in favor of ~n{post_hooks, [{clean, \"script\"}]}."
+ "~nFuture builds of rebar will remove the option "
+ "'port_pre_script'.~n~n"
+ >>, []),
?CONSOLE("Running ~s\n", [Script]),
{ok, _} = rebar_utils:sh(Script, []),
ok
diff --git a/src/rebar_post_script.erl b/src/rebar_post_script.erl
index c7f2d01..39185a9 100644
--- a/src/rebar_post_script.erl
+++ b/src/rebar_post_script.erl
@@ -51,6 +51,24 @@ execute_post_script(Config, Key) ->
undefined ->
ok;
Script ->
+ deprecated(Key),
{ok, _} = rebar_utils:sh(Script, []),
ok
end.
+
+deprecated(compile_post_script) ->
+ ?CONSOLE(
+ <<
+ "WARNING: option deprecated~n"
+ "Config option 'compile_post_script' has been deprecated in favor"
+ " of ~noption {post_hooks, [{compile, \"script\"}]}.~nFuture builds "
+ "of rebar will remove the option 'compile_post_script'.~n~n"
+ >>, []);
+deprecated(clean_post_script) ->
+ ?CONSOLE(
+ <<
+ "WARNING: option deprecated~n"
+ "Config option 'clean_post_script' has been deprecated in favor"
+ " of ~noption {post_hooks, [{clean, \"script\"}]}.~nFuture builds "
+ "of rebar will remove the option 'clean_post_script'.~n~n"
+ >>, []).
diff --git a/src/rebar_pre_script.erl b/src/rebar_pre_script.erl
index 9097807..b23f469 100644
--- a/src/rebar_pre_script.erl
+++ b/src/rebar_pre_script.erl
@@ -51,6 +51,24 @@ execute_pre_script(Config, Key) ->
undefined ->
ok;
Script ->
+ deprecated(Key),
{ok, _} = rebar_utils:sh(Script, []),
ok
end.
+
+deprecated(compile_pre_script) ->
+ ?CONSOLE(
+ <<
+ "WARNING: option deprecated~n"
+ "Config option 'compile_pre_script' has been deprecated in favor"
+ " of ~n{pre_hooks, [{compile, \"script\"}]}.~nFuture builds of"
+ " rebar will remove the option 'compile_pre_script'.~n~n"
+ >>, []);
+deprecated(clean_pre_script) ->
+ ?CONSOLE(
+ <<
+ "WARNING: option deprecated~n"
+ "Config option 'clean_pre_script' has been deprecated in favor"
+ " of ~n{pre_hooks, [{clean, \"script\"}]}.~nFuture builds of"
+ " rebar will remove the option 'clean_pre_script'.~n~n"
+ >>, []).