diff options
-rwxr-xr-x | bootstrap | 3 | ||||
-rw-r--r-- | ebin/rebar.app | 2 | ||||
-rw-r--r-- | include/rebar.hrl | 2 | ||||
-rw-r--r-- | inttest/logging/logging_rt.erl | 99 | ||||
-rwxr-xr-x | inttest/retest | bin | 16957 -> 0 bytes | |||
-rw-r--r-- | inttest/rgen1/retest.config | 1 | ||||
-rw-r--r-- | inttest/t_custom_config/t_custom_config_rt.erl | 2 | ||||
-rw-r--r-- | priv/shell-completion/bash/rebar | 1 | ||||
-rw-r--r-- | priv/shell-completion/zsh/_rebar | 9 | ||||
-rw-r--r-- | priv/templates/simplelib.app.src | 14 | ||||
-rw-r--r-- | priv/templates/simplelib.erl | 18 | ||||
-rw-r--r-- | priv/templates/simplelib.template | 3 | ||||
-rw-r--r-- | rebar.config.sample | 25 | ||||
-rw-r--r-- | rebar.config.script | 5 | ||||
-rw-r--r-- | src/rebar.erl | 65 | ||||
-rw-r--r-- | src/rebar_config.erl | 5 | ||||
-rw-r--r-- | src/rebar_core.erl | 4 | ||||
-rw-r--r-- | src/rebar_ct.erl | 4 | ||||
-rw-r--r-- | src/rebar_deps.erl | 157 | ||||
-rw-r--r-- | src/rebar_dia_compiler.erl | 4 | ||||
-rw-r--r-- | src/rebar_erlc_compiler.erl | 6 | ||||
-rw-r--r-- | src/rebar_eunit.erl | 2 | ||||
-rw-r--r-- | src/rebar_lfe_compiler.erl | 4 | ||||
-rw-r--r-- | src/rebar_log.erl | 37 | ||||
-rw-r--r-- | src/rebar_templater.erl | 11 | ||||
-rw-r--r-- | src/rebar_upgrade.erl | 27 | ||||
-rw-r--r-- | src/rebar_utils.erl | 14 | ||||
-rw-r--r-- | src/rebar_xref.erl | 2 |
28 files changed, 378 insertions, 148 deletions
@@ -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/ebin/rebar.app b/ebin/rebar.app index e64a51f..873be18 100644 --- a/ebin/rebar.app +++ b/ebin/rebar.app @@ -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/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 Binary files differdeleted file mode 100755 index 4e14bde..0000000 --- a/inttest/retest +++ /dev/null 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/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/rebar.config.sample b/rebar.config.sample index 97b5a02..e6071bd 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 == 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..00505be 100644 --- a/src/rebar.erl +++ b/src/rebar.erl @@ -258,13 +258,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 @@ -324,6 +338,7 @@ escriptize Generate escript archive create template= [var=foo,...] Create skel based on template and vars create-app [appid=myapp] Create simple app skel +create-lib [libid=mylib] Create simple lib skel create-node [nodeid=mynode] Create simple node skel list-templates List available templates @@ -375,12 +390,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 +432,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_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 6c4f5c5..631cef2 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -181,7 +181,7 @@ skip_or_process_dir1(AppFile, ModuleSet, Config, CurrentCodePath, process_dir1(Dir, Command, DirSet, Config, CurrentCodePath, {DirModules, ModuleSetFile}) -> - Config0 = rebar_config:set(Config, current_command, Command), + 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 @@ -411,7 +411,7 @@ restore_code_path(no_change) -> restore_code_path({added, Paths}) -> %% Verify that all of the paths still exist -- some dynamically %% added paths can get blown away during clean. - [code:del_path(F) || F <- Paths, 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) -> diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl index 74ae618..91d763b 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 -> @@ -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]); diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl index 5e69709..2e305d5 100644 --- a/src/rebar_deps.erl +++ b/src/rebar_deps.erl @@ -72,43 +72,49 @@ preprocess(Config, _) -> %% deps-related can be executed on their directories. NonRawAvailableDeps = [D || D <- AvailableDeps, not D#dep.is_raw], - case rebar_config:get(Config, current_command, undefined) of + 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)), + 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. + %% 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, + 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)} @@ -183,19 +189,20 @@ do_check_deps(Config) -> {ok, save_dep_dirs(Config2, lists:reverse(PulledDeps))}. 'update-deps'(Config, _) -> - {Config2, UpdatedDeps} = update_deps_int(rebar_config:set(Config, depowner, dict:new()), []), - DepOwners = rebar_config:get(Config2, depowner, dict:new()), + 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], + _ = [?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 @@ -250,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, @@ -439,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 @@ -462,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")), @@ -524,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), @@ -561,7 +581,8 @@ update_source1(AppDir, {git, _Url, {branch, Branch}}) -> ShOpts = [{cd, AppDir}], rebar_utils:sh("git fetch origin", 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); + 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 origin", ShOpts), @@ -580,8 +601,6 @@ 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}]), @@ -607,24 +626,27 @@ update_deps_int(Config0, UDD) -> 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, + 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... - Config4 = rebar_config:set(Config3, depowner, - dict:append(Dep, ConfDir, - rebar_config:get(Config3, - depowner, - dict:new()))), + 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), @@ -655,7 +677,8 @@ collect_deps(Dir, C) -> {Config1, Deps} = find_deps(Config, read, RawDeps), lists:flatten(Deps ++ [begin - {true, AppDir} = get_deps_dir(Config1, Dep#dep.app), + {true, AppDir} = get_deps_dir( + Config1, Dep#dep.app), collect_deps(AppDir, C) end || Dep <- Deps]); _ -> 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 4157ba4..dbefa4a 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -157,7 +157,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), {ok, SrcErls}. @@ -201,12 +202,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'}] ++ diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index d39b1a2..6ea28f7 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -408,7 +408,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 -> 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/rebar_templater.erl b/src/rebar_templater.erl index b8f7087..c21daa3 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"). @@ -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" diff --git a/src/rebar_upgrade.erl b/src/rebar_upgrade.erl index 17676fb..3a38a08 100644 --- a/src/rebar_upgrade.erl +++ b/src/rebar_upgrade.erl @@ -183,21 +183,22 @@ boot_files(TargetDir, Ver, Name) -> filename:join([".", ?TMP, "releases", Ver, "start_clean.boot"])), 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, + _ = 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} + 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) -> diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 4a74661..618427f 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -200,12 +200,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}; @@ -441,11 +441,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 +479,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..0d89460 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"), |