From d8e50e8c2d3af9234d27e8e5a652c5575d1493ad Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Thu, 9 Dec 2010 19:45:58 +0100 Subject: Implement update-deps and disable auto update --- src/rebar_core.erl | 1 + 1 file changed, 1 insertion(+) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 3c64f8d..e8b4e57 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -223,6 +223,7 @@ 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 generate [dump_spec=0/1] Build release with reltool -- cgit v1.1 From a8870807fc6e677b471591ba9313179a5c6c78b6 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 7 Jan 2011 14:58:30 +0100 Subject: Fix code clarity --- src/rebar_core.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index e8b4e57..f8eb6f5 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -453,10 +453,11 @@ execute(Command, Modules, Config, ModuleFile) -> ?FAIL; {Module, {error, _} = Other} -> ?ABORT("~p failed while processing ~s in module ~s: ~s\n", - [Command, Dir, Module, io_lib:print(Other, 1,80,-1)]); + [Command, Dir, Module, + io_lib:print(Other, 1, 80, -1)]); Other -> ?ABORT("~p failed while processing ~s: ~s\n", - [Command, Dir, io_lib:print(Other, 1,80,-1)]) + [Command, Dir, io_lib:print(Other, 1, 80, -1)]) end end. -- cgit v1.1 From d922985b368cebfa10606f347d84eafb06c26d15 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 7 Jan 2011 17:24:27 +0100 Subject: Fix typos --- src/rebar_core.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index f8eb6f5..353a218 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -476,8 +476,8 @@ update_code_path(Config) -> restore_code_path(no_change) -> ok; restore_code_path({old, Path}) -> - %% Verify that all of the paths still exist -- some dynamically add paths - %% can get blown away during clean. + %% 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, filelib:is_file(F)]), ok. -- cgit v1.1 From 932eb2e34335f0f6a4ee845cb5e2e8acec71c831 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Tue, 11 Jan 2011 11:54:10 +0100 Subject: Simplify rebar_core --- src/rebar_core.erl | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 353a218..edf220f 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -120,7 +120,7 @@ parse_args(Args) -> case getopt:parse(OptSpecList, Args) of {ok, {Options, NonOptArgs}} -> %% Check options and maybe halt execution - {ok, continue} = show_info_maybe_halt(Options, NonOptArgs), + ok = show_info_maybe_halt(Options, NonOptArgs), %% Set global variables based on getopt options set_global_flag(Options, verbose), @@ -165,31 +165,25 @@ set_global_flag(Options, Flag) -> %% show info and maybe halt execution %% show_info_maybe_halt(Opts, NonOptArgs) -> - case proplists:get_bool(help, Opts) of - true -> + false = show_info_maybe_halt(help, Opts, fun help/0), + false = show_info_maybe_halt(commands, Opts, fun commands/0), + false = show_info_maybe_halt(version, Opts, fun version/0), + case NonOptArgs of + [] -> + ?CONSOLE("No command to run specified!~n",[]), help(), + halt(1); + _ -> + ok + end. + +show_info_maybe_halt(O, Opts, F) -> + case proplists:get_bool(O, Opts) of + true -> + F(), halt(0); false -> - case proplists:get_bool(commands, Opts) of - true -> - commands(), - halt(0); - false -> - case proplists:get_bool(version, Opts) of - true -> - version(), - halt(0); - false -> - case NonOptArgs of - [] -> - ?CONSOLE("No command to run specified!~n",[]), - help(), - halt(1); - _ -> - {ok, continue} - end - end - end + false end. %% -- cgit v1.1 From d1ff83a8989cd11fbbed794a97c6e13cf6388e21 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Mon, 24 Jan 2011 16:40:50 +0100 Subject: Move command line handling funs into rebar.erl --- src/rebar_core.erl | 175 +---------------------------------------------------- 1 file changed, 3 insertions(+), 172 deletions(-) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index edf220f..86607e2 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -47,12 +47,12 @@ %% =================================================================== run(["help"]) -> - help(), + rebar:help(), ok; run(["version"]) -> %% Load application spec and display vsn and build time info ok = application:load(rebar), - version(), + rebar:version(), ok; run(RawArgs) -> %% Pre-load the rebar app so that we get default configuration @@ -60,7 +60,7 @@ run(RawArgs) -> %% Parse out command line arguments -- what's left is a list of commands to %% run - Commands = parse_args(RawArgs), + Commands = rebar:parse_args(RawArgs), %% Make sure crypto is running ok = crypto:start(), @@ -110,175 +110,6 @@ skip_dirs() -> %% Internal functions %% =================================================================== -%% -%% Parse command line arguments using getopt and also filtering out any -%% key=value pairs. What's left is the list of commands to run -%% -parse_args(Args) -> - %% Parse getopt options - OptSpecList = option_spec_list(), - case getopt:parse(OptSpecList, Args) of - {ok, {Options, NonOptArgs}} -> - %% Check options and maybe halt execution - ok = show_info_maybe_halt(Options, NonOptArgs), - - %% Set global variables based on getopt options - set_global_flag(Options, verbose), - set_global_flag(Options, force), - DefJobs = rebar_config:get_jobs(), - case proplists:get_value(jobs, Options, DefJobs) of - DefJobs -> - ok; - Jobs -> - rebar_config:set_global(jobs, Jobs) - end, - - %% Set the rebar config to use - case proplists:get_value(config, Options) of - undefined -> ok; - Conf -> rebar_config:set_global(config, Conf) - end, - - %% Filter all the flags (i.e. strings of form key=value) from the - %% command line arguments. What's left will be the commands to run. - filter_flags(NonOptArgs, []); - - {error, {Reason, Data}} -> - ?ERROR("Error: ~s ~p~n~n", [Reason, Data]), - help(), - halt(1) - end. - -%% -%% set global flag based on getopt option boolean value -%% -set_global_flag(Options, Flag) -> - Value = case proplists:get_bool(Flag, Options) of - true -> - "1"; - false -> - "0" - end, - rebar_config:set_global(Flag, Value). - -%% -%% show info and maybe halt execution -%% -show_info_maybe_halt(Opts, NonOptArgs) -> - false = show_info_maybe_halt(help, Opts, fun help/0), - false = show_info_maybe_halt(commands, Opts, fun commands/0), - false = show_info_maybe_halt(version, Opts, fun version/0), - case NonOptArgs of - [] -> - ?CONSOLE("No command to run specified!~n",[]), - help(), - halt(1); - _ -> - ok - end. - -show_info_maybe_halt(O, Opts, F) -> - case proplists:get_bool(O, Opts) of - true -> - F(), - halt(0); - false -> - false - end. - -%% -%% print help/usage string -%% -help() -> - OptSpecList = option_spec_list(), - getopt:usage(OptSpecList, "rebar", - "[var=value,...] ", - [{"var=value", "rebar global variables (e.g. force=1)"}, - {"command", "Command to run (e.g. compile)"}]). - -%% -%% print known commands -%% -commands() -> - S = <<" -dialyze Analyze with Dialyzer -build-plt Build Dialyzer PLT -check-plt Check Dialyzer PLT - -clean Clean -compile Compile sources - -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 - -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 - -generate [dump_spec=0/1] Build release with reltool - -eunit [suite=foo] Run eunit [test/foo_tests.erl] tests -ct [suite=] [case=] Run common_test suites in ./test - -xref Run cross reference analysis - -help Show the program options -version Show version information -">>, - io:put_chars(S), - %% workaround to delay exit until all output is written - timer:sleep(300). - -%% -%% show version information and halt -%% -version() -> - {ok, Vsn} = application:get_key(rebar, vsn), - ?CONSOLE("rebar version: ~s date: ~s vcs: ~s\n", [Vsn, ?BUILD_TIME, ?VCS_INFO]). - -%% -%% options accepted via getopt -%% -option_spec_list() -> - Jobs = rebar_config:get_jobs(), - JobsHelp = io_lib:format( - "Number of concurrent workers a command may use. Default: ~B", - [Jobs]), - [ - %% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg} - {help, $h, "help", undefined, "Show the program options"}, - {commands, $c, "commands", undefined, "Show available commands"}, - {verbose, $v, "verbose", undefined, "Be verbose about what gets done"}, - {version, $V, "version", undefined, "Show version information"}, - {force, $f, "force", undefined, "Force"}, - {jobs, $j, "jobs", integer, JobsHelp}, - {config, $C, "config", string, "Rebar config file to use"} - ]. - -%% -%% Seperate all commands (single-words) from flags (key=value) and store -%% values into the rebar_config global storage. -%% -filter_flags([], Commands) -> - lists:reverse(Commands); -filter_flags([Item | Rest], Commands) -> - case string:tokens(Item, "=") of - [Command] -> - filter_flags(Rest, [Command | Commands]); - [KeyStr, Value] -> - Key = list_to_atom(KeyStr), - rebar_config:set_global(Key, Value), - filter_flags(Rest, Commands); - Other -> - ?CONSOLE("Ignoring command line argument: ~p\n", [Other]), - filter_flags(Rest, Commands) - end. - process_commands([]) -> case erlang:get(operations) of 0 -> -- cgit v1.1 From 6978504d43de4d12d791db974e4748e2cb4c2092 Mon Sep 17 00:00:00 2001 From: Klas Johansson Date: Mon, 24 Jan 2011 16:55:18 +0100 Subject: Add support for abbreviated command names This change makes it possible to type the beginning (the prefix) of a command name and rebar will guess the full name of the command, thereby saving the user precious keystrokes. As long as the prefix matches only one command, rebar runs that command, otherwise rebar prints a list of candidate command names. The "-" character is considered to be a word separator and the prefix matching is done per word. Example prefix matches: co ==> compile cl ==> clean create ==> create create-a ==> create-app c-a ==> create-app c-app ==> create-app --- src/rebar_core.erl | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 86607e2..cb08cdf 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -46,22 +46,21 @@ %% Public API %% =================================================================== -run(["help"]) -> - rebar:help(), - ok; -run(["version"]) -> - %% Load application spec and display vsn and build time info - ok = application:load(rebar), - rebar:version(), - ok; run(RawArgs) -> %% Pre-load the rebar app so that we get default configuration ok = application:load(rebar), - %% Parse out command line arguments -- what's left is a list of commands to - %% run - Commands = rebar:parse_args(RawArgs), + %% run -- and start running commands + run_aux(rebar:parse_args(RawArgs)). +run_aux(["help"]) -> + rebar:help(), + ok; +run_aux(["version"]) -> + %% Display vsn and build time info + rebar:version(), + ok; +run_aux(Commands) -> %% Make sure crypto is running ok = crypto:start(), -- cgit v1.1 From 3fd3bfc89a614728c21360ecb91d8a5029f7d0b3 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Thu, 27 Jan 2011 15:52:48 +0100 Subject: Fix circular dependency --- src/rebar_core.erl | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index cb08cdf..1c3940f 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -26,7 +26,7 @@ %% ------------------------------------------------------------------- -module(rebar_core). --export([run/1, +-export([process_commands/1, skip_dir/1, is_skip_dir/1, skip_dirs/0]). @@ -46,44 +46,6 @@ %% Public API %% =================================================================== -run(RawArgs) -> - %% Pre-load the rebar app so that we get default configuration - ok = application:load(rebar), - %% Parse out command line arguments -- what's left is a list of commands to - %% run -- and start running commands - run_aux(rebar:parse_args(RawArgs)). - -run_aux(["help"]) -> - rebar:help(), - ok; -run_aux(["version"]) -> - %% Display vsn and build time info - rebar:version(), - ok; -run_aux(Commands) -> - %% Make sure crypto is running - ok = crypto:start(), - - %% Initialize logging system - rebar_log:init(), - - %% Convert command strings to atoms - CommandAtoms = [list_to_atom(C) || C <- Commands], - - %% Determine the location of the rebar executable; important for pulling - %% resources out of the escript - rebar_config:set_global(escript, filename:absname(escript:script_name())), - ?DEBUG("Rebar location: ~p\n", [rebar_config:get_global(escript, undefined)]), - - %% Note the top-level directory for reference - rebar_config:set_global(base_dir, filename:absname(rebar_utils:get_cwd())), - - %% Keep track of how many operations we do, so we can detect bad commands - erlang:put(operations, 0), - - %% Process each command, resetting any state between each one - process_commands(CommandAtoms). - skip_dir(Dir) -> SkipDir = {skip_dir, Dir}, case erlang:get(SkipDir) of -- cgit v1.1 From 7ac3a5aa9b03e8e1a1c5b3d8fcdfeedd6819c074 Mon Sep 17 00:00:00 2001 From: Tim Watson Date: Wed, 26 Jan 2011 02:15:27 +0000 Subject: Move BUILD_TIME and VCS_INFO macros I have moved these macros from rebar_core.erl to rebar.erl in order to prevent eunit tests from failing (which they currently are). --- src/rebar_core.erl | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 1c3940f..954e6b8 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -34,14 +34,6 @@ -include("rebar.hrl"). --ifndef(BUILD_TIME). --define(BUILD_TIME, "undefined"). --endif. - --ifndef(VCS_INFO). --define(VCS_INFO, "undefined"). --endif. - %% =================================================================== %% Public API %% =================================================================== -- cgit v1.1 From c466076ffb5a1ea4c00d49fefff0dcfbceb58236 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Mon, 31 Jan 2011 17:43:31 +0100 Subject: Clean up emacs file local variables --- src/rebar_core.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 954e6b8..5a6bebd 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -1,4 +1,4 @@ -%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- %% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% -- cgit v1.1 From 63de05d914f3c2bef6dcfc6cf966400d93c9c80d Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 28 Jan 2011 16:08:27 +0100 Subject: Clean up code --- src/rebar_core.erl | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'src/rebar_core.erl') diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 5a6bebd..db3e0b4 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -50,10 +50,10 @@ skip_dir(Dir) -> is_skip_dir(Dir) -> case erlang:get({skip_dir, Dir}) of - undefined -> - false; - true -> - true + undefined -> + false; + true -> + true end. skip_dirs() -> @@ -76,7 +76,8 @@ process_commands([Command | Rest]) -> lists:foreach(fun (D) -> erlang:erase({skip_dir, D}) end, skip_dirs()), Operations = erlang:get(operations), - _ = process_dir(rebar_utils:get_cwd(), rebar_config:new(), Command, sets:new()), + _ = process_dir(rebar_utils:get_cwd(), rebar_config:new(), + Command, sets:new()), case erlang:get(operations) of Operations -> %% This command didn't do anything @@ -108,7 +109,8 @@ process_dir(Dir, ParentConfig, Command, DirSet) -> %% CWD to see if it's a fit -- if it is, use that set of modules %% to process this dir. {ok, AvailModuleSets} = application:get_env(rebar, modules), - {DirModules, ModuleSetFile} = choose_module_set(AvailModuleSets, Dir), + {DirModules, ModuleSetFile} = choose_module_set(AvailModuleSets, + Dir), %% Get the list of modules for "any dir". This is a catch-all list %% of modules that are processed in addition to modules associated @@ -122,7 +124,8 @@ process_dir(Dir, ParentConfig, Command, DirSet) -> %% directories that should be processed _before_ the current one. Predirs = acc_modules(Modules, preprocess, Config, ModuleSetFile), ?DEBUG("Predirs: ~p\n", [Predirs]), - DirSet2 = process_each(Predirs, Command, Config, ModuleSetFile, DirSet), + DirSet2 = process_each(Predirs, Command, Config, + ModuleSetFile, DirSet), %% Make sure the CWD is reset properly; processing the dirs may have %% caused it to change @@ -131,27 +134,30 @@ process_dir(Dir, ParentConfig, Command, DirSet) -> %% Check that this directory is not on the skip list case is_skip_dir(Dir) of true -> - %% Do not execute the command on the directory, as some module - %% as requested a skip on it. + %% Do not execute the command on the directory, as some + %% module as requested a skip on it. ?INFO("Skipping ~s in ~s\n", [Command, Dir]); false -> - %% Get the list of plug-in modules from rebar.config. These modules are - %% processed LAST and do not participate in preprocess. + %% Get the list of plug-in modules from rebar.config. These + %% modules are processed LAST and do not participate + %% in preprocess. {ok, PluginModules} = plugin_modules(Config), %% Execute the current command on this directory - execute(Command, Modules ++ PluginModules, Config, ModuleSetFile) + execute(Command, Modules ++ PluginModules, + Config, ModuleSetFile) end, %% Mark the current directory as processed DirSet3 = sets:add_element(Dir, DirSet2), - %% Invoke 'postprocess' on the modules -- this yields a list of other + %% Invoke 'postprocess' on the modules. This yields a list of other %% directories that should be processed _after_ the current one. Postdirs = acc_modules(Modules, postprocess, Config, ModuleSetFile), ?DEBUG("Postdirs: ~p\n", [Postdirs]), - DirSet4 = process_each(Postdirs, Command, Config, ModuleSetFile, DirSet3), + DirSet4 = process_each(Postdirs, Command, Config, + ModuleSetFile, DirSet3), %% Make sure the CWD is reset properly; processing the dirs may have %% caused it to change @@ -220,11 +226,13 @@ execute(Command, Modules, Config, ModuleFile) -> Dir = rebar_utils:get_cwd(), ?CONSOLE("==> ~s (~s)\n", [filename:basename(Dir), Command]), - %% Increment the count of operations, since some module responds to this command + %% Increment the count of operations, since some module + %% responds to this command erlang:put(operations, erlang:get(operations) + 1), %% Run the available modules - case catch(run_modules(TargetModules, Command, Config, ModuleFile)) of + case catch(run_modules(TargetModules, Command, + Config, ModuleFile)) of ok -> ok; {error, failed} -> -- cgit v1.1