summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--.travis.yml2
-rw-r--r--Makefile1
-rw-r--r--RELEASE-NOTES.md33
-rw-r--r--THANKS1
-rw-r--r--dialyzer_reference4
-rw-r--r--ebin/rebar.app6
-rw-r--r--rebar.config.sample5
-rw-r--r--src/rebar.erl91
-rw-r--r--src/rebar_app_utils.erl9
-rw-r--r--src/rebar_base_compiler.erl44
-rw-r--r--src/rebar_ct.erl10
-rw-r--r--src/rebar_deps.erl2
-rw-r--r--src/rebar_erlc_compiler.erl467
-rw-r--r--src/rebar_erlydtl_compiler.erl33
-rw-r--r--src/rebar_eunit.erl62
-rw-r--r--src/rebar_getopt.erl (renamed from src/getopt.erl)90
-rw-r--r--src/rebar_mustache.erl (renamed from src/mustache.erl)10
-rw-r--r--src/rebar_qc.erl7
-rw-r--r--src/rebar_templater.erl2
-rw-r--r--src/rebar_upgrade.erl8
-rw-r--r--src/rebar_utils.erl6
-rw-r--r--src/rebar_xref.erl5
23 files changed, 671 insertions, 229 deletions
diff --git a/.gitignore b/.gitignore
index ef672fe..165948e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,9 +4,9 @@ rebar
*.orig
.*.swp
rt.work
-.hgignore
.test
dialyzer_warnings
rebar.cmd
.eunit
deps
+.rebar/*
diff --git a/.travis.yml b/.travis.yml
index 191d337..a7eedb4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,7 @@
language: erlang
otp_release:
+ - R16B02
+ - R16B01
- R16B
- R15B01
- R15B
diff --git a/Makefile b/Makefile
index 1aeb6ad..db7d519 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,7 @@ all:
clean:
@rm -rf rebar ebin/*.beam inttest/rt.work rt.work .eunit
+ @rm -f .rebarinfo
distclean: clean
@rm -f dialyzer_warnings
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
new file mode 100644
index 0000000..bdfb3d7
--- /dev/null
+++ b/RELEASE-NOTES.md
@@ -0,0 +1,33 @@
+# Rebar 2.2.0
+
+## PR's Merged
+
+* rebar/137: [Filter documented behaviour callbacks](https://github.com/basho/rebar/pull/137)
+* rebar/142: [Fix rebar_file_utils module on Windows with MSYS](https://github.com/basho/rebar/pull/142)
+* rebar/152: [Allow users to configure skip_deps for specific commands](https://github.com/basho/rebar/pull/152)
+* rebar/154: [Stop applications nicely before killing extra processes](https://github.com/basho/rebar/pull/154)
+* rebar/155: [Fix rebar_utils:expand_env_variable/3](https://github.com/basho/rebar/pull/155)
+* rebar/157: [add native Windows compiler support](https://github.com/basho/rebar/pull/157)
+* rebar/172: [Allow reltool target_dir to be constructed on the fly](https://github.com/basho/rebar/pull/172)
+* rebar/173: [rebar should expand VCS version in the top directory, if possible](https://github.com/basho/rebar/pull/173)
+* rebar/174: [Fixed handle_call response in simplesrv.erl](https://github.com/basho/rebar/pull/174)
+* rebar/177: [Cache vsn information during the run to avoid extra unnecessary shell calls](https://github.com/basho/rebar/pull/177)
+* rebar/179: [Add ebin to the path before compiling erlydtl templates](https://github.com/basho/rebar/pull/179)
+* rebar/183: [Fix compiling DTL templates with latest erlydtl](https://github.com/basho/rebar/pull/183)
+* rebar/184: [Fix for destruction of config app vars on reset](https://github.com/basho/rebar/pull/184)
+* rebar/185: [simple enhance and simple bugfix](https://github.com/basho/rebar/pull/185)
+* rebar/187: [fix for cp_r_win32 where copying a directory to a non-existant directory would crash](https://github.com/basho/rebar/pull/187)
+* rebar/189: [Fix typos in generated cmd script in bootstrap](https://github.com/basho/rebar/pull/189)
+* rebar/190: [Windows xcopy dir to non-existant dir (re-request)](https://github.com/basho/rebar/pull/190)
+* rebar/191: [Fix typos in rebar_templater](https://github.com/basho/rebar/pull/191)
+* rebar/196: [Escape '|' in the Windows runner usage string](https://github.com/basho/rebar/pull/196)
+* rebar/198: [New feature to rebar_xref to allow execution of custom queries.](https://github.com/basho/rebar/pull/198)
+* rebar/199: [Added new feature to rebar xref to allow execution of custom queries.](https://github.com/basho/rebar/pull/199)
+* rebar/200: [Enable runner to pass more than one argument to start](https://github.com/basho/rebar/pull/200)
+* rebar/201: [include simplemodule.app.src in simplemod template](https://github.com/basho/rebar/pull/201)
+* rebar/205: [Ports in languages other than C](https://github.com/basho/rebar/issues/205)
+* rebar/210: [use file:script if a .config.script file present](https://github.com/basho/rebar/pull/210)
+* rebar/212: [ Modified simplenode.runner to start from alternative directory](https://github.com/basho/rebar/pull/212)
+* rebar/214: [Foreground running doesn't allow console attaching](https://github.com/basho/rebar/issues/214)
+* rebar/215: [Add support for http proxy_friendly_github_urls](https://github.com/basho/rebar/pull/215)
+* rebar/388: [Less than useful rebar error message when error in .hrl files](https://github.com/basho/rebar/issues/388)
diff --git a/THANKS b/THANKS
index 95cc493..0b503d3 100644
--- a/THANKS
+++ b/THANKS
@@ -120,3 +120,4 @@ Pedram Nimreezi
Sylvain Benner
Oliver Ferrigni
Dave Thomas
+Evgeniy Khramtsov
diff --git a/dialyzer_reference b/dialyzer_reference
index e26d8dd..7fbe609 100644
--- a/dialyzer_reference
+++ b/dialyzer_reference
@@ -1,3 +1,3 @@
-rebar_eunit.erl:388: Call to missing or unexported function eunit_test:function_wrapper/2
-rebar_utils.erl:163: Call to missing or unexported function escript:foldl/3
+rebar_eunit.erl:434: Call to missing or unexported function eunit_test:function_wrapper/2
+rebar_utils.erl:164: Call to missing or unexported function escript:foldl/3
diff --git a/ebin/rebar.app b/ebin/rebar.app
index 873be18..8e239e9 100644
--- a/ebin/rebar.app
+++ b/ebin/rebar.app
@@ -3,7 +3,7 @@
{application, rebar,
[{description, "Rebar: Erlang Build Tool"},
- {vsn, "2.1.0"},
+ {vsn, "2.2.0"},
{modules, [ rebar,
rebar_abnfc_compiler,
rebar_app_utils,
@@ -38,8 +38,8 @@
rebar_upgrade,
rebar_utils,
rebar_xref,
- getopt,
- mustache ]},
+ rebar_getopt,
+ rebar_mustache ]},
{registered, []},
{applications, [kernel,
stdlib,
diff --git a/rebar.config.sample b/rebar.config.sample
index e6071bd..30d28d0 100644
--- a/rebar.config.sample
+++ b/rebar.config.sample
@@ -221,6 +221,11 @@
{xref_warnings, false}.
+%% optional extra paths to include in xref:set_library_path/2.
+%% specified relative location of rebar.config.
+%% e.g. {xref_extra_paths,["../gtknode/src"]}
+{xref_extra_paths,[]}.
+
%% xref checks to run
{xref_checks, [undefined_function_calls, undefined_functions,
locals_not_used, exports_not_used,
diff --git a/src/rebar.erl b/src/rebar.erl
index 00505be..36a7b36 100644
--- a/src/rebar.erl
+++ b/src/rebar.erl
@@ -87,7 +87,9 @@ run(["help"|RawCmds]) when RawCmds =/= [] ->
run(["help"]) ->
help();
run(["info"|_]) ->
- help();
+ %% Catch calls to 'rebar info' to avoid treating plugins' info/2 functions
+ %% as commands.
+ ?CONSOLE("Command 'info' not understood or not applicable~n", []);
run(["version"]) ->
ok = load_rebar_app(),
%% Display vsn and build time info
@@ -178,14 +180,26 @@ run_aux(BaseConfig, Commands) ->
%%
help() ->
OptSpecList = option_spec_list(),
- getopt:usage(OptSpecList, "rebar",
- "[var=value,...] <command,...>",
- [{"var=value", "rebar global variables (e.g. force=1)"},
- {"command", "Command to run (e.g. compile)"}]),
+ rebar_getopt:usage(OptSpecList, "rebar",
+ "[var=value,...] <command,...>",
+ [{"var=value", "rebar global variables (e.g. force=1)"},
+ {"command", "Command to run (e.g. compile)"}]),
+
+ ?CONSOLE("To see a list of built-in commands, execute rebar -c.~n~n", []),
?CONSOLE(
"Type 'rebar help <CMD1> <CMD2>' for help on specific commands."
"~n~n", []),
?CONSOLE(
+ "rebar allows you to abbreviate the command to run:~n"
+ "$ rebar co # same as rebar compile~n"
+ "$ rebar eu # same as rebar eunit~n"
+ "$ rebar g-d # same as rebar get-deps~n"
+ "$ rebar x eu # same as rebar xref eunit~n"
+ "$ rebar l-d # same as rebar list-deps~n"
+ "$ rebar l-d l-t # same as rebar list-deps list-templates~n"
+ "$ rebar list-d l-te # same as rebar list-deps list-templates~n"
+ "~n", []),
+ ?CONSOLE(
"Core rebar.config options:~n"
" ~p~n"
" ~p~n"
@@ -215,7 +229,7 @@ help() ->
parse_args(RawArgs) ->
%% Parse getopt options
OptSpecList = option_spec_list(),
- case getopt:parse(OptSpecList, RawArgs) of
+ case rebar_getopt:parse(OptSpecList, RawArgs) of
{ok, Args} ->
Args;
{error, {Reason, Data}} ->
@@ -331,51 +345,54 @@ show_info_maybe_halt(O, Opts, F) ->
%%
commands() ->
S = <<"
-clean Clean
-compile Compile sources
+clean Clean
+compile Compile sources
-escriptize Generate escript archive
+escriptize Generate escript archive
-create template= [var=foo,...] Create skel based on template and vars
-create-app [appid=myapp] Create simple app skel
-create-lib [libid=mylib] Create simple lib skel
-create-node [nodeid=mynode] Create simple node skel
-list-templates List available templates
+create template= [var=foo,...] Create skel based on template and vars
+create-app [appid=myapp] Create simple app skel
+create-lib [libid=mylib] Create simple lib skel
+create-node [nodeid=mynode] Create simple node skel
+list-templates List available templates
-doc Generate Erlang program documentation
+doc Generate Erlang program documentation
-check-deps Display to be fetched dependencies
-get-deps Fetch dependencies
-update-deps Update fetched dependencies
-delete-deps Delete fetched dependencies
-list-deps List dependencies
+check-deps Display to be fetched dependencies
+get-deps Fetch dependencies
+update-deps Update fetched dependencies
+delete-deps Delete fetched dependencies
+list-deps List dependencies
-generate [dump_spec=0/1] Build release with reltool
-overlay Run reltool overlays only
+generate [dump_spec=0/1] Build release with reltool
+overlay Run reltool overlays only
generate-upgrade previous_release=path Build an upgrade package
generate-appups previous_release=path Generate appup files
-eunit [suites=foo] Run eunit tests in foo.erl and
- test/foo_tests.erl
- [suites=foo] [tests=bar] Run specific eunit tests [first test name
- starting with 'bar' in foo.erl and
- test/foo_tests.erl]
- [tests=bar] For every existing suite, run the first
- test whose name starts with bar and, if
- no such test exists, run the test whose
- name starts with bar in the suite's
- _tests module
+eunit [suite[s]=foo] Run EUnit tests in foo.erl and
+ test/foo_tests.erl
+ [suite[s]=foo] [test[s]=bar] Run specific EUnit tests [first test
+ name starting with 'bar' in foo.erl
+ and test/foo_tests.erl]
+ [test[s]=bar] For every existing suite, run the first
+ test whose name starts with bar and, if
+ no such test exists, run the test whose
+ name starts with bar in the suite's
+ _tests module.
+ [random_suite_order=true] Run tests in a random order, either
+ [random_suite_order=Seed] with a random seed for the PRNG, or a
+ specific one.
-ct [suites=] [case=] Run common_test suites
+ct [suite[s]=] [case=] Run common_test suites
-qc Test QuickCheck properties
+qc Test QuickCheck properties
-xref Run cross reference analysis
+xref Run cross reference analysis
-help Show the program options
-version Show version information
+help Show the program options
+version Show version information
">>,
io:put_chars(S).
diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl
index 8158eb6..a2484e1 100644
--- a/src/rebar_app_utils.erl
+++ b/src/rebar_app_utils.erl
@@ -163,15 +163,6 @@ consult_app_file(Filename) ->
false ->
file:consult(Filename);
true ->
- %% TODO: EXPERIMENTAL For now let's warn the user if a
- %% script is going to be run.
- case filelib:is_regular([Filename, ".script"]) of
- true ->
- ?CONSOLE("NOTICE: Using experimental *.app.src.script "
- "functionality on ~s ~n", [Filename]);
- _ ->
- ok
- end,
rebar_config:consult_file(Filename)
end.
diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl
index a0dec30..1957070 100644
--- a/src/rebar_base_compiler.erl
+++ b/src/rebar_base_compiler.erl
@@ -49,7 +49,7 @@ run(Config, FirstFiles, RestFiles, CompileFn) ->
Jobs = rebar:get_jobs(Config),
?DEBUG("Starting ~B compile worker(s)~n", [Jobs]),
Pids = [spawn_monitor(F) || _I <- lists:seq(1,Jobs)],
- compile_queue(Pids, RestFiles)
+ compile_queue(Config, Pids, RestFiles)
end.
run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
@@ -139,27 +139,31 @@ compile_each([Source | Rest], Config, CompileFn) ->
skipped ->
?INFO("Skipped ~s\n", [Source]);
Error ->
+ ?CONSOLE("Compiling ~s failed:\n",
+ [maybe_absname(Config, Source)]),
maybe_report(Error),
?DEBUG("Compilation failed: ~p\n", [Error]),
?FAIL
end,
compile_each(Rest, Config, CompileFn).
-compile_queue([], []) ->
+compile_queue(_Config, [], []) ->
ok;
-compile_queue(Pids, Targets) ->
+compile_queue(Config, Pids, Targets) ->
receive
{next, Worker} ->
case Targets of
[] ->
Worker ! empty,
- compile_queue(Pids, Targets);
+ compile_queue(Config, Pids, Targets);
[Source | Rest] ->
Worker ! {compile, Source},
- compile_queue(Pids, Rest)
+ compile_queue(Config, Pids, Rest)
end;
- {fail, Error} ->
+ {fail, {_, {source, Source}}=Error} ->
+ ?CONSOLE("Compiling ~s failed:\n",
+ [maybe_absname(Config, Source)]),
maybe_report(Error),
?DEBUG("Worker compilation failed: ~p\n", [Error]),
?FAIL;
@@ -167,20 +171,20 @@ compile_queue(Pids, Targets) ->
{compiled, Source, Warnings} ->
report(Warnings),
?CONSOLE("Compiled ~s\n", [Source]),
- compile_queue(Pids, Targets);
+ compile_queue(Config, Pids, Targets);
{compiled, Source} ->
?CONSOLE("Compiled ~s\n", [Source]),
- compile_queue(Pids, Targets);
+ compile_queue(Config, Pids, Targets);
{skipped, Source} ->
?INFO("Skipped ~s\n", [Source]),
- compile_queue(Pids, Targets);
+ compile_queue(Config, Pids, Targets);
{'DOWN', Mref, _, Pid, normal} ->
?DEBUG("Worker exited cleanly\n", []),
Pids2 = lists:delete({Pid, Mref}, Pids),
- compile_queue(Pids2, Targets);
+ compile_queue(Config, Pids2, Targets);
{'DOWN', _Mref, _, _Pid, Info} ->
?DEBUG("Worker failed: ~p\n", [Info]),
@@ -202,8 +206,7 @@ compile_worker(QueuePid, Config, CompileFn) ->
QueuePid ! {skipped, Source},
compile_worker(QueuePid, Config, CompileFn);
Error ->
- QueuePid ! {fail, [{error, Error},
- {source, Source}]},
+ QueuePid ! {fail, {{error, Error}, {source, Source}}},
ok
end;
@@ -224,7 +227,7 @@ format_warnings(Config, Source, Warnings, Opts) ->
end,
format_errors(Config, Source, Prefix, Warnings).
-maybe_report([{error, {error, _Es, _Ws}=ErrorsAndWarnings}, {source, _}]) ->
+maybe_report({{error, {error, _Es, _Ws}=ErrorsAndWarnings}, {source, _}}) ->
maybe_report(ErrorsAndWarnings);
maybe_report([{error, E}, {source, S}]) ->
report(["unexpected error compiling " ++ S, io_lib:fwrite("~n~p~n", [E])]);
@@ -239,12 +242,7 @@ report(Messages) ->
format_errors(Config, _MainSource, Extra, Errors) ->
[begin
- AbsSource = case rebar_utils:processing_base_dir(Config) of
- true ->
- Source;
- false ->
- filename:absname(Source)
- end,
+ AbsSource = maybe_absname(Config, Source),
[format_error(AbsSource, Extra, Desc) || Desc <- Descs]
end
|| {Source, Descs} <- Errors].
@@ -258,3 +256,11 @@ format_error(AbsSource, Extra, {Line, Mod, Desc}) ->
format_error(AbsSource, Extra, {Mod, Desc}) ->
ErrorDesc = Mod:format_error(Desc),
?FMT("~s: ~s~s~n", [AbsSource, Extra, ErrorDesc]).
+
+maybe_absname(Config, Filename) ->
+ case rebar_utils:processing_base_dir(Config) of
+ true ->
+ Filename;
+ false ->
+ filename:absname(Filename)
+ end.
diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl
index 91d763b..f3ed29f 100644
--- a/src/rebar_ct.erl
+++ b/src/rebar_ct.erl
@@ -320,7 +320,7 @@ get_config_file(TestDir) ->
end.
get_suites(Config, TestDir) ->
- case rebar_config:get_global(Config, suites, undefined) of
+ case get_suites(Config) of
undefined ->
" -dir " ++ TestDir;
Suites ->
@@ -329,6 +329,14 @@ get_suites(Config, TestDir) ->
string:join([" -suite"] ++ Suites2, " ")
end.
+get_suites(Config) ->
+ case rebar_config:get_global(Config, suites, undefined) of
+ undefined ->
+ rebar_config:get_global(Config, suite, undefined);
+ Suites ->
+ Suites
+ end.
+
find_suite_path(Suite, TestDir) ->
Path = filename:join(TestDir, Suite ++ "_SUITE.erl"),
case filelib:is_regular(Path) of
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl
index 2e305d5..43bde04 100644
--- a/src/rebar_deps.erl
+++ b/src/rebar_deps.erl
@@ -304,7 +304,7 @@ get_deps_dir(Config) ->
get_deps_dir(Config, "").
get_deps_dir(Config, App) ->
- BaseDir = rebar_config:get_xconf(Config, base_dir, []),
+ BaseDir = rebar_utils:base_dir(Config),
DepsDir = get_shared_deps_dir(Config, "deps"),
{true, filename:join([BaseDir, DepsDir, App])}.
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index dbefa4a..a1740b0 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -36,6 +36,17 @@
-include("rebar.hrl").
-include_lib("stdlib/include/erl_compile.hrl").
+-define(ERLCINFO_VSN, 1).
+-define(ERLCINFO_FILE, "erlcinfo").
+-type erlc_info_v() :: {digraph:vertex(), term()} | 'false'.
+-type erlc_info_e() :: {digraph:vertex(), digraph:vertex()}.
+-type erlc_info() :: {list(erlc_info_v()), list(erlc_info_e())}.
+-record(erlcinfo,
+ {
+ vsn = ?ERLCINFO_VSN :: pos_integer(),
+ info = {[], []} :: erlc_info()
+ }).
+
%% ===================================================================
%% Public API
%% ===================================================================
@@ -90,7 +101,7 @@ compile(Config, _AppFile) ->
doterl_compile(Config, "ebin").
-spec clean(rebar_config:config(), file:filename()) -> 'ok'.
-clean(_Config, _AppFile) ->
+clean(Config, _AppFile) ->
MibFiles = rebar_utils:find_files("mibs", "^.*\\.mib\$"),
MIBs = [filename:rootname(filename:basename(MIB)) || MIB <- MibFiles],
rebar_file_utils:delete_each(
@@ -103,6 +114,9 @@ clean(_Config, _AppFile) ->
[ binary_to_list(iolist_to_binary(re:replace(F, "\\.[x|y]rl$", ".erl")))
|| F <- YrlFiles ]),
+ %% Delete the build graph, if any
+ rebar_file_utils:rm_rf(erlcinfo_file(Config)),
+
%% Erlang compilation is recursive, so it's possible that we have a nested
%% directory structure in ebin with .beam files within. As such, we want
%% to scan whatever is left in the ebin/ directory for sub-dirs which
@@ -260,7 +274,7 @@ doterl_compile(Config, OutDir) ->
doterl_compile(Config, OutDir, []).
doterl_compile(Config, OutDir, MoreSources) ->
- FirstErls = rebar_config:get_list(Config, erl_first_files, []),
+ ErlFirstFiles = rebar_config:get_list(Config, erl_first_files, []),
ErlOpts = rebar_utils:erl_opts(Config),
?DEBUG("erl_opts ~p~n", [ErlOpts]),
%% Support the src_dirs option allowing multiple directories to
@@ -268,114 +282,270 @@ doterl_compile(Config, OutDir, MoreSources) ->
%% eunit tests be separated from the core application source.
SrcDirs = rebar_utils:src_dirs(proplists:append_values(src_dirs, ErlOpts)),
RestErls = [Source || Source <- gather_src(SrcDirs, []) ++ MoreSources,
- not lists:member(Source, FirstErls)],
-
- %% Split RestErls so that parse_transforms and behaviours are instead added
- %% to erl_first_files, parse transforms first.
- %% This should probably be somewhat combined with inspect_epp
- [ParseTransforms, Behaviours, OtherErls] =
- lists:foldl(fun(F, [A, B, C]) ->
- case compile_priority(F) of
- parse_transform ->
- [[F | A], B, C];
- behaviour ->
- [A, [F | B], C];
- callback ->
- [A, [F | B], C];
- _ ->
- [A, B, [F | C]]
- end
- end, [[], [], []], RestErls),
-
- NewFirstErls = FirstErls ++ ParseTransforms ++ Behaviours,
-
+ not lists:member(Source, ErlFirstFiles)],
%% Make sure that ebin/ exists and is on the path
ok = filelib:ensure_dir(filename:join("ebin", "dummy.beam")),
CurrPath = code:get_path(),
true = code:add_path(filename:absname("ebin")),
OutDir1 = proplists:get_value(outdir, ErlOpts, OutDir),
- rebar_base_compiler:run(Config, NewFirstErls, OtherErls,
- fun(S, C) ->
- internal_erl_compile(C, S, OutDir1, ErlOpts)
- end),
+ G = init_erlcinfo(Config, RestErls),
+ %% Split RestErls so that files which are depended on are treated
+ %% like erl_first_files.
+ {OtherFirstErls, OtherErls} =
+ lists:partition(
+ fun(F) ->
+ Children = get_children(G, F),
+ log_files(?FMT("Files dependent on ~s", [F]), Children),
+
+ case erls(Children) of
+ [] ->
+ %% There are no files dependent on this file.
+ false;
+ _ ->
+ %% There are some files dependent on the file.
+ %% Thus the file has higher priority
+ %% and should be compiled in the first place.
+ true
+ end
+ end, RestErls),
+ %% Dependencies of OtherFirstErls that must be compiled first.
+ OtherFirstErlsDeps = lists:flatmap(
+ fun(Erl) -> erls(get_parents(G, Erl)) end,
+ OtherFirstErls),
+ %% NOTE: In case the way we retrieve OtherFirstErlsDeps or merge
+ %% it with OtherFirstErls does not result in the correct compile
+ %% priorities, or the method in use proves to be too slow for
+ %% certain projects, consider using a more elaborate method (maybe
+ %% digraph_utils) or alternatively getting and compiling the .erl
+ %% parents of an individual Source in internal_erl_compile. By not
+ %% handling this in internal_erl_compile, we also avoid extra
+ %% needs_compile/2 calls.
+ FirstErls = ErlFirstFiles ++ uo_merge(OtherFirstErlsDeps, OtherFirstErls),
+ ?DEBUG("Files to compile first: ~p~n", [FirstErls]),
+ rebar_base_compiler:run(
+ Config, FirstErls, OtherErls,
+ fun(S, C) ->
+ internal_erl_compile(C, S, OutDir1, ErlOpts, G)
+ end),
true = code:set_path(CurrPath),
ok.
+%%
+%% Return all .erl files from a list of files
+%%
+erls(Files) ->
+ [Erl || Erl <- Files, filename:extension(Erl) =:= ".erl"].
+
+%%
+%% Return a list without duplicates while preserving order
+%%
+ulist(L) ->
+ ulist(L, []).
+
+ulist([H|T], Acc) ->
+ case lists:member(H, T) of
+ true ->
+ ulist(T, Acc);
+ false ->
+ ulist(T, [H|Acc])
+ end;
+ulist([], Acc) ->
+ lists:reverse(Acc).
+
+%%
+%% Merge two lists without duplicates while preserving order
+%%
+uo_merge(L1, L2) ->
+ lists:foldl(fun(E, Acc) -> u_add_element(E, Acc) end, ulist(L1), L2).
+
+u_add_element(Elem, [Elem|_]=Set) -> Set;
+u_add_element(Elem, [E1|Set]) -> [E1|u_add_element(Elem, Set)];
+u_add_element(Elem, []) -> [Elem].
+
-spec include_path(file:filename(),
rebar_config:config()) -> [file:filename(), ...].
include_path(Source, Config) ->
ErlOpts = rebar_config:get(Config, erl_opts, []),
- ["include", filename:dirname(Source)]
- ++ proplists:get_all_values(i, ErlOpts).
-
--spec inspect(file:filename(),
- [file:filename(), ...]) -> {string(), [string()]}.
-inspect(Source, IncludePath) ->
- ModuleDefault = filename:basename(Source, ".erl"),
- case epp:open(Source, IncludePath) of
- {ok, Epp} ->
- inspect_epp(Epp, Source, ModuleDefault, []);
- {error, Reason} ->
- ?DEBUG("Failed to inspect ~s: ~p\n", [Source, Reason]),
- {ModuleDefault, []}
- end.
-
--spec inspect_epp(pid(), file:filename(), file:filename(),
- [string()]) -> {string(), [string()]}.
-inspect_epp(Epp, Source, Module, Includes) ->
- case epp:parse_erl_form(Epp) of
- {ok, {attribute, _, module, ModInfo}} ->
- ActualModuleStr =
- case ModInfo of
- %% Typical module name, single atom
- ActualModule when is_atom(ActualModule) ->
- atom_to_list(ActualModule);
- %% Packag-ized module name, list of atoms
- ActualModule when is_list(ActualModule) ->
- string:join([atom_to_list(P) ||
- P <- ActualModule], ".");
- %% Parameterized module name, single atom
- {ActualModule, _} when is_atom(ActualModule) ->
- atom_to_list(ActualModule);
- %% Parameterized and packagized module name, list of atoms
- {ActualModule, _} when is_list(ActualModule) ->
- string:join([atom_to_list(P) ||
- P <- ActualModule], ".")
- end,
- inspect_epp(Epp, Source, ActualModuleStr, Includes);
- {ok, {attribute, 1, file, {Module, 1}}} ->
- inspect_epp(Epp, Source, Module, Includes);
- {ok, {attribute, 1, file, {Source, 1}}} ->
- inspect_epp(Epp, Source, Module, Includes);
- {ok, {attribute, 1, file, {IncFile, 1}}} ->
- inspect_epp(Epp, Source, Module, [IncFile | Includes]);
- {eof, _} ->
- epp:close(Epp),
- {Module, Includes};
- _ ->
- inspect_epp(Epp, Source, Module, Includes)
- end.
+ lists:usort(["include", filename:dirname(Source)]
+ ++ proplists:get_all_values(i, ErlOpts)).
-spec needs_compile(file:filename(), file:filename(),
[string()]) -> boolean().
-needs_compile(Source, Target, Hrls) ->
+needs_compile(Source, Target, Parents) ->
TargetLastMod = filelib:last_modified(Target),
lists:any(fun(I) -> TargetLastMod < filelib:last_modified(I) end,
- [Source] ++ Hrls).
+ [Source] ++ Parents).
+
+check_erlcinfo(_Config, #erlcinfo{vsn=?ERLCINFO_VSN}) ->
+ ok;
+check_erlcinfo(Config, #erlcinfo{vsn=Vsn}) ->
+ ?ABORT("~s file version is incompatible. expected: ~b got: ~b~n",
+ [erlcinfo_file(Config), ?ERLCINFO_VSN, Vsn]);
+check_erlcinfo(Config, _) ->
+ ?ABORT("~s file is invalid. Please delete before next run.~n",
+ [erlcinfo_file(Config)]).
+
+erlcinfo_file(Config) ->
+ filename:join([rebar_utils:base_dir(Config), ".rebar", ?ERLCINFO_FILE]).
+
+init_erlcinfo(Config, Erls) ->
+ G = restore_erlcinfo(Config),
+ %% Get a unique list of dirs based on the source files' locations.
+ %% This is used for finding files in sub dirs of the configured
+ %% src_dirs. For example, src/sub_dir/foo.erl.
+ Dirs = sets:to_list(lists:foldl(
+ fun(Erl, Acc) ->
+ Dir = filename:dirname(Erl),
+ sets:add_element(Dir, Acc)
+ end, sets:new(), Erls)),
+ Updates = [update_erlcinfo(G, Erl, include_path(Erl, Config) ++ Dirs)
+ || Erl <- Erls],
+ Modified = lists:member(modified, Updates),
+ ok = store_erlcinfo(G, Config, Modified),
+ G.
+
+update_erlcinfo(G, Source, Dirs) ->
+ case digraph:vertex(G, Source) of
+ {_, LastUpdated} ->
+ LastModified = filelib:last_modified(Source),
+ if LastModified == 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);
+ modified;
+ true ->
+ unmodified
+ end;
+ false ->
+ modify_erlcinfo(G, Source, Dirs),
+ modified
+ end.
+
+modify_erlcinfo(G, Source, Dirs) ->
+ {ok, Fd} = file:open(Source, [read]),
+ Incls = parse_attrs(Fd, []),
+ AbsIncls = expand_file_names(Incls, Dirs),
+ ok = file:close(Fd),
+ LastUpdated = {date(), time()},
+ digraph:add_vertex(G, Source, LastUpdated),
+ lists:foreach(
+ fun(Incl) ->
+ update_erlcinfo(G, Incl, Dirs),
+ digraph:add_edge(G, Source, Incl)
+ end, AbsIncls).
+
+restore_erlcinfo(Config) ->
+ File = erlcinfo_file(Config),
+ G = digraph:new(),
+ case file:read_file(File) of
+ {ok, Data} ->
+ try binary_to_term(Data) of
+ Erlcinfo ->
+ ok = check_erlcinfo(Config, Erlcinfo),
+ #erlcinfo{info=ErlcInfo} = Erlcinfo,
+ {Vs, Es} = ErlcInfo,
+ lists:foreach(
+ fun({V, LastUpdated}) ->
+ digraph:add_vertex(G, V, LastUpdated)
+ end, Vs),
+ lists:foreach(
+ fun({V1, V2}) ->
+ digraph:add_edge(G, V1, V2)
+ end, Es)
+ catch
+ error:badarg ->
+ ?ERROR(
+ "Failed (binary_to_term) to restore rebar info file."
+ " Discard file.~n", []),
+ ok
+ end;
+ _Err ->
+ ok
+ end,
+ G.
+
+store_erlcinfo(_G, _Config, _Modified = false) ->
+ ok;
+store_erlcinfo(G, Config, _Modified) ->
+ Vs = lists:map(
+ fun(V) ->
+ digraph:vertex(G, V)
+ end, digraph:vertices(G)),
+ Es = lists:flatmap(
+ fun({V, _}) ->
+ lists:map(
+ fun(E) ->
+ {_, V1, V2, _} = digraph:edge(G, E),
+ {V1, V2}
+ end, digraph:out_edges(G, V))
+ end, Vs),
+ File = erlcinfo_file(Config),
+ ok = filelib:ensure_dir(File),
+ Data = term_to_binary(#erlcinfo{info={Vs, Es}}, [{compressed, 9}]),
+ file:write_file(File, Data).
+
+%% NOTE: If, for example, one of the entries in Files, refers to
+%% gen_server.erl, that entry will be dropped. It is dropped because
+%% such an entry usually refers to the beam file, and we don't pass a
+%% list of OTP src dirs for finding gen_server.erl's full path. Also,
+%% if gen_server.erl was modified, it's not rebar's task to compile a
+%% new version of the beam file. Therefore, it's reasonable to drop
+%% such entries. Also see process_attr(behaviour, Form, Includes).
+-spec expand_file_names([file:filename()],
+ [file:filename()]) -> [file:filename()].
+expand_file_names(Files, Dirs) ->
+ %% We check if Files exist by itself or within the directories
+ %% listed in Dirs.
+ %% Return the list of files matched.
+ lists:flatmap(
+ fun(Incl) ->
+ case filelib:is_regular(Incl) of
+ true ->
+ [Incl];
+ false ->
+ lists:flatmap(
+ fun(Dir) ->
+ FullPath = filename:join(Dir, Incl),
+ case filelib:is_regular(FullPath) of
+ true ->
+ [FullPath];
+ false ->
+ []
+ end
+ end, Dirs)
+ end
+ end, Files).
+
+-spec get_parents(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()].
+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()) -> 'ok' | 'skipped'.
-internal_erl_compile(Config, Source, Outdir, ErlOpts) ->
+ file:filename(), list(),
+ digraph()) -> 'ok' | 'skipped'.
+internal_erl_compile(Config, Source, OutDir, ErlOpts, G) ->
%% Determine the target name and includes list by inspecting the source file
- {Module, Hrls} = inspect(Source, include_path(Source, Config)),
+ Module = filename:basename(Source, ".erl"),
+ Parents = get_parents(G, Source),
+ log_files(?FMT("~s depends on", [Source]), Parents),
%% Construct the target filename
- Target = filename:join([Outdir | string:tokens(Module, ".")]) ++ ".beam",
+ Target = filename:join([OutDir | string:tokens(Module, ".")]) ++ ".beam",
ok = filelib:ensure_dir(Target),
%% If the file needs compilation, based on last mod date of includes or
%% the target
- case needs_compile(Source, Target, Hrls) of
+ case needs_compile(Source, Target, Parents) of
true ->
Opts = [{outdir, filename:dirname(Target)}] ++
ErlOpts ++ [{i, "include"}, return],
@@ -463,40 +633,97 @@ delete_dir(Dir, Subdirs) ->
lists:foreach(fun(D) -> delete_dir(D, dirs(D)) end, Subdirs),
file:del_dir(Dir).
--spec compile_priority(file:filename()) -> 'normal' | 'behaviour' |
- 'callback' |
- 'parse_transform'.
-compile_priority(File) ->
- case epp_dodger:parse_file(File) of
- {error, _} ->
- normal; % couldn't parse the file, default priority
- {ok, Trees} ->
- F2 = fun({tree,arity_qualifier,_,
- {arity_qualifier,{tree,atom,_,behaviour_info},
- {tree,integer,_,1}}}, _) ->
- behaviour;
- ({tree,arity_qualifier,_,
- {arity_qualifier,{tree,atom,_,parse_transform},
- {tree,integer,_,2}}}, _) ->
- parse_transform;
- (_, Acc) ->
- Acc
- end,
-
- F = fun({tree, attribute, _,
- {attribute, {tree, atom, _, export},
- [{tree, list, _, {list, List, none}}]}}, Acc) ->
- lists:foldl(F2, Acc, List);
- ({tree, attribute, _,
- {attribute, {tree, atom, _, callback},_}}, _Acc) ->
- callback;
- (_, Acc) ->
- Acc
- end,
+parse_attrs(Fd, Includes) ->
+ case io:parse_erl_form(Fd, "") of
+ {ok, Form, _Line} ->
+ case erl_syntax:type(Form) of
+ attribute ->
+ NewIncludes = process_attr(Form, Includes),
+ parse_attrs(Fd, NewIncludes);
+ _ ->
+ parse_attrs(Fd, Includes)
+ end;
+ {eof, _} ->
+ Includes;
+ _Err ->
+ parse_attrs(Fd, Includes)
+ end.
- lists:foldl(F, normal, Trees)
+process_attr(Form, Includes) ->
+ try
+ AttrName = erl_syntax:atom_value(erl_syntax:attribute_name(Form)),
+ process_attr(AttrName, Form, Includes)
+ catch _:_ ->
+ %% TODO: We should probably try to be more specific here
+ %% and not suppress all errors.
+ Includes
end.
+process_attr(import, Form, Includes) ->
+ case erl_syntax_lib:analyze_import_attribute(Form) of
+ {Mod, _Funs} ->
+ [atom_to_list(Mod) ++ ".erl"|Includes];
+ Mod ->
+ [atom_to_list(Mod) ++ ".erl"|Includes]
+ end;
+process_attr(file, Form, Includes) ->
+ {File, _} = erl_syntax_lib:analyze_file_attribute(Form),
+ [File|Includes];
+process_attr(include, Form, Includes) ->
+ [FileNode] = erl_syntax:attribute_arguments(Form),
+ File = erl_syntax:string_value(FileNode),
+ [File|Includes];
+process_attr(include_lib, Form, Includes) ->
+ [FileNode] = erl_syntax:attribute_arguments(Form),
+ RawFile = erl_syntax:string_value(FileNode),
+ File = maybe_expand_include_lib_path(RawFile),
+ [File|Includes];
+process_attr(behaviour, Form, Includes) ->
+ [FileNode] = erl_syntax:attribute_arguments(Form),
+ File = erl_syntax:atom_name(FileNode) ++ ".erl",
+ [File|Includes];
+process_attr(compile, Form, Includes) ->
+ [Arg] = erl_syntax:attribute_arguments(Form),
+ case erl_syntax:concrete(Arg) of
+ {parse_transform, Mod} ->
+ [atom_to_list(Mod) ++ ".erl"|Includes];
+ {core_transform, Mod} ->
+ [atom_to_list(Mod) ++ ".erl"|Includes];
+ L when is_list(L) ->
+ lists:foldl(
+ fun({parse_transform, M}, Acc) ->
+ [atom_to_list(M) ++ ".erl"|Acc];
+ ({core_transform, M}, Acc) ->
+ [atom_to_list(M) ++ ".erl"|Acc];
+ (_, Acc) ->
+ Acc
+ end, Includes, L)
+ end.
+
+%% Given the filename from an include_lib attribute, if the path
+%% exists, return unmodified, or else get the absolute ERL_LIBS
+%% path.
+maybe_expand_include_lib_path(File) ->
+ case filelib:is_regular(File) of
+ true ->
+ File;
+ false ->
+ expand_include_lib_path(File)
+ end.
+
+%% Given a path like "stdlib/include/erl_compile.hrl", return
+%% "OTP_INSTALL_DIR/lib/erlang/lib/stdlib-x.y.z/include/erl_compile.hrl".
+%% Usually a simple [Lib, SubDir, File1] = filename:split(File) should
+%% work, but to not crash when an unusual include_lib path is used,
+%% utilize more elaborate logic.
+expand_include_lib_path(File) ->
+ File1 = filename:basename(File),
+ Split = filename:split(filename:dirname(File)),
+ Lib = hd(Split),
+ SubDir = filename:join(tl(Split)),
+ Dir = code:lib_dir(list_to_atom(Lib), list_to_atom(SubDir)),
+ filename:join(Dir, File1).
+
%%
%% Ensure all files in a list are present and abort if one is missing
%%
@@ -509,3 +736,13 @@ check_file(File) ->
false -> ?ABORT("File ~p is missing, aborting\n", [File]);
true -> File
end.
+
+%% Print prefix followed by list of files. If the list is empty, print
+%% on the same line, otherwise use a separate line.
+log_files(Prefix, Files) ->
+ case Files of
+ [] ->
+ ?DEBUG("~s: ~p~n", [Prefix, Files]);
+ _ ->
+ ?DEBUG("~s:~n~p~n", [Prefix, Files])
+ end.
diff --git a/src/rebar_erlydtl_compiler.erl b/src/rebar_erlydtl_compiler.erl
index 6172879..556e841 100644
--- a/src/rebar_erlydtl_compiler.erl
+++ b/src/rebar_erlydtl_compiler.erl
@@ -178,7 +178,7 @@ compile_dtl(Config, Source, Target, DtlOpts) ->
?ERROR("~n===============================================~n"
" You need to install erlydtl to compile DTL templates~n"
" Download the latest tarball release from github~n"
- " http://code.google.com/p/erlydtl/~n"
+ " https://github.com/erlydtl/erlydtl/releases~n"
" and install it into your erlang library dir~n"
"===============================================~n~n", []),
?FAIL;
@@ -194,15 +194,22 @@ compile_dtl(Config, Source, Target, DtlOpts) ->
do_compile(Config, Source, Target, DtlOpts) ->
%% TODO: Check last mod on target and referenced DTLs here..
+ %% erlydtl >= 0.8.1 does not use the extra indirection using the
+ %% compiler_options. Kept for backward compatibility with older
+ %% versions of erlydtl.
+ CompilerOptions = option(compiler_options, DtlOpts),
+
+ Sorted = proplists:unfold(
+ lists:sort(
+ [{out_dir, option(out_dir, DtlOpts)},
+ {doc_root, option(doc_root, DtlOpts)},
+ {custom_tags_dir, option(custom_tags_dir, DtlOpts)},
+ {compiler_options, CompilerOptions}
+ |CompilerOptions])),
+
%% ensure that doc_root and out_dir are defined,
%% using defaults if necessary
- Opts = lists:ukeymerge(1,
- DtlOpts,
- lists:sort(
- [{out_dir, option(out_dir, DtlOpts)},
- {doc_root, option(doc_root, DtlOpts)},
- {custom_tags_dir, option(custom_tags_dir, DtlOpts)},
- {compiler_options, option(compiler_options, DtlOpts)}])),
+ Opts = lists:ukeymerge(1, DtlOpts, Sorted),
?INFO("Compiling \"~s\" -> \"~s\" with options:~n ~s~n",
[Source, Target, io_lib:format("~p", [Opts])]),
case erlydtl:compile(Source,
@@ -210,13 +217,21 @@ do_compile(Config, Source, Target, DtlOpts) ->
Opts) of
ok ->
ok;
+ {ok, _Mod} ->
+ ok;
+ {ok, _Mod, Ws} ->
+ rebar_base_compiler:ok_tuple(Config, Source, Ws);
+ {ok, _Mod, _Bin, Ws} ->
+ rebar_base_compiler:ok_tuple(Config, Source, Ws);
error ->
rebar_base_compiler:error_tuple(Config, Source, [], [], Opts);
{error, {_File, _Msgs} = Error} ->
rebar_base_compiler:error_tuple(Config, Source, [Error], [], Opts);
{error, Msg} ->
Es = [{Source, [{erlydtl_parser, Msg}]}],
- rebar_base_compiler:error_tuple(Config, Source, Es, [], Opts)
+ rebar_base_compiler:error_tuple(Config, Source, Es, [], Opts);
+ {error, Es, Ws} ->
+ rebar_base_compiler:error_tuple(Config, Source, Es, Ws, Opts)
end.
module_name(Target) ->
diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl
index 6ea28f7..d969f96 100644
--- a/src/rebar_eunit.erl
+++ b/src/rebar_eunit.erl
@@ -84,8 +84,7 @@ eunit(Config, _AppFile) ->
ok = ensure_dirs(),
%% Save code path
CodePath = setup_code_path(),
- CompileOnly = rebar_utils:get_experimental_global(Config, compile_only,
- false),
+ CompileOnly = rebar_config:get_global(Config, compile_only, false),
{ok, SrcErls} = rebar_erlc_compiler:test_compile(Config, "eunit",
?EUNIT_DIR),
case CompileOnly of
@@ -121,12 +120,16 @@ info_help(Description) ->
" ~p~n"
" ~p~n"
"Valid command line options:~n"
- " suites=\"foo,bar\" (Run tests in foo.erl, test/foo_tests.erl and~n"
+ " suite[s]=\"foo,bar\" (Run tests in foo.erl, test/foo_tests.erl and~n"
" tests in bar.erl, test/bar_tests.erl)~n"
- " tests=\"baz\" (For every existing suite, run the first test whose~n"
+ " test[s]=\"baz\" (For every existing suite, run the first test whose~n"
" name starts with bar and, if no such test exists,~n"
" run the test whose name starts with bar in the~n"
- " suite's _tests module)~n",
+ " suite's _tests module)~n"
+ " random_suite_order=true (Run tests in random order)~n"
+ " random_suite_order=Seed (Run tests in random order,~n"
+ " with the PRNG seeded with Seed)~n"
+ " compile_only=true (Compile but do not run tests)",
[
Description,
{eunit_opts, []},
@@ -150,7 +153,7 @@ run_eunit(Config, CodePath, SrcErls) ->
AllBeamFiles),
OtherBeamFiles = TestBeamFiles --
[filename:rootname(N) ++ "_tests.beam" || N <- AllBeamFiles],
- ModuleBeamFiles = BeamFiles ++ OtherBeamFiles,
+ ModuleBeamFiles = randomize_suites(Config, BeamFiles ++ OtherBeamFiles),
%% Get modules to be run in eunit
AllModules = [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- AllBeamFiles],
@@ -215,7 +218,7 @@ setup_code_path() ->
%%
filter_suites(Config, Modules) ->
- RawSuites = rebar_config:get_global(Config, suites, ""),
+ RawSuites = get_suites(Config),
SuitesProvided = RawSuites =/= "",
Suites = [list_to_atom(Suite) || Suite <- string:tokens(RawSuites, ",")],
{SuitesProvided, filter_suites1(Modules, Suites)}.
@@ -225,6 +228,41 @@ filter_suites1(Modules, []) ->
filter_suites1(Modules, Suites) ->
[M || M <- Suites, lists:member(M, Modules)].
+get_suites(Config) ->
+ case rebar_config:get_global(Config, suites, "") of
+ "" ->
+ rebar_config:get_global(Config, suite, "");
+ Suites ->
+ Suites
+ end.
+
+%%
+%% == randomize suites ==
+%%
+
+randomize_suites(Config, Modules) ->
+ case rebar_config:get_global(Config, random_suite_order, undefined) of
+ undefined ->
+ Modules;
+ "true" ->
+ Seed = crypto:rand_uniform(1, 65535),
+ randomize_suites1(Modules, Seed);
+ String ->
+ try list_to_integer(String) of
+ Seed ->
+ randomize_suites1(Modules, Seed)
+ catch
+ error:badarg ->
+ ?ERROR("Bad random seed provided: ~p~n", [String]),
+ ?FAIL
+ end
+ end.
+
+randomize_suites1(Modules, Seed) ->
+ _ = random:seed(35, Seed, 1337),
+ ?CONSOLE("Randomizing suite order with seed ~b~n", [Seed]),
+ [X||{_,X} <- lists:sort([{random:uniform(), M} || M <- Modules])].
+
%%
%% == get matching tests ==
%%
@@ -259,8 +297,16 @@ get_tests(Config, SuitesProvided, ModuleBeamFiles, FilteredModules) ->
end,
get_matching_tests(Config, Modules).
+get_tests(Config) ->
+ case rebar_config:get_global(Config, tests, "") of
+ "" ->
+ rebar_config:get_global(Config, test, "");
+ Suites ->
+ Suites
+ end.
+
get_matching_tests(Config, Modules) ->
- RawFunctions = rebar_utils:get_experimental_global(Config, tests, ""),
+ RawFunctions = get_tests(Config),
Tests = [list_to_atom(F1) || F1 <- string:tokens(RawFunctions, ",")],
case Tests of
[] ->
diff --git a/src/getopt.erl b/src/rebar_getopt.erl
index f9852fb..79b871d 100644
--- a/src/getopt.erl
+++ b/src/rebar_getopt.erl
@@ -8,10 +8,11 @@
%%% a copy of the New BSD license with this software. If not, it can be
%%% retrieved from: http://www.opensource.org/licenses/bsd-license.php
%%%-------------------------------------------------------------------
--module(getopt).
+-module(rebar_getopt).
-author('juanjo@comellas.org').
--export([parse/2, usage/2, usage/3, usage/4, tokenize/1]).
+-export([parse/2, check/2, parse_and_check/2, format_error/2,
+ usage/2, usage/3, usage/4, tokenize/1]).
-export([usage_cmd_line/2]).
-define(LINE_LENGTH, 75).
@@ -57,11 +58,52 @@
-export_type([arg_type/0, arg_value/0, arg_spec/0, simple_option/0, compound_option/0, option/0, option_spec/0]).
-%% @doc Parse the command line options and arguments returning a list of tuples
-%% and/or atoms using the Erlang convention for sending options to a
-%% function.
+%% @doc Parse the command line options and arguments returning a list of tuples
+%% and/or atoms using the Erlang convention for sending options to a
+%% function. Additionally perform check if all required options (the ones
+%% without default values) are present. The function is a combination of
+%% two calls: parse/2 and check/2.
+-spec parse_and_check([option_spec()], string() | [string()]) ->
+ {ok, {[option()], [string()]}} | {error, {Reason :: atom(), Data :: term()}}.
+parse_and_check(OptSpecList, CmdLine) when is_list(OptSpecList), is_list(CmdLine) ->
+ case parse(OptSpecList, CmdLine) of
+ {ok, {Opts, _}} = Result ->
+ case check(OptSpecList, Opts) of
+ ok -> Result;
+ Error -> Error
+ end;
+ Error ->
+ Error
+ end.
+
+%% @doc Check the parsed command line arguments returning ok if all required
+%% options (i.e. that don't have defaults) are present, and returning
+%% error otherwise.
+-spec check([option_spec()], [option()]) ->
+ ok | {error, {Reason :: atom(), Option :: atom()}}.
+check(OptSpecList, ParsedOpts) when is_list(OptSpecList), is_list(ParsedOpts) ->
+ try
+ RequiredOpts = [Name || {Name, _, _, Arg, _} <- OptSpecList,
+ not is_tuple(Arg) andalso Arg =/= undefined],
+ lists:foreach(fun (Option) ->
+ case proplists:is_defined(Option, ParsedOpts) of
+ true ->
+ ok;
+ false ->
+ throw({error, {missing_required_option, Option}})
+ end
+ end, RequiredOpts)
+ catch
+ _:Error ->
+ Error
+ end.
+
+
+%% @doc Parse the command line options and arguments returning a list of tuples
+%% and/or atoms using the Erlang convention for sending options to a
+%% function.
-spec parse([option_spec()], string() | [string()]) ->
- {ok, {[option()], [string()]}} | {error, {Reason :: atom(), Data :: any()}}.
+ {ok, {[option()], [string()]}} | {error, {Reason :: atom(), Data :: term()}}.
parse(OptSpecList, CmdLine) when is_list(CmdLine) ->
try
Args = if
@@ -101,6 +143,24 @@ parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, []) ->
{ok, {lists:reverse(append_default_options(OptSpecList, OptAcc)), lists:reverse(ArgAcc)}}.
+%% @doc Format the error code returned by prior call to parse/2 or check/2.
+-spec format_error([option_spec()], {error, {Reason :: atom(), Data :: term()}} |
+ {Reason :: term(), Data :: term()}) -> string().
+format_error(OptSpecList, {error, Reason}) ->
+ format_error(OptSpecList, Reason);
+format_error(OptSpecList, {missing_required_option, Name}) ->
+ {_Name, Short, Long, _Type, _Help} = lists:keyfind(Name, 1, OptSpecList),
+ lists:flatten(["missing required option: -", [Short], " (", to_string(Long), ")"]);
+format_error(_OptSpecList, {invalid_option, OptStr}) ->
+ lists:flatten(["invalid option: ", to_string(OptStr)]);
+format_error(_OptSpecList, {invalid_option_arg, {Name, Arg}}) ->
+ lists:flatten(["option \'", to_string(Name) ++ "\' has invalid argument: ", to_string(Arg)]);
+format_error(_OptSpecList, {invalid_option_arg, OptStr}) ->
+ lists:flatten(["invalid option argument: ", to_string(OptStr)]);
+format_error(_OptSpecList, {Reason, Data}) ->
+ lists:flatten([to_string(Reason), " ", to_string(Data)]).
+
+
%% @doc Parse a long option, add it to the option accumulator and continue
%% parsing the rest of the arguments recursively.
%% A long option can have the following syntax:
@@ -698,7 +758,7 @@ format_usage_line(_MaxOptionLength, _MaxLineLength, {_OptionLength, OptionText,
%% @doc Wrap a text line converting it into several text lines so that the
-%% length of each one of them is never over HelpLength characters.
+%% length of each one of them is never over Length characters.
-spec wrap_text_line(Length :: non_neg_integer(), Text :: string()) -> [string()].
wrap_text_line(Length, Text) ->
wrap_text_line(Length, Text, [], 0, []).
@@ -730,7 +790,7 @@ default_arg_value_to_string(Value) when is_binary(Value) ->
default_arg_value_to_string(Value) when is_integer(Value) ->
integer_to_list(Value);
default_arg_value_to_string(Value) when is_float(Value) ->
- float_to_list(Value);
+ lists:flatten(io_lib:format("~w", [Value]));
default_arg_value_to_string(Value) ->
Value.
@@ -832,7 +892,7 @@ get_env_var(Prefix, Suffix, []) ->
Prefix ++ Suffix.
--spec line_length() -> non_neg_integer().
+-spec line_length() -> 0..?LINE_LENGTH.
line_length() ->
case io:columns() of
{ok, Columns} when Columns < ?LINE_LENGTH ->
@@ -840,3 +900,15 @@ line_length() ->
_ ->
?LINE_LENGTH
end.
+
+
+-spec to_string(term()) -> string().
+to_string(List) when is_list(List) ->
+ case io_lib:printable_list(List) of
+ true -> List;
+ false -> io_lib:format("~p", [List])
+ end;
+to_string(Atom) when is_atom(Atom) ->
+ atom_to_list(Atom);
+to_string(Value) ->
+ io_lib:format("~p", [Value]).
diff --git a/src/mustache.erl b/src/rebar_mustache.erl
index f6963cd..9016c0f 100644
--- a/src/mustache.erl
+++ b/src/rebar_mustache.erl
@@ -23,7 +23,7 @@
%% See the README at http://github.com/mojombo/mustache.erl for additional
%% documentation and usage examples.
--module(mustache). %% v0.1.0
+-module(rebar_mustache). %% v0.1.0
-author("Tom Preston-Werner").
-export([compile/1, compile/2, render/1, render/2, render/3, get/2, get/3, escape/1, start/1]).
@@ -31,6 +31,8 @@
section_re = undefined,
tag_re = undefined}).
+-define(MUSTACHE_STR, "rebar_mustache").
+
compile(Body) when is_list(Body) ->
State = #mstate{},
CompiledTemplate = pre_compile(Body, State),
@@ -108,7 +110,7 @@ compile_section(Name, Content, State) ->
Mod = State#mstate.mod,
Result = compiler(Content, State),
"fun() -> " ++
- "case mustache:get(" ++ Name ++ ", Ctx, " ++ atom_to_list(Mod) ++ ") of " ++
+ "case " ++ ?MUSTACHE_STR ++ ":get(" ++ Name ++ ", Ctx, " ++ atom_to_list(Mod) ++ ") of " ++
"\"true\" -> " ++
Result ++ "; " ++
"\"false\" -> " ++
@@ -143,10 +145,10 @@ tag_kind(T, {K0, K1}) ->
compile_tag(none, Content, State) ->
Mod = State#mstate.mod,
- "mustache:escape(mustache:get(" ++ Content ++ ", Ctx, " ++ atom_to_list(Mod) ++ "))";
+ ?MUSTACHE_STR ++ ":escape(" ++ ?MUSTACHE_STR ++ ":get(" ++ Content ++ ", Ctx, " ++ atom_to_list(Mod) ++ "))";
compile_tag("{", Content, State) ->
Mod = State#mstate.mod,
- "mustache:get(" ++ Content ++ ", Ctx, " ++ atom_to_list(Mod) ++ ")";
+ ?MUSTACHE_STR ++ ":get(" ++ Content ++ ", Ctx, " ++ atom_to_list(Mod) ++ ")";
compile_tag("!", _Content, _State) ->
"[]".
diff --git a/src/rebar_qc.erl b/src/rebar_qc.erl
index 53a6f52..99d37a2 100644
--- a/src/rebar_qc.erl
+++ b/src/rebar_qc.erl
@@ -67,7 +67,9 @@ info(help, qc) ->
"Valid rebar.config options:~n"
" {qc_opts, [{qc_mod, module()}, Options]}~n"
" ~p~n"
- " ~p~n",
+ " ~p~n"
+ "Valid command line options:~n"
+ " compile_only=true (Compile but do not test properties)",
[
{qc_compile_opts, []},
{qc_first_files, []}
@@ -142,8 +144,7 @@ run(Config, QC, QCOpts) ->
ok = ensure_dirs(),
CodePath = setup_codepath(),
- CompileOnly = rebar_utils:get_experimental_global(Config, compile_only,
- false),
+ CompileOnly = rebar_config:get_global(Config, compile_only, false),
%% Compile erlang code to ?QC_DIR, using a tweaked config
%% with appropriate defines, and include all the test modules
%% as well.
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl
index c21daa3..43bb8da 100644
--- a/src/rebar_templater.erl
+++ b/src/rebar_templater.erl
@@ -103,7 +103,7 @@ render(Bin, Context) ->
ReOpts = [global, {return, list}],
Str0 = re:replace(Bin, "\\\\", "\\\\\\", ReOpts),
Str1 = re:replace(Str0, "\"", "\\\\\"", ReOpts),
- mustache:render(Str1, Context).
+ rebar_mustache:render(Str1, Context).
%% ===================================================================
%% Internal functions
diff --git a/src/rebar_upgrade.erl b/src/rebar_upgrade.erl
index 5814e51..3a38a08 100644
--- a/src/rebar_upgrade.erl
+++ b/src/rebar_upgrade.erl
@@ -87,7 +87,8 @@ info(help, 'generate-upgrade') ->
?CONSOLE("Build an upgrade package.~n"
"~n"
"Valid command line options:~n"
- " previous_release=path~n",
+ " previous_release=path~n"
+ " target_dir=target_dir (optional)~n",
[]).
run_checks(Config, OldVerPath, ReltoolConfig) ->
@@ -97,10 +98,7 @@ run_checks(Config, OldVerPath, ReltoolConfig) ->
{Name, Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolConfig),
- NewVerPath =
- filename:join(
- [rebar_rel_utils:get_target_parent_dir(Config, ReltoolConfig),
- Name]),
+ NewVerPath = rebar_rel_utils:get_target_dir(Config, ReltoolConfig),
true = rebar_utils:prop_check(filelib:is_dir(NewVerPath),
"Release directory doesn't exist (~p)~n",
[NewVerPath]),
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 618427f..2d227b6 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -52,6 +52,7 @@
erl_opts/1,
src_dirs/1,
ebin_dir/0,
+ base_dir/1,
processing_base_dir/1, processing_base_dir/2]).
-include("rebar.hrl").
@@ -307,12 +308,15 @@ src_dirs(SrcDirs) ->
ebin_dir() ->
filename:join(get_cwd(), "ebin").
+base_dir(Config) ->
+ rebar_config:get_xconf(Config, base_dir).
+
processing_base_dir(Config) ->
Cwd = rebar_utils:get_cwd(),
processing_base_dir(Config, Cwd).
processing_base_dir(Config, Dir) ->
- Dir =:= rebar_config:get_xconf(Config, base_dir).
+ Dir =:= base_dir(Config).
%% ====================================================================
%% Internal functions
diff --git a/src/rebar_xref.erl b/src/rebar_xref.erl
index 0d89460..16e8cc4 100644
--- a/src/rebar_xref.erl
+++ b/src/rebar_xref.erl
@@ -103,9 +103,11 @@ info(help, xref) ->
"Valid rebar.config options:~n"
" ~p~n"
" ~p~n"
+ " ~p~n"
" ~p~n",
[
{xref_warnings, false},
+ {xref_extra_paths,[]},
{xref_checks, [undefined_function_calls, undefined_functions,
locals_not_used, exports_not_used,
deprecated_function_calls, deprecated_functions]},
@@ -144,8 +146,9 @@ code_path(Config) ->
%% functions, even though those functions are present as part
%% of compilation. H/t to @dluna. Long term we should tie more
%% properly into the overall compile code path if possible.
- BaseDir = rebar_config:get_xconf(Config, base_dir),
+ BaseDir = rebar_utils:base_dir(Config),
[P || P <- code:get_path() ++
+ rebar_config:get(Config, xref_extra_paths, []) ++
[filename:join(BaseDir, filename:join(SubDir, "ebin"))
|| SubDir <- rebar_config:get(Config, sub_dirs, [])],
filelib:is_dir(P)].