summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--.travis.yml2
-rw-r--r--CONTRIBUTING.md94
-rw-r--r--Makefile1
-rw-r--r--README.md72
-rw-r--r--RELEASE-NOTES.md33
-rw-r--r--THANKS1
-rwxr-xr-xbootstrap3
-rw-r--r--dialyzer_reference4
-rw-r--r--ebin/rebar.app8
-rw-r--r--include/rebar.hrl2
-rw-r--r--inttest/depplugins/base_dir_cwd_plugin.erl7
-rw-r--r--inttest/depplugins/dep_cwd_plugin.erl7
-rw-r--r--inttest/depplugins/depplugins_rt.erl43
-rw-r--r--inttest/depplugins/rebar.config1
-rw-r--r--inttest/depplugins/rebar_testplugin.config1
-rw-r--r--inttest/depplugins/testplugin_mod.erl9
-rw-r--r--inttest/logging/logging_rt.erl99
-rwxr-xr-xinttest/retestbin16957 -> 0 bytes
-rw-r--r--inttest/rgen1/retest.config1
-rw-r--r--inttest/t_custom_config/t_custom_config_rt.erl2
-rw-r--r--inttest/tdeps3/a.erl3
-rw-r--r--inttest/tdeps3/a.rebar.config4
-rw-r--r--inttest/tdeps3/b.hrl1
-rw-r--r--inttest/tdeps3/b.rebar.config5
-rw-r--r--inttest/tdeps3/c.hrl1
-rw-r--r--inttest/tdeps3/c.rebar.config1
-rw-r--r--inttest/tdeps3/d.hrl1
-rw-r--r--inttest/tdeps3/d.rebar.config1
-rw-r--r--inttest/tdeps3/e.hrl1
-rw-r--r--inttest/tdeps3/f.hrl1
-rw-r--r--inttest/tdeps3/root.rebar.config1
-rw-r--r--inttest/tdeps3/tdeps3_rt.erl89
-rw-r--r--inttest/tdeps_update/a.erl3
-rw-r--r--inttest/tdeps_update/a.rebar.config1
-rw-r--r--inttest/tdeps_update/a2.rebar.config1
-rw-r--r--inttest/tdeps_update/a3.rebar.config1
-rw-r--r--inttest/tdeps_update/a4.rebar.config4
-rw-r--r--inttest/tdeps_update/b.hrl1
-rw-r--r--inttest/tdeps_update/b.rebar.config1
-rw-r--r--inttest/tdeps_update/b2.rebar.config1
-rw-r--r--inttest/tdeps_update/b3.rebar.config1
-rw-r--r--inttest/tdeps_update/b4.rebar.config1
-rw-r--r--inttest/tdeps_update/c.hrl1
-rw-r--r--inttest/tdeps_update/c.rebar.config1
-rw-r--r--inttest/tdeps_update/c2.hrl1
-rw-r--r--inttest/tdeps_update/c2.rebar.config4
-rw-r--r--inttest/tdeps_update/c3.rebar.config4
-rw-r--r--inttest/tdeps_update/d.hrl1
-rw-r--r--inttest/tdeps_update/root.rebar.config1
-rw-r--r--inttest/tdeps_update/tdeps_update_rt.erl147
-rw-r--r--priv/shell-completion/bash/rebar1
-rw-r--r--priv/shell-completion/zsh/_rebar9
-rw-r--r--priv/templates/simplelib.app.src14
-rw-r--r--priv/templates/simplelib.erl18
-rw-r--r--priv/templates/simplelib.template3
-rwxr-xr-xpriv/templates/simplenode.runner1
-rw-r--r--rebar.config.sample30
-rw-r--r--rebar.config.script5
-rw-r--r--src/rebar.erl154
-rw-r--r--src/rebar_app_utils.erl9
-rw-r--r--src/rebar_base_compiler.erl44
-rw-r--r--src/rebar_config.erl5
-rw-r--r--src/rebar_core.erl28
-rw-r--r--src/rebar_ct.erl16
-rw-r--r--src/rebar_deps.erl223
-rw-r--r--src/rebar_dia_compiler.erl4
-rw-r--r--src/rebar_erlc_compiler.erl502
-rw-r--r--src/rebar_erlydtl_compiler.erl63
-rw-r--r--src/rebar_eunit.erl76
-rw-r--r--src/rebar_getopt.erl (renamed from src/getopt.erl)90
-rw-r--r--src/rebar_lfe_compiler.erl4
-rw-r--r--src/rebar_log.erl37
-rw-r--r--src/rebar_mustache.erl (renamed from src/mustache.erl)10
-rw-r--r--src/rebar_neotoma_compiler.erl8
-rw-r--r--src/rebar_port_compiler.erl12
-rw-r--r--src/rebar_qc.erl7
-rw-r--r--src/rebar_templater.erl34
-rw-r--r--src/rebar_upgrade.erl33
-rw-r--r--src/rebar_utils.erl20
-rw-r--r--src/rebar_xref.erl7
81 files changed, 1659 insertions, 484 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/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..30693d8
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,94 @@
+Contributing to rebar
+---------------------
+
+Before implementing a new feature, please submit a ticket to discuss your plans.
+The feature might have been rejected already, or the implementation might already be decided.
+
+See [Community and Resources](README.md#community-and-resources).
+
+Code style
+----------
+
+The following rules must be followed:
+ * Do not introduce trailing whitespace
+ * Do not mix spaces and tabs
+ * Do not introduce lines longer than 80 characters
+
+The following rules should be followed:
+ * Write small functions whenever possible
+ * Avoid having too many clauses containing clauses containing clauses.
+ Basically, avoid deeply nested functions.
+
+[erlang-mode (emacs)](http://www.erlang.org/doc/man/erlang.el.html)
+indentation is preferred. This will keep the code base consistent.
+vi users are encouraged to give [Vim emulation](http://emacswiki.org/emacs/Evil) ([more
+info](https://gitorious.org/evil/pages/Home)) a try.
+
+Pull requests and branching
+---------------------------
+
+Use one topic branch per pull request. If you do that, you can add extra commits or fix up
+buggy commits via `git rebase -i`, and update the branch. The updated branch will be
+visible in the same pull request. Therefore, you should not open a new pull request when
+you have to fix your changes.
+
+Do not commit to master in your fork.
+
+Provide a clean branch without merge commits.
+
+Committing your changes
+-----------------------
+
+Please ensure that all commits pass all tests, and do not have extra Dialyzer warnings.
+To do that run `make check`. If you didn't build via `make debug` at first, the beam files in
+`ebin/` might be missing debug_info required for [xref](http://www.erlang.org/doc/man/xref.html)
+and [Dialyzer](http://www.erlang.org/doc/man/dialyzer.html), causing a test
+failure.
+If that happens, running `make clean` before running `make check` could solve the problem.
+If you change any of the files with known but safe to ignore Dialyzer warnings, you may
+have to adapt the line number(s) in [dialyzer_reference](dialyzer_reference). If you do that,
+do not remove the
+leading blank line.
+
+#### Structuring your commits
+
+Fixing a bug is one commit.
+Adding a feature is one commit.
+Adding two features is two commits.
+Two unrelated changes is two commits.
+
+If you fix a (buggy) commit, squash (`git rebase -i`) the changes as a fixup commit into
+the original commit.
+
+#### Writing Commit Messages
+
+It's important to write a proper commit title and description. The commit title must be
+at most 50 characters; it is the first line of the commit text. The second line of the
+commit text must be left blank. The third line and beyond is the commit message. You
+should write a commit message. If you do, wrap all lines at 72 characters. You should
+explain what the commit does, what references you used, and any other information
+that helps understanding your changes.
+
+Basically, structure your commit message like this:
+
+<pre>
+One line summary (at most 50 characters)
+
+Longer description (wrap at 72 characters)
+</pre>
+
+##### Commit title/summary
+
+* At most 50 characters
+* What was changed
+* Imperative present tense (Fix, Add, Change)
+ * `Fix bug 123`
+ * `Add 'foobar' command`
+ * `Change default timeout to 123`
+* No period
+
+##### Commit description
+
+* Wrap at 72 characters
+* Why, explain intention and implementation approach
+* Present tense
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/README.md b/README.md
index 3be5091..3ec4a3a 100644
--- a/README.md
+++ b/README.md
@@ -51,77 +51,7 @@ and you can use rebar to build OTP-compliant apps.
Contributing to rebar
=====================
-Pull requests and branching
----------------------------
-
-Use one topic branch per pull request.
-
-Do not commit to master in your fork.
-
-Provide a clean branch without any merge commits from upstream.
-
-Usually you should squash any intermediate commits into the original single commit.
-
-Code style
-----------
-
-Do not introduce trailing whitespace.
-
-Do not mix spaces and tabs.
-
-Do not introduce lines longer than 80 characters.
-
-[erlang-mode (emacs)](http://www.erlang.org/doc/man/erlang.el.html) indentation
-is preferred. vi-only users are encouraged to give [Vim
-emulation](http://emacswiki.org/emacs/Evil) ([more
-info](https://gitorious.org/evil/pages/Home)) a try.
-
-Writing Commit Messages
------------------------
-
-Structure your commit message like this:
-
-<pre>
-One line summary (less than 50 characters)
-
-Longer description (wrap at 72 characters)
-</pre>
-
-### Summary
-
-* Less than 50 characters
-* What was changed
-* Imperative present tense (fix, add, change)
- * `Fix bug 123`
- * `Add 'foobar' command`
- * `Change default timeout to 123`
-* No period
-
-### Description
-
-* Wrap at 72 characters
-* Why, explain intention and implementation approach
-* Present tense
-
-### Atomicity
-
-* Break up logical changes
-* Make whitespace changes separately
-
-Run checks
-----------
-
-Before you submit a patch, run ``make check`` to execute the test suite and
-check for [xref](http://www.erlang.org/doc/man/xref.html) and
-[Dialyzer](http://www.erlang.org/doc/man/dialyzer.html) warnings. You may have
-to run ``make clean`` first.
-
-[Dialyzer](http://www.erlang.org/doc/man/dialyzer.html) warnings are compared
-against a set of safe-to-ignore warnings found in
-[dialyzer_reference](https://raw.github.com/rebar/rebar/master/dialyzer_reference).
-[xref](http://www.erlang.org/doc/man/xref.html) is run with [custom
-queries](https://raw.github.com/rebar/rebar/master/rebar.config) to suppress
-safe-to-ignore warnings.
+Please refer to [CONTRIBUTING](CONTRIBUTING.md).
Community and Resources
-----------------------
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/bootstrap b/bootstrap
index 70d8da1..019aaea 100755
--- a/bootstrap
+++ b/bootstrap
@@ -56,7 +56,8 @@ main(Args) ->
%% Run rebar compile to do proper .app validation etc.
%% and rebar escriptize to create the rebar script
- rebar:main(["compile", "escriptize"] ++ Args),
+ RebarArgs = Args -- ["debug"], %% Avoid trying to run 'debug' command
+ rebar:main(["compile", "escriptize"] ++ RebarArgs),
%% Finally, update executable perms for our script on *nix,
%% or write out script files on win32.
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 d3a50df..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-pre"},
+ {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,
@@ -50,7 +50,7 @@
tools]},
{env, [
%% Default log level
- {log_level, error},
+ {log_level, warn},
%% any_dir processing modules
{any_dir_modules, [
diff --git a/include/rebar.hrl b/include/rebar.hrl
index 58debfc..b19fdd3 100644
--- a/include/rebar.hrl
+++ b/include/rebar.hrl
@@ -9,6 +9,6 @@
-define(DEBUG(Str, Args), rebar_log:log(debug, Str, Args)).
-define(INFO(Str, Args), rebar_log:log(info, Str, Args)).
-define(WARN(Str, Args), rebar_log:log(warn, Str, Args)).
--define(ERROR(Str, Args), rebar_log:log(error, Str, Args)).
+-define(ERROR(Str, Args), rebar_log:log(standard_error, error, Str, Args)).
-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).
diff --git a/inttest/depplugins/base_dir_cwd_plugin.erl b/inttest/depplugins/base_dir_cwd_plugin.erl
new file mode 100644
index 0000000..4953b8b
--- /dev/null
+++ b/inttest/depplugins/base_dir_cwd_plugin.erl
@@ -0,0 +1,7 @@
+-module(base_dir_cwd_plugin).
+-export([pre_compile/2]).
+
+pre_compile(_, _) ->
+ File = "base_dir_cwd_pre.compile",
+ ok = file:write_file(File, <<"base_dir cwd pre_compile plugin">>),
+ rebar_log:log(info, "Wrote ~p/~s~n", [rebar_utils:get_cwd(), File]).
diff --git a/inttest/depplugins/dep_cwd_plugin.erl b/inttest/depplugins/dep_cwd_plugin.erl
new file mode 100644
index 0000000..fe1ceba
--- /dev/null
+++ b/inttest/depplugins/dep_cwd_plugin.erl
@@ -0,0 +1,7 @@
+-module(dep_cwd_plugin).
+-export([pre_compile/2]).
+
+pre_compile(_, _) ->
+ File = "dep_cwd_pre.compile",
+ ok = file:write_file(File, <<"dep cwd pre_compile plugin">>),
+ rebar_log:log(info, "Wrote ~p/~s~n", [rebar_utils:get_cwd(), File]).
diff --git a/inttest/depplugins/depplugins_rt.erl b/inttest/depplugins/depplugins_rt.erl
index 7b106eb..a45fa93 100644
--- a/inttest/depplugins/depplugins_rt.erl
+++ b/inttest/depplugins/depplugins_rt.erl
@@ -4,11 +4,14 @@
%%%
%%% It has three applications:
%%% <ol>
-%%% <li>fish. top-level module, has one dependency: `dependsonplugin'.</li>
-%%% <li>dependsonplugin. This depends on some pre-compile actions by the
-%%% plugin. In the test the plugin creates a file `pre.compile' in the
-%%% top-level folder of this application.</li>
-%%% <li>testplugin. This is a plugin application which creates the file.</li>
+%%% <li>fish. top-level app, has one dependency: `dependsonplugin'.
+%%% It also loads a plugin from CWD which creates
+%%% base_dir_cwd_pre.compile on pre_compile.</li>
+%%% <li>dependsonplugin, has one dependency: `testplugin' and loads
+%%% the testplugin_mod plugin.</li>
+%%% <li>testplugin. This is a plugin application which creates
+%%% plugin_pre.compile on pre_compile. It also loads a plugin from CWD
+%%% which creates dep_cwd_pre.compile on pre_compile.</li>
%%% </ol>
-module(depplugins_rt).
@@ -20,21 +23,37 @@ files() ->
[
{copy, "../../rebar", "rebar"},
{copy, "rebar.config", "rebar.config"},
+ {copy, "base_dir_cwd_plugin.erl", "base_dir_cwd_plugin.erl"},
{create, "ebin/fish.app", app(fish, [])},
- {create, "deps/dependsonplugin/ebin/dependsonplugin.app",
- app(dependsonplugin, [])},
{copy, "rebar_dependsonplugin.config",
- "deps/dependsonplugin/rebar.config"},
+ "deps/dependsonplugin/rebar.config"},
+ {create, "deps/dependsonplugin/ebin/dependsonplugin.app",
+ app(dependsonplugin, [])},
+
+ {copy, "rebar_testplugin.config", "deps/testplugin/rebar.config"},
{copy, "testplugin_mod.erl",
- "deps/testplugin/plugins/testplugin_mod.erl"},
- {create, "deps/testplugin/ebin/testplugin.app",
- app(testplugin, [])}
+ "deps/testplugin/plugins/testplugin_mod.erl"},
+ {copy, "dep_cwd_plugin.erl", "deps/testplugin/dep_cwd_plugin.erl"},
+ {create, "deps/testplugin/ebin/testplugin.app", app(testplugin, [])}
].
run(_Dir) ->
?assertMatch({ok, _}, retest_sh:run("./rebar compile", [])),
- ?assertEqual(true, filelib:is_regular("deps/dependsonplugin/pre.compile")),
+
+ ?assertEqual(true, filelib:is_regular("base_dir_cwd_pre.compile")),
+
+ ?assertEqual(true, filelib:is_regular(
+ "deps/dependsonplugin/base_dir_cwd_pre.compile")),
+ ?assertEqual(true, filelib:is_regular(
+ "deps/dependsonplugin/plugin_pre.compile")),
+
+ ?assertEqual(true, filelib:is_regular(
+ "deps/testplugin/base_dir_cwd_pre.compile")),
+ ?assertEqual(true, filelib:is_regular(
+ "deps/testplugin/dep_cwd_pre.compile")),
+ ?assertEqual(true, filelib:is_regular(
+ "deps/testplugin/plugin_pre.compile")),
ok.
%%
diff --git a/inttest/depplugins/rebar.config b/inttest/depplugins/rebar.config
index 3a2e34e..86fb037 100644
--- a/inttest/depplugins/rebar.config
+++ b/inttest/depplugins/rebar.config
@@ -1 +1,2 @@
{deps, [dependsonplugin]}.
+{plugins, [base_dir_cwd_plugin]}.
diff --git a/inttest/depplugins/rebar_testplugin.config b/inttest/depplugins/rebar_testplugin.config
new file mode 100644
index 0000000..58a1f99
--- /dev/null
+++ b/inttest/depplugins/rebar_testplugin.config
@@ -0,0 +1 @@
+{plugins, [dep_cwd_plugin]}.
diff --git a/inttest/depplugins/testplugin_mod.erl b/inttest/depplugins/testplugin_mod.erl
index 055bbc7..d829ff0 100644
--- a/inttest/depplugins/testplugin_mod.erl
+++ b/inttest/depplugins/testplugin_mod.erl
@@ -1,6 +1,7 @@
-module(testplugin_mod).
--compile(export_all).
+-export([pre_compile/2]).
-pre_compile(Config, _) ->
- ok = file:write_file("pre.compile", <<"Yadda!">>),
- rebar_log:log(info, "Wrote ~p/pre.compile~n", [rebar_utils:get_cwd()]).
+pre_compile(_, _) ->
+ File = "plugin_pre.compile",
+ ok = file:write_file(File, <<"Yadda!">>),
+ rebar_log:log(info, "Wrote ~p/~s~n", [rebar_utils:get_cwd(), File]).
diff --git a/inttest/logging/logging_rt.erl b/inttest/logging/logging_rt.erl
new file mode 100644
index 0000000..2b8e54b
--- /dev/null
+++ b/inttest/logging/logging_rt.erl
@@ -0,0 +1,99 @@
+-module(logging_rt).
+-export([files/0,
+ run/1]).
+
+-define(APP_FILE, "ebin/logging.app").
+
+files() ->
+ [
+ {copy, "../../rebar", "rebar"},
+ {create, ?APP_FILE, app(invalid_name, [])}
+ ].
+
+run(_Dir) ->
+ SharedExpected = "==> logging_rt \\(compile\\)",
+ %% provoke ERROR due to an invalid app file
+ retest:log(info, "Check 'compile' failure output~n"),
+ ok = check_output("./rebar compile -q", should_fail,
+ [SharedExpected, "ERROR: "],
+ ["WARN: ", "INFO: ", "DEBUG: "]),
+ %% fix bad app file
+ ok = file:write_file(?APP_FILE, app(logging, [])),
+ retest:log(info, "Check 'compile' success output~n"),
+ ok = check_output("./rebar compile", should_succeed,
+ [SharedExpected],
+ ["ERROR: ", "WARN: ", "INFO: ", "DEBUG: "]),
+ retest:log(info, "Check 'compile -v' success output~n"),
+ ok = check_output("./rebar compile -v", should_succeed,
+ [SharedExpected],
+ ["ERROR: ", "INFO: ", "DEBUG: "]),
+ retest:log(info, "Check 'compile -vv' success output~n"),
+ ok = check_output("./rebar compile -vv", should_succeed,
+ [SharedExpected, "DEBUG: "],
+ ["ERROR: ", "INFO: "]),
+ ok.
+
+check_output(Cmd, FailureMode, Expected, Unexpected) ->
+ case {retest:sh(Cmd), FailureMode} of
+ {{error, _}=Error, should_succeed} ->
+ retest:log(error, "cmd '~s' failed:~n~p~n", [Cmd, Error]),
+ Error;
+ {{ok, Captured}, should_succeed} ->
+ Joined = string:join(Captured, "\n"),
+ check_output1(Cmd, Joined, Expected, Unexpected);
+ {{error, {stopped, {_Rc, Captured}}}, should_fail} ->
+ Joined = string:join(Captured, "\n"),
+ check_output1(Cmd, Joined, Expected, Unexpected)
+ end.
+
+check_output1(Cmd, Captured, Expected, Unexpected) ->
+ ReOpts = [{capture, all, list}],
+ ExMatches =
+ lists:zf(
+ fun(Pattern) ->
+ case re:run(Captured, Pattern, ReOpts) of
+ nomatch ->
+ retest:log(error,
+ "Expected pattern '~s' missing "
+ "in the following output:~n"
+ "=== BEGIN ===~n~s~n=== END ===~n",
+ [Pattern, Captured]),
+ {true, Pattern};
+ {match, _} ->
+ false
+ end
+ end, Expected),
+
+ UnExMatches =
+ lists:zf(
+ fun(Pattern) ->
+ case re:run(Captured, Pattern, ReOpts) of
+ nomatch ->
+ false;
+ {match, [Match]} ->
+ retest:log(
+ console,
+ "Unexpected output when running cmd '~s':~n~s~n",
+ [Cmd, Match]),
+ {true, Match}
+ end
+ end, Unexpected),
+
+ case {ExMatches, UnExMatches} of
+ {[], []} ->
+ ok;
+ _ ->
+ error
+ end.
+
+%%
+%% 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/inttest/retest b/inttest/retest
deleted file mode 100755
index 4e14bde..0000000
--- a/inttest/retest
+++ /dev/null
Binary files differ
diff --git a/inttest/rgen1/retest.config b/inttest/rgen1/retest.config
new file mode 100644
index 0000000..b569f14
--- /dev/null
+++ b/inttest/rgen1/retest.config
@@ -0,0 +1 @@
+{timeout, 120000}.
diff --git a/inttest/t_custom_config/t_custom_config_rt.erl b/inttest/t_custom_config/t_custom_config_rt.erl
index 864ce5e..b56eb1a 100644
--- a/inttest/t_custom_config/t_custom_config_rt.erl
+++ b/inttest/t_custom_config/t_custom_config_rt.erl
@@ -11,7 +11,7 @@ files() ->
run(Dir) ->
retest_log:log(debug, "Running in Dir: ~s~n", [Dir]),
- Ref = retest:sh("./rebar -C custom.config check-deps -vvv",
+ Ref = retest:sh("./rebar -C custom.config check-deps -vv",
[{async, true}]),
{ok, Captured} =
retest:sh_expect(Ref,
diff --git a/inttest/tdeps3/a.erl b/inttest/tdeps3/a.erl
new file mode 100644
index 0000000..5a387eb
--- /dev/null
+++ b/inttest/tdeps3/a.erl
@@ -0,0 +1,3 @@
+-module({{module}}).
+
+-include_lib("{{dep}}/include/{{dep}}.hrl").
diff --git a/inttest/tdeps3/a.rebar.config b/inttest/tdeps3/a.rebar.config
new file mode 100644
index 0000000..19b8ef8
--- /dev/null
+++ b/inttest/tdeps3/a.rebar.config
@@ -0,0 +1,4 @@
+{deps, [
+ {b, "1", {git, "../repo/b"}},
+ {f, "1", {git, "../repo/f"}}
+]}.
diff --git a/inttest/tdeps3/b.hrl b/inttest/tdeps3/b.hrl
new file mode 100644
index 0000000..efbeab1
--- /dev/null
+++ b/inttest/tdeps3/b.hrl
@@ -0,0 +1 @@
+-include_lib("c/include/c.hrl").
diff --git a/inttest/tdeps3/b.rebar.config b/inttest/tdeps3/b.rebar.config
new file mode 100644
index 0000000..d1ccae2
--- /dev/null
+++ b/inttest/tdeps3/b.rebar.config
@@ -0,0 +1,5 @@
+{deps, [
+ {c, "1", {git, "../repo/c"}}
+]}.
+
+{lib_dirs, [apps]}.
diff --git a/inttest/tdeps3/c.hrl b/inttest/tdeps3/c.hrl
new file mode 100644
index 0000000..cc87fff
--- /dev/null
+++ b/inttest/tdeps3/c.hrl
@@ -0,0 +1 @@
+-include_lib("d/include/d.hrl").
diff --git a/inttest/tdeps3/c.rebar.config b/inttest/tdeps3/c.rebar.config
new file mode 100644
index 0000000..b590771
--- /dev/null
+++ b/inttest/tdeps3/c.rebar.config
@@ -0,0 +1 @@
+{deps, [{d, "1", {git, "../repo/d"}}]}.
diff --git a/inttest/tdeps3/d.hrl b/inttest/tdeps3/d.hrl
new file mode 100644
index 0000000..02f8088
--- /dev/null
+++ b/inttest/tdeps3/d.hrl
@@ -0,0 +1 @@
+-include_lib("e/include/e.hrl").
diff --git a/inttest/tdeps3/d.rebar.config b/inttest/tdeps3/d.rebar.config
new file mode 100644
index 0000000..4c7cd54
--- /dev/null
+++ b/inttest/tdeps3/d.rebar.config
@@ -0,0 +1 @@
+{deps, [{e, "1", {git, "../repo/e"}}]}.
diff --git a/inttest/tdeps3/e.hrl b/inttest/tdeps3/e.hrl
new file mode 100644
index 0000000..9f02fab
--- /dev/null
+++ b/inttest/tdeps3/e.hrl
@@ -0,0 +1 @@
+-define(HELLO, hello).
diff --git a/inttest/tdeps3/f.hrl b/inttest/tdeps3/f.hrl
new file mode 100644
index 0000000..02f8088
--- /dev/null
+++ b/inttest/tdeps3/f.hrl
@@ -0,0 +1 @@
+-include_lib("e/include/e.hrl").
diff --git a/inttest/tdeps3/root.rebar.config b/inttest/tdeps3/root.rebar.config
new file mode 100644
index 0000000..d1c3793
--- /dev/null
+++ b/inttest/tdeps3/root.rebar.config
@@ -0,0 +1 @@
+{sub_dirs, ["apps/a"]}.
diff --git a/inttest/tdeps3/tdeps3_rt.erl b/inttest/tdeps3/tdeps3_rt.erl
new file mode 100644
index 0000000..da87d43
--- /dev/null
+++ b/inttest/tdeps3/tdeps3_rt.erl
@@ -0,0 +1,89 @@
+-module(tdeps3_rt).
+
+-compile(export_all).
+
+%% Exercise transitive dependencies where there are multiple files
+%% depending on the same set of deps as well as lib_dir directives
+%% A -> B -> C -> D -> E
+%% |--> G(via lib_dir)
+%% |--> F -> D -> E
+
+files() ->
+ [
+ %% A1 application
+ {create, "ebin/a.app", app(a, [a])},
+ {template, "a.erl", "src/a.erl", dict:from_list([{module, a}, {dep, b}])},
+
+ {copy, "a.rebar.config", "rebar.config"},
+ {copy, "../../rebar", "rebar"},
+
+ %% B application
+ {create, "repo/b/ebin/b.app", app(b, [b])},
+ {template, "a.erl", "repo/b/src/b.erl", dict:from_list([{module, b}, {dep, b}])},
+ {copy, "b.rebar.config", "repo/b/rebar.config"},
+ {copy, "b.hrl", "repo/b/include/b.hrl"},
+
+ %% C application
+ {create, "repo/c/ebin/c.app", app(c, [c])},
+ {template, "a.erl", "repo/c/src/c.erl", dict:from_list([{module, c}, {dep, d}])},
+ {copy, "c.rebar.config", "repo/c/rebar.config"},
+ {copy, "c.hrl", "repo/c/include/c.hrl"},
+
+ %% D application
+ {create, "repo/d/ebin/d.app", app(d, [d])},
+ {template, "a.erl", "repo/d/src/d.erl", dict:from_list([{module, d}, {dep, e}])},
+ {copy, "d.rebar.config", "repo/d/rebar.config"},
+ {copy, "d.hrl", "repo/d/include/d.hrl"},
+
+ %% E application
+ {create, "repo/e/ebin/e.app", app(e, [])},
+ {copy, "e.hrl", "repo/e/include/e.hrl"},
+
+
+ %% F application
+ {create, "repo/f/ebin/f.app", app(f, [f])},
+ {template, "a.erl", "repo/f/src/f.erl", dict:from_list([{module, f}, {dep, d}])},
+ {copy, "c.rebar.config", "repo/f/rebar.config"},
+ {copy, "f.hrl", "repo/f/include/f.hrl"},
+
+ %% G application, which is part of the B repo, in a lib_dir
+ {create, "repo/b/apps/g/ebin/g.app", app(g, [])},
+ {copy, "e.hrl", "repo/b/apps/g/include/g.hrl"}
+
+ ].
+
+apply_cmds([], _Params) ->
+ ok;
+apply_cmds([Cmd | Rest], Params) ->
+ io:format("Running: ~s (~p)\n", [Cmd, Params]),
+ {ok, _} = retest_sh:run(Cmd, Params),
+ apply_cmds(Rest, Params).
+
+run(_Dir) ->
+ %% Initialize the b/c apps as git repos so that dependencies pull
+ %% properly
+ GitCmds = ["git init",
+ "git add -A",
+ "git config user.email 'tdeps@example.com'",
+ "git config user.name 'tdeps'",
+ "git commit -a -m 'Initial Commit'"],
+ ok = apply_cmds(GitCmds, [{dir, "repo/b"}]),
+ ok = apply_cmds(GitCmds, [{dir, "repo/c"}]),
+ ok = apply_cmds(GitCmds, [{dir, "repo/d"}]),
+ ok = apply_cmds(GitCmds, [{dir, "repo/e"}]),
+ ok = apply_cmds(GitCmds, [{dir, "repo/f"}]),
+
+ {ok, _} = retest_sh:run("./rebar -v get-deps compile", []),
+ ok.
+
+%%
+%% 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/inttest/tdeps_update/a.erl b/inttest/tdeps_update/a.erl
new file mode 100644
index 0000000..294ae21
--- /dev/null
+++ b/inttest/tdeps_update/a.erl
@@ -0,0 +1,3 @@
+-module({{module}}).
+
+-include_lib("b/include/b.hrl").
diff --git a/inttest/tdeps_update/a.rebar.config b/inttest/tdeps_update/a.rebar.config
new file mode 100644
index 0000000..3b721dc
--- /dev/null
+++ b/inttest/tdeps_update/a.rebar.config
@@ -0,0 +1 @@
+{deps, [{b, "0.2.3", {git, "../repo/b", {tag, "0.2.3"}}}]}.
diff --git a/inttest/tdeps_update/a2.rebar.config b/inttest/tdeps_update/a2.rebar.config
new file mode 100644
index 0000000..5687349
--- /dev/null
+++ b/inttest/tdeps_update/a2.rebar.config
@@ -0,0 +1 @@
+{deps, [{b, "0.2.4", {git, "../repo/b", {tag, "0.2.4"}}}]}.
diff --git a/inttest/tdeps_update/a3.rebar.config b/inttest/tdeps_update/a3.rebar.config
new file mode 100644
index 0000000..86bf462
--- /dev/null
+++ b/inttest/tdeps_update/a3.rebar.config
@@ -0,0 +1 @@
+{deps, [{b, "0.2.5", {git, "../repo/b", {tag, "0.2.5"}}}]}.
diff --git a/inttest/tdeps_update/a4.rebar.config b/inttest/tdeps_update/a4.rebar.config
new file mode 100644
index 0000000..bfba813
--- /dev/null
+++ b/inttest/tdeps_update/a4.rebar.config
@@ -0,0 +1,4 @@
+{deps, [
+ {b, "0.2.6", {git, "../repo/b", {tag, "0.2.6"}}},
+ {f, "0.1", {git, "../repo/f", {tag, "0.1"}}}
+ ]}.
diff --git a/inttest/tdeps_update/b.hrl b/inttest/tdeps_update/b.hrl
new file mode 100644
index 0000000..efbeab1
--- /dev/null
+++ b/inttest/tdeps_update/b.hrl
@@ -0,0 +1 @@
+-include_lib("c/include/c.hrl").
diff --git a/inttest/tdeps_update/b.rebar.config b/inttest/tdeps_update/b.rebar.config
new file mode 100644
index 0000000..536aaa9
--- /dev/null
+++ b/inttest/tdeps_update/b.rebar.config
@@ -0,0 +1 @@
+{deps, [{c, "1.0", {git, "../repo/c", {tag, "1.0"}}}]}.
diff --git a/inttest/tdeps_update/b2.rebar.config b/inttest/tdeps_update/b2.rebar.config
new file mode 100644
index 0000000..b603277
--- /dev/null
+++ b/inttest/tdeps_update/b2.rebar.config
@@ -0,0 +1 @@
+{deps, [{c, "1.1", {git, "../repo/c", {tag, "1.1"}}}]}.
diff --git a/inttest/tdeps_update/b3.rebar.config b/inttest/tdeps_update/b3.rebar.config
new file mode 100644
index 0000000..5f4e20a
--- /dev/null
+++ b/inttest/tdeps_update/b3.rebar.config
@@ -0,0 +1 @@
+{deps, [{c, "1.2", {git, "../repo/c", {tag, "1.2"}}}]}.
diff --git a/inttest/tdeps_update/b4.rebar.config b/inttest/tdeps_update/b4.rebar.config
new file mode 100644
index 0000000..5fd1dca
--- /dev/null
+++ b/inttest/tdeps_update/b4.rebar.config
@@ -0,0 +1 @@
+{deps, [{c, "1.3", {git, "../repo/c", {tag, "1.3"}}}]}.
diff --git a/inttest/tdeps_update/c.hrl b/inttest/tdeps_update/c.hrl
new file mode 100644
index 0000000..9f02fab
--- /dev/null
+++ b/inttest/tdeps_update/c.hrl
@@ -0,0 +1 @@
+-define(HELLO, hello).
diff --git a/inttest/tdeps_update/c.rebar.config b/inttest/tdeps_update/c.rebar.config
new file mode 100644
index 0000000..d99b963
--- /dev/null
+++ b/inttest/tdeps_update/c.rebar.config
@@ -0,0 +1 @@
+{deps, [{d, "0.7", {git, "../repo/d", {tag, "0.7"}}}]}.
diff --git a/inttest/tdeps_update/c2.hrl b/inttest/tdeps_update/c2.hrl
new file mode 100644
index 0000000..cc87fff
--- /dev/null
+++ b/inttest/tdeps_update/c2.hrl
@@ -0,0 +1 @@
+-include_lib("d/include/d.hrl").
diff --git a/inttest/tdeps_update/c2.rebar.config b/inttest/tdeps_update/c2.rebar.config
new file mode 100644
index 0000000..1297e07
--- /dev/null
+++ b/inttest/tdeps_update/c2.rebar.config
@@ -0,0 +1,4 @@
+{deps, [
+ {d, "0.7", {git, "../repo/d", {tag, "0.7"}}},
+ {e, "2.0", {git, "../repo/e", {tag, "2.0"}}}
+ ]}.
diff --git a/inttest/tdeps_update/c3.rebar.config b/inttest/tdeps_update/c3.rebar.config
new file mode 100644
index 0000000..40c93c5
--- /dev/null
+++ b/inttest/tdeps_update/c3.rebar.config
@@ -0,0 +1,4 @@
+{deps, [
+ {d, "0.7", {git, "../repo/d", {tag, "0.7"}}},
+ {e, "2.1", {git, "../repo/e", {tag, "2.1"}}}
+ ]}.
diff --git a/inttest/tdeps_update/d.hrl b/inttest/tdeps_update/d.hrl
new file mode 100644
index 0000000..9f02fab
--- /dev/null
+++ b/inttest/tdeps_update/d.hrl
@@ -0,0 +1 @@
+-define(HELLO, hello).
diff --git a/inttest/tdeps_update/root.rebar.config b/inttest/tdeps_update/root.rebar.config
new file mode 100644
index 0000000..ea03437
--- /dev/null
+++ b/inttest/tdeps_update/root.rebar.config
@@ -0,0 +1 @@
+{sub_dirs, ["apps/a1"]}.
diff --git a/inttest/tdeps_update/tdeps_update_rt.erl b/inttest/tdeps_update/tdeps_update_rt.erl
new file mode 100644
index 0000000..81bb7ef
--- /dev/null
+++ b/inttest/tdeps_update/tdeps_update_rt.erl
@@ -0,0 +1,147 @@
+-module(tdeps_update_rt).
+
+-compile(export_all).
+
+%% Exercises update deps, with recursive dependency updates.
+%% Initially:
+%% A(v0.5) -> B(v0.2.3) -> C(v1.0)
+%% But after updating A to 0.6:
+%% A(v0.6) -> B(v0.2.4) -> C(v1.1)
+%% -> D(v0.7)
+%% And after updating A to 0.7:
+%% A(v0.7) -> B(v0.2.5) -> C(v1.2) -> E(v2.0)
+%% -> D(v0.7)
+%% And after updating A to 0.8:
+%% A(v0.8) -> B(v0.2.6) -> C(v1.3) -> E(v2.1)
+%% -> D(v0.7)
+%% -> F(v0.1) -> E(v2.1)
+files() ->
+ [
+ %% A1 application
+ {create, "apps/a1/ebin/a1.app", app(a1, [a1], "0.5")},
+ {copy, "a.rebar.config", "apps/a1/rebar.config"},
+ {template, "a.erl", "apps/a1/src/a1.erl", dict:from_list([{module, a1}])},
+
+ {copy, "root.rebar.config", "rebar.config"},
+ {copy, "../../rebar", "rebar"},
+
+ %% B application
+ {create, "repo/b/ebin/b.app", app(b, [], "0.2.3")},
+ {create, "b2.app", app(b, [], "0.2.4")},
+ {create, "b3.app", app(b, [], "0.2.5")},
+ {create, "b4.app", app(b, [], "0.2.6")},
+ {copy, "b.rebar.config", "repo/b/rebar.config"},
+ {copy, "b.hrl", "repo/b/include/b.hrl"},
+
+ %% C application
+ {create, "repo/c/ebin/c.app", app(c, [], "1.0")},
+ {create, "c2.app", app(c, [], "1.1")},
+ {create, "c3.app", app(c, [], "1.2")},
+ {create, "c4.app", app(c, [], "1.3")},
+ {copy, "c.hrl", "repo/c/include/c.hrl"},
+
+ %% D application
+ {create, "repo/d/ebin/d.app", app(d, [], "0.7")},
+ {copy, "d.hrl", "repo/d/include/d.hrl"},
+
+ %% E application
+ {create, "repo/e/ebin/e.app", app(e, [], "2.0")},
+ {create, "e2.app", app(e, [], "2.1")},
+
+ %% F application
+ {create, "repo/f/ebin/f.app", app(f, [], "0.1")},
+
+ %% update files
+ {copy, "a2.rebar.config", "a2.rebar.config"},
+ {copy, "a3.rebar.config", "a3.rebar.config"},
+ {copy, "a4.rebar.config", "a4.rebar.config"},
+ {copy, "b2.rebar.config", "b2.rebar.config"},
+ {copy, "b3.rebar.config", "b3.rebar.config"},
+ {copy, "b4.rebar.config", "b4.rebar.config"},
+ {copy, "c2.hrl", "c2.hrl"},
+ {copy, "c.rebar.config", "c.rebar.config"},
+ {copy, "c2.rebar.config", "c2.rebar.config"},
+ {copy, "c3.rebar.config", "c3.rebar.config"}
+ ].
+
+apply_cmds([], _Params) ->
+ ok;
+apply_cmds([Cmd | Rest], Params) ->
+ io:format("Running: ~s (~p)\n", [Cmd, Params]),
+ {ok, _} = retest_sh:run(Cmd, Params),
+ apply_cmds(Rest, Params).
+
+run(_Dir) ->
+ %% Initialize the b/c/d apps as git repos so that dependencies pull
+ %% properly
+ GitCmds = ["git init",
+ "git add -A",
+ "git config user.email 'tdeps@example.com'",
+ "git config user.name 'tdeps'",
+ "git commit -a -m 'Initial Commit'"],
+ BCmds = ["git tag 0.2.3",
+ "cp ../../b2.rebar.config rebar.config",
+ "cp ../../b2.app ebin/b.app",
+ "git commit -a -m 'update to 0.2.4'",
+ "git tag 0.2.4",
+ "cp ../../b3.rebar.config rebar.config",
+ "cp ../../b3.app ebin/b.app",
+ "git commit -a -m 'update to 0.2.5'",
+ "git tag 0.2.5",
+ "cp ../../b4.rebar.config rebar.config",
+ "cp ../../b4.app ebin/b.app",
+ "git commit -a -m 'update to 0.2.6'",
+ "git tag 0.2.6"],
+ %"git checkout 0.2.3"],
+ CCmds = ["git tag 1.0",
+ "cp ../../c2.hrl include/c.hrl",
+ "cp ../../c2.app ebin/c.app",
+ "cp ../../c.rebar.config rebar.config",
+ "git add rebar.config",
+ "git commit -a -m 'update to 1.1'",
+ "git tag 1.1",
+ "cp ../../c3.app ebin/c.app",
+ "cp ../../c2.rebar.config rebar.config",
+ "git commit -a -m 'update to 1.2'",
+ "git tag 1.2",
+ "cp ../../c4.app ebin/c.app",
+ "cp ../../c3.rebar.config rebar.config",
+ "git commit -a -m 'update to 1.3'",
+ "git tag 1.3"],
+ %"git checkout 1.0"],
+ DCmds = ["git tag 0.7"],
+ ECmds = ["git tag 2.0",
+ "cp ../../e2.app ebin/e.app",
+ "git commit -a -m 'update to 2.1'",
+ "git tag 2.1"],
+ FCmds = ["git tag 0.1"],
+
+ ok = apply_cmds(GitCmds++BCmds, [{dir, "repo/b"}]),
+ ok = apply_cmds(GitCmds++CCmds, [{dir, "repo/c"}]),
+ ok = apply_cmds(GitCmds++DCmds, [{dir, "repo/d"}]),
+ ok = apply_cmds(GitCmds++ECmds, [{dir, "repo/e"}]),
+ ok = apply_cmds(GitCmds++FCmds, [{dir, "repo/f"}]),
+
+ {ok, _} = retest_sh:run("./rebar -v get-deps compile", []),
+ os:cmd("cp a2.rebar.config apps/a1/rebar.config"),
+ {ok, _} = retest_sh:run("./rebar -v update-deps", []),
+ {ok, _} = retest_sh:run("./rebar -v compile", []),
+ os:cmd("cp a3.rebar.config apps/a1/rebar.config"),
+ {ok, _} = retest_sh:run("./rebar -v update-deps", []),
+ {ok, _} = retest_sh:run("./rebar -v compile", []),
+ os:cmd("cp a4.rebar.config apps/a1/rebar.config"),
+ {ok, _} = retest_sh:run("./rebar -v update-deps", []),
+ {ok, _} = retest_sh:run("./rebar -v compile", []),
+ ok.
+
+%%
+%% Generate the contents of a simple .app file
+%%
+app(Name, Modules, Version) ->
+ App = {application, Name,
+ [{description, atom_to_list(Name)},
+ {vsn, Version},
+ {modules, Modules},
+ {registered, []},
+ {applications, [kernel, stdlib]}]},
+ io_lib:format("~p.\n", [App]).
diff --git a/priv/shell-completion/bash/rebar b/priv/shell-completion/bash/rebar
index d4a42dc..7dc3b5e 100644
--- a/priv/shell-completion/bash/rebar
+++ b/priv/shell-completion/bash/rebar
@@ -21,6 +21,7 @@ _rebar()
compile \
create \
create-app \
+ create-lib \
create-node \
ct \
doc \
diff --git a/priv/shell-completion/zsh/_rebar b/priv/shell-completion/zsh/_rebar
index 3d04ba1..384fead 100644
--- a/priv/shell-completion/zsh/_rebar
+++ b/priv/shell-completion/zsh/_rebar
@@ -7,10 +7,10 @@ _rebar_global_opts=(
'(--help -h)'{--help,-h}'[Show the program options]'
'(--commands -c)'{--commands,-c}'[Show available commands]'
'(--version -V)'{--version,-V}'[Show version information]'
- '(-vvv -vv -v)'--verbose+'[Verbosity level. Default: 0]:verbosity level:(0 1 2 3)'
- '(-vvv)-v[Slightly more verbose output]'
- '(-vvv)-vv[More verbose output]'
- '(-v -vv)-vvv[Most verbose output]'
+ '(-vv -v)'--verbose'[Enforce verbosity level]'
+ '(-vv)-v[Slightly more verbose output]'
+ '(-v)-vv[More verbose output]'
+ '(-vv -v --verbose)'{--quiet,-q}'[Quiet, only print error messages]'
'(--force -f)'{--force,-f}'[Force]'
'-D+[Define compiler macro]'
'(--jobs -j)'{--jobs+,-j+}'[Number of concurrent workers a command may use. Default: 3]:workers:(1 2 3 4 5 6 7 8 9)'
@@ -31,6 +31,7 @@ _rebar () {
'compile[Compile sources]' \
'create[Create skel based on template and vars]' \
'create-app[Create simple app skel]' \
+ 'create-lib[Create simple lib skel]' \
'create-node[Create simple node skel]' \
'list-template[List avaiavle templates]' \
'doc[Generate Erlang program documentation]' \
diff --git a/priv/templates/simplelib.app.src b/priv/templates/simplelib.app.src
new file mode 100644
index 0000000..752665a
--- /dev/null
+++ b/priv/templates/simplelib.app.src
@@ -0,0 +1,14 @@
+{application, {{libid}},
+ [
+ {description, "An Erlang {{libid}} library"},
+ {vsn, "1"},
+ {modules, [
+ {{libid}}
+ ]},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {env, []}
+ ]}.
diff --git a/priv/templates/simplelib.erl b/priv/templates/simplelib.erl
new file mode 100644
index 0000000..2c4451f
--- /dev/null
+++ b/priv/templates/simplelib.erl
@@ -0,0 +1,18 @@
+-module({{libid}}).
+
+%% {{libid}}: {{libid}} library's entry point.
+
+-export([my_func/0]).
+
+
+%% API
+
+my_func() ->
+ ok().
+
+%% Internals
+
+ok() ->
+ ok.
+
+%% End of Module.
diff --git a/priv/templates/simplelib.template b/priv/templates/simplelib.template
new file mode 100644
index 0000000..59d20fa
--- /dev/null
+++ b/priv/templates/simplelib.template
@@ -0,0 +1,3 @@
+{variables, [{libid, "mylib"}]}.
+{template, "simplelib.app.src", "src/{{libid}}.app.src"}.
+{template, "simplelib.erl", "src/{{libid}}.erl"}.
diff --git a/priv/templates/simplenode.runner b/priv/templates/simplenode.runner
index 260d067..032eb28 100755
--- a/priv/templates/simplenode.runner
+++ b/priv/templates/simplenode.runner
@@ -16,6 +16,7 @@ fi
unset POSIX_SHELL
RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd -P)
+RUNNER_SCRIPT=${0##*/}
CALLER_DIR=$PWD
diff --git a/rebar.config.sample b/rebar.config.sample
index 97b5a02..30d28d0 100644
--- a/rebar.config.sample
+++ b/rebar.config.sample
@@ -152,11 +152,17 @@
%% 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 supports git, hg, bzr, svn, and rsync.
-{deps, [application_name,
- {application_name, "1.0.*"},
- {application_name, "1.0.*",
+%% Rebar currently supports git, hg, bzr, svn, rsync, and fossil.
+{deps, [app_name,
+ {rebar, "1.0.*"},
+ {rebar, ".*",
+ {git, "git://github.com/rebar/rebar.git"}},
+ {rebar, ".*",
+ {git, "git://github.com/rebar/rebar.git", "Rev"}},
+ {rebar, "1.0.*",
{git, "git://github.com/rebar/rebar.git", {branch, "master"}}},
+ {rebar, "1.0.0",
+ {git, "git://github.com/rebar/rebar.git", {tag, "1.0.0"}}},
%% Dependencies can be marked as 'raw'. Rebar does not require
%% such dependencies to have a standard Erlang/OTP layout
%% which assumes the presence of either
@@ -170,9 +176,16 @@
%% Only a subset of rebar commands will be executed on the
%% 'raw' subdirectories: get-deps, update-deps, check-deps,
%% list-deps and delete-deps.
- {application_name, "",
+ {rebar, "",
{git, "git://github.com/rebar/rebar.git", {branch, "master"}},
- [raw]}]}.
+ [raw]},
+ {app_name, ".*", {hg, "https://www.example.org/url"}},
+ {app_name, ".*", {rsync, "Url"}},
+ {app_name, ".*", {svn, "https://www.example.org/url"}},
+ {app_name, ".*", {svn, "svn://svn.example.org/url"}},
+ {app_name, ".*", {bzr, "https://www.example.org/url", "Rev"}},
+ {app_name, ".*", {fossil, "https://www.example.org/url"}},
+ {app_name, ".*", {fossil, "https://www.example.org/url", "Vsn"}}]}.
%% == Subdirectories ==
@@ -208,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/rebar.config.script b/rebar.config.script
index 07feb95..6735645 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -1,10 +1,7 @@
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
-%% TODO: Change temporary retest fork back to dizzyd/retest after merge
-%% ExtraDeps = [{retest, ".*", {git, "git://github.com/dizzyd/retest.git"}}],
-ExtraDeps = [{retest, ".*",
- {git, "git://github.com/tuncer/retest.git", "next"}}],
+ExtraDeps = [{retest, ".*", {git, "git://github.com/dizzyd/retest.git"}}],
case os:getenv("REBAR_EXTRA_DEPS") of
false ->
diff --git a/src/rebar.erl b/src/rebar.erl
index 1902f14..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}} ->
@@ -258,13 +272,27 @@ save_options(Config, {Options, NonOptArgs}) ->
%% set log level based on getopt option
%%
set_log_level(Config, Options) ->
- LogLevel = case proplists:get_all_values(verbose, Options) of
- [] ->
- rebar_log:default_level();
- Verbosities ->
- lists:last(Verbosities)
- end,
- rebar_config:set_global(Config, verbose, LogLevel).
+ {IsVerbose, Level} =
+ case proplists:get_bool(quiet, Options) of
+ true ->
+ {false, rebar_log:error_level()};
+ false ->
+ DefaultLevel = rebar_log:default_level(),
+ case proplists:get_all_values(verbose, Options) of
+ [] ->
+ {false, DefaultLevel};
+ Verbosities ->
+ {true, DefaultLevel + lists:last(Verbosities)}
+ end
+ end,
+
+ case IsVerbose of
+ true ->
+ Config1 = rebar_config:set_xconf(Config, is_verbose, true),
+ rebar_config:set_global(Config1, verbose, Level);
+ false ->
+ rebar_config:set_global(Config, verbose, Level)
+ end.
%%
%% show version information and halt
@@ -317,50 +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-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).
@@ -375,12 +407,12 @@ option_spec_list() ->
JobsHelp = io_lib:format(
"Number of concurrent workers a command may use. Default: ~B",
[Jobs]),
- VerboseHelp = "Verbosity level (-v, -vv, -vvv, --verbose 3). Default: 0",
[
%% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg}
{help, $h, "help", undefined, "Show the program options"},
{commands, $c, "commands", undefined, "Show available commands"},
- {verbose, $v, "verbose", integer, VerboseHelp},
+ {verbose, $v, "verbose", integer, "Verbosity level (-v, -vv)"},
+ {quiet, $q, "quiet", boolean, "Quiet, only print error messages"},
{version, $V, "version", undefined, "Show version information"},
{force, $f, "force", undefined, "Force"},
{defines, $D, undefined, string, "Define compiler macro"},
@@ -417,11 +449,33 @@ filter_flags(Config, [Item | Rest], Commands) ->
end.
command_names() ->
- ["check-deps", "clean", "compile", "create", "create-app", "create-node",
- "ct", "delete-deps", "doc", "eunit", "escriptize", "generate",
- "generate-appups", "generate-upgrade", "get-deps", "help", "list-deps",
- "list-templates", "qc", "update-deps", "overlay", "shell", "version",
- "xref"].
+ [
+ "check-deps",
+ "clean",
+ "compile",
+ "create",
+ "create-app",
+ "create-lib",
+ "create-node",
+ "ct",
+ "delete-deps",
+ "doc",
+ "eunit",
+ "escriptize",
+ "generate",
+ "generate-appups",
+ "generate-upgrade",
+ "get-deps",
+ "help",
+ "list-deps",
+ "list-templates",
+ "qc",
+ "update-deps",
+ "overlay",
+ "shell",
+ "version",
+ "xref"
+ ].
unabbreviate_command_names([]) ->
[];
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_config.erl b/src/rebar_config.erl
index 461de5d..9b58d4f 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -31,7 +31,6 @@
get_all/2,
set/3,
set_global/3, get_global/3,
- is_verbose/1,
save_env/3, get_env/2, reset_envs/1,
set_skip_dir/2, is_skip_dir/2, reset_skip_dirs/1,
clean_config/2,
@@ -110,10 +109,6 @@ get_global(Config, Key, Default) ->
Value
end.
-is_verbose(Config) ->
- DefaulLevel = rebar_log:default_level(),
- get_global(Config, verbose, DefaulLevel) > DefaulLevel.
-
consult_file(File) ->
case filename:extension(File) of
".script" ->
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index fcfa62a..4efc978 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -163,6 +163,13 @@ skip_or_process_dir({_, ModuleSetFile}=ModuleSet, Config, CurrentCodePath,
skip_or_process_dir1(AppFile, ModuleSet, Config, CurrentCodePath,
Dir, Command, DirSet) ->
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);
{Config1, {true, SkippedApp}} ->
?DEBUG("Skipping app: ~p~n", [SkippedApp]),
Config2 = increment_operations(Config1),
@@ -172,8 +179,9 @@ skip_or_process_dir1(AppFile, ModuleSet, Config, CurrentCodePath,
CurrentCodePath, ModuleSet)
end.
-process_dir1(Dir, Command, DirSet, Config0, CurrentCodePath,
+process_dir1(Dir, Command, DirSet, Config, CurrentCodePath,
{DirModules, ModuleSetFile}) ->
+ 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
@@ -391,18 +399,19 @@ update_code_path(Config) ->
[] ->
no_change;
Paths ->
- OldPath = code:get_path(),
LibPaths = expand_lib_dirs(Paths, rebar_utils:get_cwd(), []),
ok = code:add_pathsa(LibPaths),
- {old, OldPath}
+ %% track just the paths we added, so we can remove them without
+ %% removing other paths added by this dep
+ {added, LibPaths}
end.
restore_code_path(no_change) ->
ok;
-restore_code_path({old, Path}) ->
+restore_code_path({added, Paths}) ->
%% Verify that all of the paths still exist -- some dynamically
%% added paths can get blown away during clean.
- true = code:set_path([F || F <- Path, erl_prim_loader_is_file(F)]),
+ _ = [code:del_path(F) || F <- Paths, erl_prim_loader_is_file(F)],
ok.
erl_prim_loader_is_file(File) ->
@@ -493,6 +502,8 @@ acc_modules([Module | Rest], Command, Config, File, Acc) ->
%%
plugin_modules(Config, PredirsAssoc) ->
Modules = lists:flatten(rebar_config:get_all(Config, plugins)),
+ ?DEBUG("Plugins requested while processing ~s: ~p~n",
+ [rebar_utils:get_cwd(), Modules]),
plugin_modules(Config, PredirsAssoc, ulist(Modules)).
ulist(L) ->
@@ -534,6 +545,7 @@ plugin_modules(Config, PredirsAssoc, FoundModules, MissingModules) ->
load_plugin_modules(Config, PredirsAssoc, Modules) ->
Cwd = rebar_utils:get_cwd(),
PluginDirs = get_all_plugin_dirs(Config, Cwd, PredirsAssoc),
+ ?DEBUG("Plugin dirs for ~s:~n~p~n", [Cwd, PluginDirs]),
%% Find relevant sources in base_dir and plugin_dir
Erls = string:join([atom_to_list(M)++"\\.erl" || M <- Modules], "|"),
@@ -549,7 +561,9 @@ load_plugin_modules(Config, PredirsAssoc, Modules) ->
{Loaded, NotLoaded}.
get_all_plugin_dirs(Config, Cwd, PredirsAssoc) ->
- get_plugin_dir(Config, Cwd) ++ get_base_plugin_dirs(Cwd, PredirsAssoc).
+ [rebar_utils:get_cwd()]
+ ++ get_plugin_dir(Config, Cwd)
+ ++ get_base_plugin_dirs(Cwd, PredirsAssoc).
get_plugin_dir(Config, Cwd) ->
case rebar_config:get_local(Config, plugin_dir, undefined) of
@@ -568,7 +582,7 @@ get_base_plugin_dirs(Cwd, PredirsAssoc) ->
[filename:join(Dir, "plugins") ||
Dir <- get_plugin_base_dirs(Cwd, PredirsAssoc)].
-%% @doc PredirsAssoc is a dictionary of plugindir -> 'parent' pairs
+%% @doc PredirsAssoc is a dictionary of plugindir -> 'parent' pairs.
%% 'parent' in this case depends on plugin; therefore we have to give
%% all plugins that Cwd ('parent' in this case) depends on.
get_plugin_base_dirs(Cwd, PredirsAssoc) ->
diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl
index 04b2a51..f3ed29f 100644
--- a/src/rebar_ct.erl
+++ b/src/rebar_ct.erl
@@ -101,7 +101,7 @@ run_test(TestDir, LogDir, Config, _File) ->
{Cmd, RawLog} = make_cmd(TestDir, LogDir, Config),
?DEBUG("ct_run cmd:~n~p~n", [Cmd]),
clear_log(LogDir, RawLog),
- Output = case rebar_config:is_verbose(Config) of
+ Output = case rebar_log:is_verbose(Config) of
false ->
" >> " ++ RawLog ++ " 2>&1";
true ->
@@ -149,7 +149,7 @@ check_fail_log(Config, RawLog, Command, Result) ->
check_log(Config,RawLog,Fun) ->
{ok, Msg} =
- rebar_utils:sh("grep -e 'TEST COMPLETE' -e '{error,make_failed}' "
+ rebar_utils:sh("grep -e \"TEST COMPLETE\" -e \"{error,make_failed}\" "
++ RawLog, [{use_stdout, false}]),
MakeFailed = string:str(Msg, "{error,make_failed}") =/= 0,
RunFailed = string:str(Msg, ", 0 failed") =:= 0,
@@ -172,7 +172,7 @@ check_log(Config,RawLog,Fun) ->
%% Show the log if it hasn't already been shown because verbose was on
show_log(Config, RawLog) ->
?CONSOLE("Showing log\n", []),
- case rebar_config:is_verbose(Config) of
+ case rebar_log:is_verbose(Config) of
false ->
{ok, Contents} = file:read_file(RawLog),
?CONSOLE("~s", [Contents]);
@@ -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 be6283d..43bde04 100644
--- a/src/rebar_deps.erl
+++ b/src/rebar_deps.erl
@@ -68,37 +68,57 @@ preprocess(Config, _) ->
%% Add available deps to code path
Config3 = update_deps_code_path(Config2, AvailableDeps),
- %% If skip_deps=true, mark each dep dir as a skip_dir w/ the core so that
- %% the current command doesn't run on the dep dir. However, pre/postprocess
- %% WILL run (and we want it to) for transitivity purposes.
- %%
- %% Also, if skip_deps=comma,separated,app,list, then only the given
- %% dependencies are skipped.
- NewConfig = case rebar_config:get_global(Config3, skip_deps, false) of
- "true" ->
- lists:foldl(
- fun(#dep{dir = Dir}, C) ->
- rebar_config:set_skip_dir(C, Dir)
- end, Config3, AvailableDeps);
- Apps when is_list(Apps) ->
- SkipApps = [list_to_atom(App) || App <- string:tokens(Apps, ",")],
- lists:foldl(
- fun(#dep{dir = Dir, app = App}, C) ->
- case lists:member(App, SkipApps) of
- true -> rebar_config:set_skip_dir(C, Dir);
- false -> C
- end
- end, Config3, AvailableDeps);
- _ ->
- Config3
- end,
-
%% Filtering out 'raw' dependencies so that no commands other than
%% deps-related can be executed on their directories.
NonRawAvailableDeps = [D || D <- AvailableDeps, not D#dep.is_raw],
- %% Return all the available dep directories for process
- {ok, NewConfig, dep_dirs(NonRawAvailableDeps)}.
+ case rebar_config:get_xconf(Config, current_command, undefined) of
+ 'update-deps' ->
+ %% Skip ALL of the dep folders, we do this because we don't want
+ %% any other calls to preprocess() for update-deps beyond the
+ %% toplevel directory. They aren't actually harmful, but they slow
+ %% things down unnecessarily.
+ NewConfig = lists:foldl(
+ fun(D, Acc) ->
+ rebar_config:set_skip_dir(Acc, D#dep.dir)
+ end,
+ Config3,
+ collect_deps(rebar_utils:get_cwd(), Config3)),
+ %% Return the empty list, as we don't want anything processed before
+ %% us.
+ {ok, NewConfig, []};
+ _ ->
+ %% If skip_deps=true, mark each dep dir as a skip_dir w/ the core
+ %% so that the current command doesn't run on the dep dir.
+ %% However, pre/postprocess WILL run (and we want it to) for
+ %% transitivity purposes.
+ %%
+ %% Also, if skip_deps=comma,separated,app,list, then only the given
+ %% dependencies are skipped.
+ NewConfig =
+ case rebar_config:get_global(Config3, skip_deps, false) of
+ "true" ->
+ lists:foldl(
+ fun(#dep{dir = Dir}, C) ->
+ rebar_config:set_skip_dir(C, Dir)
+ end, Config3, AvailableDeps);
+ Apps when is_list(Apps) ->
+ SkipApps = [list_to_atom(App) ||
+ App <- string:tokens(Apps, ",")],
+ lists:foldl(
+ fun(#dep{dir = Dir, app = App}, C) ->
+ case lists:member(App, SkipApps) of
+ true -> rebar_config:set_skip_dir(C, Dir);
+ false -> C
+ end
+ end, Config3, AvailableDeps);
+ _ ->
+ Config3
+ end,
+
+ %% Return all the available dep directories for process
+ {ok, NewConfig, dep_dirs(NonRawAvailableDeps)}
+ end.
postprocess(Config, _) ->
case rebar_config:get_xconf(Config, ?MODULE, undefined) of
@@ -169,17 +189,24 @@ do_check_deps(Config) ->
{ok, save_dep_dirs(Config2, lists:reverse(PulledDeps))}.
'update-deps'(Config, _) ->
- %% Determine what deps are required
- RawDeps = rebar_config:get_local(Config, deps, []),
- {Config1, Deps} = find_deps(Config, read, RawDeps),
-
- %% Update each dep
- UpdatedDeps = [update_source(Config1, D)
- || D <- Deps, D#dep.source =/= undefined],
+ Config1 = rebar_config:set_xconf(Config, depowner, dict:new()),
+ {Config2, UpdatedDeps} = update_deps_int(Config1, []),
+ DepOwners = rebar_config:get_xconf(Config2, depowner, dict:new()),
+
+ %% check for conflicting deps
+ _ = [?ERROR("Conflicting dependencies for ~p: ~p~n",
+ [K, [{"From: " ++ string:join(dict:fetch(D, DepOwners), ", "),
+ {D#dep.vsn_regex, D#dep.source}} || D <- V]])
+ || {K, V} <- dict:to_list(
+ lists:foldl(
+ fun(Dep, Acc) ->
+ dict:append(Dep#dep.app, Dep, Acc)
+ end, dict:new(), UpdatedDeps)),
+ length(V) > 1],
%% Add each updated dep to our list of dirs for post-processing. This yields
%% the necessary transitivity of the deps
- {ok, save_dep_dirs(Config1, UpdatedDeps)}.
+ {ok, save_dep_dirs(Config, UpdatedDeps)}.
'delete-deps'(Config, _) ->
%% Delete all the available deps in our deps/ directory, if any
@@ -230,13 +257,27 @@ info_help(Description) ->
[
Description,
{deps_dir, "deps"},
- {deps, [application_name,
- {application_name, "1.0.*"},
- {application_name, "1.0.*",
- {git, "git://github.com/rebar/rebar.git", {branch, "master"}}},
- {application_name, "",
- {git, "git://github.com/rebar/rebar.git", {branch, "master"}},
- [raw]}]}
+ {deps,
+ [app_name,
+ {rebar, "1.0.*"},
+ {rebar, ".*",
+ {git, "git://github.com/rebar/rebar.git"}},
+ {rebar, ".*",
+ {git, "git://github.com/rebar/rebar.git", "Rev"}},
+ {rebar, "1.0.*",
+ {git, "git://github.com/rebar/rebar.git", {branch, "master"}}},
+ {rebar, "1.0.0",
+ {git, "git://github.com/rebar/rebar.git", {tag, "1.0.0"}}},
+ {rebar, "",
+ {git, "git://github.com/rebar/rebar.git", {branch, "master"}},
+ [raw]},
+ {app_name, ".*", {hg, "https://www.example.org/url"}},
+ {app_name, ".*", {rsync, "Url"}},
+ {app_name, ".*", {svn, "https://www.example.org/url"}},
+ {app_name, ".*", {svn, "svn://svn.example.org/url"}},
+ {app_name, ".*", {bzr, "https://www.example.org/url", "Rev"}},
+ {app_name, ".*", {fossil, "https://www.example.org/url"}},
+ {app_name, ".*", {fossil, "https://www.example.org/url", "Vsn"}}]}
]).
%% Added because of trans deps,
@@ -263,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])}.
@@ -419,7 +460,8 @@ is_app_available(Config, App, VsnRegex, Path, _IsRaw = false) ->
{Config, {false, {missing_app_file, Path}}}
end;
is_app_available(Config, App, _VsnRegex, Path, _IsRaw = true) ->
- ?DEBUG("is_app_available, looking for Raw Depencency ~p with Path ~p~n", [App, Path]),
+ ?DEBUG("is_app_available, looking for Raw Depencency ~p with Path ~p~n",
+ [App, Path]),
case filelib:is_dir(Path) of
true ->
%% TODO: look for version string in <Path>/VERSION file? Not clear
@@ -442,8 +484,8 @@ use_source(Config, Dep, Count) ->
case filelib:is_dir(Dep#dep.dir) of
true ->
%% Already downloaded -- verify the versioning matches the regex
- case is_app_available(Config, Dep#dep.app,
- Dep#dep.vsn_regex, Dep#dep.dir, Dep#dep.is_raw) of
+ case is_app_available(Config, Dep#dep.app, Dep#dep.vsn_regex,
+ Dep#dep.dir, Dep#dep.is_raw) of
{Config1, {true, _}} ->
Dir = filename:join(Dep#dep.dir, "ebin"),
ok = filelib:ensure_dir(filename:join(Dir, "dummy")),
@@ -504,8 +546,6 @@ download_source(AppDir, {rsync, Url}) ->
rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s", [Url, AppDir]), []);
download_source(AppDir, {fossil, Url}) ->
download_source(AppDir, {fossil, Url, ""});
-download_source(AppDir, {fossil, Url, latest}) ->
- download_source(AppDir, {fossil, Url, ""});
download_source(AppDir, {fossil, Url, Version}) ->
Repository = filename:join(AppDir, filename:basename(AppDir) ++ ".fossil"),
ok = filelib:ensure_dir(Repository),
@@ -540,10 +580,12 @@ update_source1(AppDir, {git, Url, ""}) ->
update_source1(AppDir, {git, _Url, {branch, Branch}}) ->
ShOpts = [{cd, AppDir}],
rebar_utils:sh("git fetch origin", ShOpts),
- rebar_utils:sh(?FMT("git checkout -q origin/~s", [Branch]), ShOpts);
+ rebar_utils:sh(?FMT("git checkout -q ~s", [Branch]), ShOpts),
+ rebar_utils:sh(
+ ?FMT("git pull --ff-only --no-rebase -q origin ~s", [Branch]),ShOpts);
update_source1(AppDir, {git, _Url, {tag, Tag}}) ->
ShOpts = [{cd, AppDir}],
- rebar_utils:sh("git fetch --tags origin", ShOpts),
+ rebar_utils:sh("git fetch origin", ShOpts),
rebar_utils:sh(?FMT("git checkout -q ~s", [Tag]), ShOpts);
update_source1(AppDir, {git, _Url, Refspec}) ->
ShOpts = [{cd, AppDir}],
@@ -559,13 +601,90 @@ update_source1(AppDir, {rsync, Url}) ->
rebar_utils:sh(?FMT("rsync -az --delete ~s/ ~s",[Url,AppDir]),[]);
update_source1(AppDir, {fossil, Url}) ->
update_source1(AppDir, {fossil, Url, ""});
-update_source1(AppDir, {fossil, Url, latest}) ->
- update_source1(AppDir, {fossil, Url, ""});
update_source1(AppDir, {fossil, _Url, Version}) ->
ok = file:set_cwd(AppDir),
rebar_utils:sh("fossil pull", [{cd, AppDir}]),
rebar_utils:sh(?FMT("fossil update ~s", [Version]), []).
+%% Recursively update deps, this is not done via rebar's usual dep traversal as
+%% that is the wrong order (tips are updated before branches). Instead we do a
+%% traverse the deps at each level completely before traversing *their* deps.
+%% This allows updates to actually propogate down the tree, rather than fail to
+%% flow up the tree, which was the previous behaviour.
+update_deps_int(Config0, UDD) ->
+ %% Determine what deps are required
+ ConfDir = filename:basename(rebar_utils:get_cwd()),
+ RawDeps = rebar_config:get_local(Config0, deps, []),
+ {Config1, Deps} = find_deps(Config0, read, RawDeps),
+
+ %% Update each dep
+ UpdatedDeps = [update_source(Config1, D)
+ || D <- Deps, D#dep.source =/= undefined,
+ not lists:member(D, UDD),
+ not should_skip_update_dep(Config1, D)
+ ],
+
+ lists:foldl(fun(Dep, {Config, Updated}) ->
+ {true, AppDir} = get_deps_dir(Config, Dep#dep.app),
+ Config2 = case has_vcs_dir(element(1, Dep#dep.source),
+ AppDir) of
+ false ->
+ %% If the dep did not exist (maybe it
+ %% was added), clone it.
+ %% We'll traverse ITS deps below and
+ %% clone them if needed.
+ {C1, _D1} = use_source(Config, Dep),
+ C1;
+ true ->
+ Config
+ end,
+ ok = file:set_cwd(AppDir),
+ Config3 = rebar_config:new(Config2),
+ %% track where a dep comes from...
+ DepOwner = dict:append(
+ Dep, ConfDir,
+ rebar_config:get_xconf(Config3, depowner,
+ dict:new())),
+ Config4 = rebar_config:set_xconf(Config3, depowner,
+ DepOwner),
+
+ {Config5, Res} = update_deps_int(Config4, Updated),
+ {Config5, lists:umerge(lists:sort(Res),
+ lists:sort(Updated))}
+ end, {Config1, lists:umerge(lists:sort(UpdatedDeps),
+ lists:sort(UDD))}, UpdatedDeps).
+
+should_skip_update_dep(Config, Dep) ->
+ {true, AppDir} = get_deps_dir(Config, Dep#dep.app),
+ case rebar_app_utils:is_app_dir(AppDir) of
+ false ->
+ false;
+ {true, AppFile} ->
+ case rebar_app_utils:is_skipped_app(Config, AppFile) of
+ {_Config, {true, _SkippedApp}} ->
+ true;
+ _ ->
+ false
+ end
+ end.
+
+%% Recursively walk the deps and build a list of them.
+collect_deps(Dir, C) ->
+ case file:set_cwd(Dir) of
+ ok ->
+ Config = rebar_config:new(C),
+ RawDeps = rebar_config:get_local(Config, deps, []),
+ {Config1, Deps} = find_deps(Config, read, RawDeps),
+
+ lists:flatten(Deps ++ [begin
+ {true, AppDir} = get_deps_dir(
+ Config1, Dep#dep.app),
+ collect_deps(AppDir, C)
+ end || Dep <- Deps]);
+ _ ->
+ []
+ end.
+
%% ===================================================================
%% Source helper functions
diff --git a/src/rebar_dia_compiler.erl b/src/rebar_dia_compiler.erl
index f81c734..ba9d159 100644
--- a/src/rebar_dia_compiler.erl
+++ b/src/rebar_dia_compiler.erl
@@ -75,8 +75,8 @@ compile_dia(Source, Target, Config) ->
case diameter_dict_util:parse({path, Source}, []) of
{ok, Spec} ->
FileName = dia_filename(Source, Spec),
- diameter_codegen:from_dict(FileName, Spec, Opts, erl),
- diameter_codegen:from_dict(FileName, Spec, Opts, hrl),
+ _ = diameter_codegen:from_dict(FileName, Spec, Opts, erl),
+ _ = diameter_codegen:from_dict(FileName, Spec, Opts, hrl),
HrlFile = filename:join("src", FileName ++ ".hrl"),
case filelib:is_regular(HrlFile) of
true ->
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index caef0d2..75d47fb 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -34,6 +34,18 @@
info/2]).
-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
@@ -89,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(
@@ -102,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
@@ -131,12 +146,13 @@ test_compile(Config, Cmd, OutDir) ->
lists:append(Acc, Files)
end, [], SrcDirs),
- %% If it is not the first time rebar eunit is executed, there will be source
- %% files already present in OutDir. Since some SCMs (like Perforce) set
- %% the source files as being read only (unless they are checked out), we
- %% need to be sure that the files already present in OutDir are writable
- %% before doing the copy. This is done here by removing any file that was
- %% already present before calling rebar_file_utils:cp_r.
+ %% If it is not the first time rebar eunit or rebar qc is executed,
+ %% there will be source files already present in OutDir. Since some
+ %% SCMs (like Perforce) set the source files as being read only (unless
+ %% they are checked out), we need to be sure that the files already
+ %% present in OutDir are writable before doing the copy. This is done
+ %% here by removing any file that was already present before calling
+ %% rebar_file_utils:cp_r.
%% Get the full path to a file that was previously copied in OutDir
ToCleanUp = fun(F, Acc) ->
@@ -156,7 +172,8 @@ 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, Cmd), OutDir, TestErls),
+ ok = doterl_compile(test_compile_config(Config, ErlOpts, Cmd),
+ OutDir, TestErls, ErlOpts),
{ok, SrcErls}.
@@ -200,12 +217,11 @@ info_help(Description) ->
{yrl_first_files, []}
]).
-test_compile_config(Config, Cmd) ->
+test_compile_config(Config, ErlOpts, Cmd) ->
{Config1, TriqOpts} = triq_opts(Config),
{Config2, PropErOpts} = proper_opts(Config1),
{Config3, EqcOpts} = eqc_opts(Config2),
- ErlOpts = rebar_config:get_list(Config3, erl_opts, []),
OptsAtom = list_to_atom(Cmd ++ "_compile_opts"),
EunitOpts = rebar_config:get_list(Config3, OptsAtom, []),
Opts0 = [{d, 'TEST'}] ++
@@ -256,125 +272,281 @@ is_lib_avail(Config, DictKey, Mod, Hrl, Name) ->
-spec doterl_compile(rebar_config:config(), file:filename()) -> 'ok'.
doterl_compile(Config, OutDir) ->
- doterl_compile(Config, OutDir, []).
-
-doterl_compile(Config, OutDir, MoreSources) ->
- FirstErls = rebar_config:get_list(Config, erl_first_files, []),
ErlOpts = rebar_utils:erl_opts(Config),
+ doterl_compile(Config, OutDir, [], ErlOpts).
+
+doterl_compile(Config, OutDir, MoreSources, ErlOpts) ->
+ ErlFirstFiles = rebar_config:get_list(Config, erl_first_files, []),
?DEBUG("erl_opts ~p~n", [ErlOpts]),
%% Support the src_dirs option allowing multiple directories to
%% contain erlang source. This might be used, for example, should
%% 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],
@@ -401,7 +573,14 @@ compile_mib(Source, Target, Config) ->
case snmpc:compile(Source, Opts) of
{ok, _} ->
Mib = filename:rootname(Target),
- ok = snmpc:mib_to_hrl(Mib),
+ MibToHrlOpts =
+ case proplists:get_value(verbosity, Opts, undefined) of
+ undefined ->
+ #options{specific = []};
+ Verbosity ->
+ #options{specific = [{verbosity, Verbosity}]}
+ end,
+ ok = snmpc:mib_to_hrl(Mib, Mib, MibToHrlOpts),
Hrl_filename = Mib ++ ".hrl",
rebar_file_utils:mv(Hrl_filename, "include"),
ok;
@@ -455,40 +634,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
%%
@@ -501,3 +737,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 4449be6..556e841 100644
--- a/src/rebar_erlydtl_compiler.erl
+++ b/src/rebar_erlydtl_compiler.erl
@@ -116,8 +116,8 @@ compile(Config, _AppFile) ->
option(source_ext, DtlOpts),
option(out_dir, DtlOpts),
option(module_ext, DtlOpts) ++ ".beam",
- fun(S, T, _C) ->
- compile_dtl(S, T, DtlOpts)
+ fun(S, T, C) ->
+ compile_dtl(C, S, T, DtlOpts)
end,
[{check_last_mod, false},
{recursive, option(recursive, DtlOpts)}])
@@ -169,58 +169,71 @@ default(out_dir) -> "ebin";
default(source_ext) -> ".dtl";
default(module_ext) -> "_dtl";
default(custom_tags_dir) -> "";
-default(compiler_options) -> [report, return];
+default(compiler_options) -> [return];
default(recursive) -> true.
-compile_dtl(Source, Target, DtlOpts) ->
+compile_dtl(Config, Source, Target, DtlOpts) ->
case code:which(erlydtl) of
non_existing ->
?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;
_ ->
case needs_compile(Source, Target, DtlOpts) of
true ->
- do_compile(Source, Target, DtlOpts);
+ do_compile(Config, Source, Target, DtlOpts);
false ->
skipped
end
end.
-do_compile(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,
module_name(Target),
Opts) of
- ok -> ok;
- {error, {File, [{Pos, _Mod, Err}]}} ->
- ?ERROR("Compiling template ~p failed:~n (~s): ~p~n",
- [File, err_location(Pos), Err]);
- Reason ->
- ?ERROR("Compiling template ~s failed:~n ~p~n",
- [Source, Reason]),
- ?FAIL
+ 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);
+ {error, Es, Ws} ->
+ rebar_base_compiler:error_tuple(Config, Source, Es, Ws, Opts)
end.
-err_location({L,C}) -> io_lib:format("line:~w, col:~w", [L, C]);
-err_location(L) -> io_lib:format("line:~w", [L]).
-
module_name(Target) ->
F = filename:basename(Target),
string:substr(F, 1, length(F)-length(".beam")).
diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl
index 95ba3e8..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
[] ->
@@ -408,7 +454,7 @@ perform_eunit(Config, Tests) ->
get_eunit_opts(Config) ->
%% Enable verbose in eunit if so requested..
- BaseOpts = case rebar_config:is_verbose(Config) of
+ BaseOpts = case rebar_log:is_verbose(Config) of
true ->
[verbose];
false ->
@@ -802,11 +848,11 @@ pause_until_net_kernel_stopped() ->
pause_until_net_kernel_stopped(0) ->
exit(net_kernel_stop_failed);
pause_until_net_kernel_stopped(N) ->
- try
- timer:sleep(100),
- pause_until_net_kernel_stopped(N - 1)
- catch
- error:badarg ->
+ case node() of
+ 'nonode@nohost' ->
?DEBUG("Stopped net kernel.\n", []),
- ok
+ ok;
+ _ ->
+ timer:sleep(100),
+ pause_until_net_kernel_stopped(N - 1)
end.
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/rebar_lfe_compiler.erl b/src/rebar_lfe_compiler.erl
index 2a047d8..8488b0f 100644
--- a/src/rebar_lfe_compiler.erl
+++ b/src/rebar_lfe_compiler.erl
@@ -70,8 +70,8 @@ compile_lfe(Source, _Target, Config) ->
"~n", []),
?FAIL;
_ ->
- Opts = [{i, "include"}, {outdir, "ebin"}, return]
- ++ rebar_config:get_list(Config, erl_opts, []),
+ ErlOpts = rebar_utils:erl_opts(Config),
+ Opts = [{i, "include"}, {outdir, "ebin"}, return] ++ ErlOpts,
case lfe_comp:file(Source, Opts) of
{ok, _Mod, Ws} ->
rebar_base_compiler:ok_tuple(Config, Source, Ws);
diff --git a/src/rebar_log.erl b/src/rebar_log.erl
index 4108c9c..ba25332 100644
--- a/src/rebar_log.erl
+++ b/src/rebar_log.erl
@@ -27,8 +27,17 @@
-module(rebar_log).
-export([init/1,
- set_level/1, default_level/0,
- log/3]).
+ set_level/1,
+ error_level/0,
+ default_level/0,
+ log/3,
+ log/4,
+ is_verbose/1]).
+
+-define(ERROR_LEVEL, 0).
+-define(WARN_LEVEL, 1).
+-define(INFO_LEVEL, 2).
+-define(DEBUG_LEVEL, 3).
%% ===================================================================
%% Public API
@@ -37,35 +46,39 @@
init(Config) ->
Verbosity = rebar_config:get_global(Config, verbose, default_level()),
case valid_level(Verbosity) of
- 0 -> set_level(error);
- 1 -> set_level(warn);
- 2 -> set_level(info);
- 3 -> set_level(debug)
+ ?ERROR_LEVEL -> set_level(error);
+ ?WARN_LEVEL -> set_level(warn);
+ ?INFO_LEVEL -> set_level(info);
+ ?DEBUG_LEVEL -> set_level(debug)
end.
set_level(Level) ->
ok = application:set_env(rebar, log_level, Level).
log(Level, Str, Args) ->
+ log(standard_io, Level, Str, Args).
+
+log(Device, Level, Str, Args) ->
{ok, LogLevel} = application:get_env(rebar, log_level),
case should_log(LogLevel, Level) of
true ->
- io:format(log_prefix(Level) ++ Str, Args);
+ io:format(Device, log_prefix(Level) ++ Str, Args);
false ->
ok
end.
-default_level() -> error_level().
+error_level() -> ?ERROR_LEVEL.
+default_level() -> ?WARN_LEVEL.
+
+is_verbose(Config) ->
+ rebar_config:get_xconf(Config, is_verbose, false).
%% ===================================================================
%% Internal functions
%% ===================================================================
valid_level(Level) ->
- erlang:max(error_level(), erlang:min(Level, debug_level())).
-
-error_level() -> 0.
-debug_level() -> 3.
+ erlang:max(?ERROR_LEVEL, erlang:min(Level, ?DEBUG_LEVEL)).
should_log(debug, _) -> true;
should_log(info, debug) -> false;
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_neotoma_compiler.erl b/src/rebar_neotoma_compiler.erl
index b9f23f2..5549dc4 100644
--- a/src/rebar_neotoma_compiler.erl
+++ b/src/rebar_neotoma_compiler.erl
@@ -70,10 +70,10 @@ info(help, compile) ->
"Valid rebar.config options:~n"
" ~p~n",
[
- {neotom_opts, [{doc_root, "src"},
- {out_dir, "src"},
- {source_ext, ".peg"},
- {module_ext, ""}]}
+ {neotoma_opts, [{doc_root, "src"},
+ {out_dir, "src"},
+ {source_ext, ".peg"},
+ {module_ext, ""}]}
]).
neotoma_opts(Config) ->
diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index 0abb044..fec8e04 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -498,10 +498,20 @@ erts_dir() ->
os_env() ->
ReOpts = [{return, list}, {parts, 2}, unicode],
- Os = [list_to_tuple(re:split(S, "=", ReOpts)) || S <- os:getenv()],
+ Os = [list_to_tuple(re:split(S, "=", ReOpts)) ||
+ S <- lists:filter(fun discard_deps_vars/1, os:getenv())],
%% Drop variables without a name (win32)
[T1 || {K, _V} = T1 <- Os, K =/= []].
+%%
+%% To avoid having multiple repetitions of the same environment variables
+%% (ERL_LIBS), avoid exporting any variables that may cause conflict with
+%% those exported by the rebar_deps module (ERL_LIBS, REBAR_DEPS_DIR)
+%%
+discard_deps_vars("ERL_LIBS=" ++ _Value) -> false;
+discard_deps_vars("REBAR_DEPS_DIR=" ++ _Value) -> false;
+discard_deps_vars(_Var) -> true.
+
select_compile_template(drv, Compiler) ->
select_compile_drv_template(Compiler);
select_compile_template(exe, Compiler) ->
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 e997975..43bb8da 100644
--- a/src/rebar_templater.erl
+++ b/src/rebar_templater.erl
@@ -27,6 +27,7 @@
-module(rebar_templater).
-export(['create-app'/2,
+ 'create-lib'/2,
'create-node'/2,
'list-templates'/2,
create/2]).
@@ -50,6 +51,10 @@
%% Alias for create w/ template=simpleapp
create1(Config, "simpleapp").
+'create-lib'(Config, _File) ->
+ %% Alias for create w/ template=simplelib
+ create1(Config, "simplelib").
+
'create-node'(Config, _File) ->
%% Alias for create w/ template=simplenode
create1(Config, "simplenode").
@@ -98,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
@@ -116,6 +121,12 @@ info(help, 'create-app') ->
"~n"
"Valid command line options:~n"
" [appid=myapp]~n", []);
+info(help, 'create-lib') ->
+ ?CONSOLE(
+ "Create simple lib skel.~n"
+ "~n"
+ "Valid command line options:~n"
+ " [libid=mylib]~n", []);
info(help, 'create-node') ->
?CONSOLE(
"Create simple node skel.~n"
@@ -347,6 +358,10 @@ write_file(Output, Data, Force) ->
{error, exists}
end.
+prepend_instructions(Instructions, Rest) when is_list(Instructions) ->
+ Instructions ++ Rest;
+prepend_instructions(Instruction, Rest) ->
+ [Instruction|Rest].
%%
%% Execute each instruction in a template definition file.
@@ -364,6 +379,23 @@ execute_template(_Files, [], _TemplateType, _TemplateName,
?ERROR("One or more files already exist on disk and "
"were not generated:~n~s~s", [Msg , Help])
end;
+execute_template(Files, [{'if', Cond, True} | Rest], TemplateType,
+ TemplateName, Context, Force, ExistingFiles) ->
+ execute_template(Files, [{'if', Cond, True, []}|Rest], TemplateType,
+ TemplateName, Context, Force, ExistingFiles);
+execute_template(Files, [{'if', Cond, True, False} | Rest], TemplateType,
+ TemplateName, Context, Force, ExistingFiles) ->
+ Instructions = case dict:find(Cond, Context) of
+ {ok, true} ->
+ True;
+ {ok, "true"} ->
+ True;
+ _ ->
+ False
+ end,
+ execute_template(Files, prepend_instructions(Instructions, Rest),
+ TemplateType, TemplateName, Context, Force,
+ ExistingFiles);
execute_template(Files, [{template, Input, Output} | Rest], TemplateType,
TemplateName, Context, Force, ExistingFiles) ->
InputName = filename:join(filename:dirname(TemplateName), Input),
diff --git a/src/rebar_upgrade.erl b/src/rebar_upgrade.erl
index d18603c..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]),
@@ -184,13 +182,24 @@ boot_files(TargetDir, Ver, Name) ->
filename:join([TargetDir, "releases", Ver, "start_clean.boot"]),
filename:join([".", ?TMP, "releases", Ver, "start_clean.boot"])),
- {ok, _} = file:copy(
- filename:join([TargetDir, "releases", Ver, "sys.config"]),
- filename:join([".", ?TMP, "releases", Ver, "sys.config"])),
-
- {ok, _} = file:copy(
- filename:join([TargetDir, "releases", Ver, "vm.args"]),
- filename:join([".", ?TMP, "releases", Ver, "vm.args"])).
+ SysConfig = filename:join([TargetDir, "releases", Ver, "sys.config"]),
+ _ = case filelib:is_regular(SysConfig) of
+ true ->
+ {ok, _} = file:copy(
+ SysConfig,
+ filename:join([".", ?TMP, "releases", Ver,
+ "sys.config"]));
+ false -> ok
+ end,
+
+ VmArgs = filename:join([TargetDir, "releases", Ver, "vm.args"]),
+ case filelib:is_regular(VmArgs) of
+ true ->
+ {ok, _} = file:copy(
+ VmArgs,
+ filename:join([".", ?TMP, "releases", Ver, "vm.args"]));
+ false -> {ok, 0}
+ end.
make_tar(NameVer, NewVer, NewName) ->
Filename = NameVer ++ ".tar.gz",
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index 4a74661..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").
@@ -200,12 +201,12 @@ expand_env_variable(InStr, VarName, RawVarValue) ->
re:replace(InStr, RegEx, [VarValue, "\\2"], ReOpts)
end.
-vcs_vsn(Config, Vcs, Dir) ->
- Key = {Vcs, Dir},
+vcs_vsn(Config, Vsn, Dir) ->
+ Key = {Vsn, Dir},
Cache = rebar_config:get_xconf(Config, vsn_cache),
case dict:find(Key, Cache) of
error ->
- VsnString = vcs_vsn_1(Vcs, Dir),
+ VsnString = vcs_vsn_1(Vsn, Dir),
Cache1 = dict:store(Key, VsnString, Cache),
Config1 = rebar_config:set_xconf(Config, vsn_cache, Cache1),
{Config1, VsnString};
@@ -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
@@ -441,11 +445,12 @@ emulate_escript_foldl(Fun, Acc, File) ->
vcs_vsn_1(Vcs, Dir) ->
case vcs_vsn_cmd(Vcs) of
- {unknown, VsnString} ->
- ?DEBUG("vcs_vsn: Unknown VCS atom in vsn field: ~p\n", [Vcs]),
+ {plain, VsnString} ->
VsnString;
{cmd, CmdString} ->
vcs_vsn_invoke(CmdString, Dir);
+ unknown ->
+ ?ABORT("vcs_vsn: Unknown vsn format: ~p\n", [Vcs]);
Cmd ->
%% If there is a valid VCS directory in the application directory,
%% use that version info
@@ -478,7 +483,8 @@ vcs_vsn_cmd(bzr) -> "bzr revno";
vcs_vsn_cmd(svn) -> "svnversion";
vcs_vsn_cmd(fossil) -> "fossil info";
vcs_vsn_cmd({cmd, _Cmd}=Custom) -> Custom;
-vcs_vsn_cmd(Version) -> {unknown, Version}.
+vcs_vsn_cmd(Version) when is_list(Version) -> {plain, Version};
+vcs_vsn_cmd(_) -> unknown.
vcs_vsn_invoke(Cmd, Dir) ->
{ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]),
diff --git a/src/rebar_xref.erl b/src/rebar_xref.erl
index eaf6d03..16e8cc4 100644
--- a/src/rebar_xref.erl
+++ b/src/rebar_xref.erl
@@ -51,7 +51,7 @@ xref(Config, _) ->
xref:set_default(xref, [{warnings,
rebar_config:get(Config, xref_warnings, false)},
- {verbose, rebar_config:is_verbose(Config)}]),
+ {verbose, rebar_log:is_verbose(Config)}]),
{ok, _} = xref:add_directory(xref, "ebin"),
@@ -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)].