diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/rebar.app.src | 1 | ||||
| -rw-r--r-- | src/rebar3.erl | 8 | ||||
| -rw-r--r-- | src/rebar_hooks.erl | 7 | ||||
| -rw-r--r-- | src/rebar_packages.erl | 39 | ||||
| -rw-r--r-- | src/rebar_prv_common_test.erl | 9 | ||||
| -rw-r--r-- | src/rebar_prv_eunit.erl | 14 | ||||
| -rw-r--r-- | src/rebar_prv_state.erl | 44 | ||||
| -rw-r--r-- | src/rebar_relx.erl | 4 | ||||
| -rw-r--r-- | src/rebar_state.erl | 17 | 
9 files changed, 119 insertions, 24 deletions
| diff --git a/src/rebar.app.src b/src/rebar.app.src index 58fee02..bd0f871 100644 --- a/src/rebar.app.src +++ b/src/rebar.app.src @@ -66,6 +66,7 @@                       rebar_prv_relup,                       rebar_prv_report,                       rebar_prv_shell, +                     rebar_prv_state,                       rebar_prv_tar,                       rebar_prv_unlock,                       rebar_prv_update, diff --git a/src/rebar3.erl b/src/rebar3.erl index 10eccfd..c1a1ae4 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -252,10 +252,10 @@ set_global_flag(State, Options, Flag) ->  %%  global_option_spec_list() ->      [ -    %% {Name, ShortOpt, LongOpt, ArgSpec, HelpMsg} -    {help,     $h, "help",     undefined, "Print this help."}, -    {version,  $v, "version",  undefined, "Show version information."}, -    {task,     undefined, undefined, string, "Task to run."} +    %% {Name,  ShortOpt,  LongOpt,    ArgSpec,   HelpMsg} +    {help,     $h,        "help",     undefined, "Print this help."}, +    {version,  $v,        "version",  undefined, "Show version information."}, +    {task,     undefined, undefined,  string,    "Task to run."}      ].  handle_error(rebar_abort) -> diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl index 4e6d486..3af17ca 100644 --- a/src/rebar_hooks.erl +++ b/src/rebar_hooks.erl @@ -2,6 +2,7 @@  -export([run_all_hooks/5          ,run_all_hooks/6 +        ,run_project_and_app_hooks/5          ,format_error/1]).  -include("rebar.hrl"). @@ -20,6 +21,11 @@ run_all_hooks(Dir, Type, Command, Providers, State) ->      run_provider_hooks(Dir, Type, Command, Providers, rebar_state:opts(State), State),      run_hooks(Dir, Type, Command, rebar_state:opts(State), State). +run_project_and_app_hooks(Dir, Type, Command, Providers, State) -> +    ProjectApps = rebar_state:project_apps(State), +    [rebar_hooks:run_all_hooks(Dir, Type, Command, Providers, AppInfo, State) || AppInfo <- ProjectApps], +    run_all_hooks(Dir, Type, Command, Providers, State). +  run_provider_hooks(Dir, Type, Command, Providers, Opts, State) ->      case rebar_opts:get(Opts, provider_hooks, []) of          [] -> @@ -81,6 +87,7 @@ run_hooks(Dir, post, Command, Opts, State) ->  run_hooks(Dir, Type, Command, Opts, State) ->      case rebar_opts:get(Opts, Type, []) of          [] -> +            ?DEBUG("run_hooks(~p, ~p, ~p) -> no hooks defined\n", [Dir, Type, Command]),              ok;          Hooks ->              Env = create_env(State, Opts), diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl index b5e0923..d4b8a14 100644 --- a/src/rebar_packages.erl +++ b/src/rebar_packages.erl @@ -67,22 +67,28 @@ deps(Name, Vsn, State) ->          deps_(Name, Vsn, State)      catch          _:_ -> -            handle_missing_package(Name, Vsn, State) +            handle_missing_package({Name, Vsn}, State, fun(State1) -> deps_(Name, Vsn, State1) end)      end.  deps_(Name, Vsn, State) ->      ?MODULE:verify_table(State),      ets:lookup_element(?PACKAGE_TABLE, {ec_cnv:to_binary(Name), ec_cnv:to_binary(Vsn)}, 2). -handle_missing_package(Name, Vsn, State) -> -    ?INFO("Package ~s-~s not found. Fetching registry updates and trying again...", [Name, Vsn]), +handle_missing_package(Dep, State, Fun) -> +    case Dep of +        {Name, Vsn} -> +            ?INFO("Package ~s-~s not found. Fetching registry updates and trying again...", [Name, Vsn]); +        _ -> +            ?INFO("Package ~p not found. Fetching registry updates and trying again...", [Dep]) +    end, +      {ok, State1} = rebar_prv_update:do(State),      try -        deps_(Name, Vsn, State1) +        Fun(State1)      catch          _:_ ->              %% Even after an update the package is still missing, time to error out -            throw(?PRV_ERROR({missing_package, ec_cnv:to_binary(Name), ec_cnv:to_binary(Vsn)})) +            throw(?PRV_ERROR({missing_package, Dep}))      end.  registry_dir(State) -> @@ -144,6 +150,23 @@ find_highest_matching(Dep, Constraint, Table, State) ->      find_highest_matching(undefined, undefined, Dep, Constraint, Table, State).  find_highest_matching(Pkg, PkgVsn, Dep, Constraint, Table, State) -> +    try find_highest_matching_(Pkg, PkgVsn, Dep, Constraint, Table, State) of +        none -> +            handle_missing_package(Dep, State, +                                   fun(State1) -> +                                       find_highest_matching_(Pkg, PkgVsn, Dep, Constraint, Table, State1) +                                   end); +        Result -> +            Result +    catch +        _:_ -> +            handle_missing_package(Dep, State, +                                   fun(State1) -> +                                       find_highest_matching_(Pkg, PkgVsn, Dep, Constraint, Table, State1) +                                   end) +    end. + +find_highest_matching_(Pkg, PkgVsn, Dep, Constraint, Table, State) ->      try find_all(Dep, Table, State) of          {ok, [Vsn]} ->              handle_single_vsn(Pkg, PkgVsn, Dep, Vsn, Constraint); @@ -193,8 +216,10 @@ handle_single_vsn(Pkg, PkgVsn, Dep, Vsn, Constraint) ->              {ok, Vsn}      end. -format_error({missing_package, Package, Version}) -> -    io_lib:format("Package not found in registry: ~s-~s.", [Package, Version]). +format_error({missing_package, {Name, Vsn}}) -> +    io_lib:format("Package not found in registry: ~s-~s.", [ec_cnv:to_binary(Name), ec_cnv:to_binary(Vsn)]); +format_error({missing_package, Dep}) -> +    io_lib:format("Package not found in registry: ~p.", [Dep]).  verify_table(State) ->      ets:info(?PACKAGE_TABLE, named_table) =:= true orelse load_and_verify_version(State). diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 12dbec9..ae0690a 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -52,14 +52,16 @@ do(State, Tests) ->      %% Run ct provider prehooks      Providers = rebar_state:providers(State),      Cwd = rebar_dir:get_cwd(), -    rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State), + +    %% Run ct provider pre hooks for all project apps and top level project hooks +    rebar_hooks:run_project_and_app_hooks(Cwd, pre, ?PROVIDER, Providers, State),      case Tests of          {ok, T} ->              case run_tests(State, T) of                  ok    -> -                    %% Run ct provider posthooks -                    rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State), +                    %% Run ct provider post hooks for all project apps and top level project hooks +                    rebar_hooks:run_project_and_app_hooks(Cwd, post, ?PROVIDER, Providers, State),                      rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)),                      {ok, State};                  Error -> @@ -655,4 +657,3 @@ help(verbose) ->      "Verbose output";  help(_) ->      "". - diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index a1a4408..c085ee4 100644 --- a/src/rebar_prv_eunit.erl +++ b/src/rebar_prv_eunit.erl @@ -56,14 +56,14 @@ do(State, Tests) ->      %% Run eunit provider prehooks      Providers = rebar_state:providers(State),      Cwd = rebar_dir:get_cwd(), -    rebar_hooks:run_all_hooks(Cwd, pre, ?PROVIDER, Providers, State), +    rebar_hooks:run_project_and_app_hooks(Cwd, pre, ?PROVIDER, Providers, State),      case validate_tests(State, Tests) of          {ok, T} ->              case run_tests(State, T) of                  {ok, State1} ->                      %% Run eunit provider posthooks -                    rebar_hooks:run_all_hooks(Cwd, post, ?PROVIDER, Providers, State1), +                    rebar_hooks:run_project_and_app_hooks(Cwd, post, ?PROVIDER, Providers, State1),                      rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default)),                      {ok, State1};                  Error -> @@ -190,7 +190,7 @@ dedupe_tests({AppMods, TestMods}) ->      %% in AppMods that will trigger it      F = fun(Mod) ->          M = filename:basename(Mod, ".erl"), -        MatchesTest = fun(Dir) -> filename:basename(Dir, ".erl") ++ "_tests" == M end,  +        MatchesTest = fun(Dir) -> filename:basename(Dir, ".erl") ++ "_tests" == M end,          case lists:any(MatchesTest, AppMods) of              false -> {true, {module, list_to_atom(M)}};              true  -> false @@ -457,10 +457,10 @@ eunit_opts(_State) ->      [{app, undefined, "app", string, help(app)},       {application, undefined, "application", string, help(app)},       {cover, $c, "cover", boolean, help(cover)}, -     {dir, undefined, "dir", string, help(dir)}, -     {file, undefined, "file", string, help(file)}, -     {module, undefined, "module", string, help(module)}, -     {suite, undefined, "suite", string, help(module)}, +     {dir, $d, "dir", string, help(dir)}, +     {file, $f, "file", string, help(file)}, +     {module, $m, "module", string, help(module)}, +     {suite, $s, "suite", string, help(module)},       {verbose, $v, "verbose", boolean, help(verbose)}].  help(app)     -> "Comma separated list of application test suites to run. Equivalent to `[{application, App}]`."; diff --git a/src/rebar_prv_state.erl b/src/rebar_prv_state.erl new file mode 100644 index 0000000..4fbcb67 --- /dev/null +++ b/src/rebar_prv_state.erl @@ -0,0 +1,44 @@ +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et + +-module(rebar_prv_state). + +-behaviour(provider). + +-export([init/1, +         do/1, +         format_error/1]). + +-include("rebar.hrl"). + +-define(PROVIDER, state). +-define(DEPS, []). + +%% =================================================================== +%% Public API +%% =================================================================== + +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> +    Provider = providers:create( +        [{name, ?PROVIDER}, +         {module, ?MODULE}, +         {bare, false}, +         {deps, ?DEPS}, +         {example, "rebar3 state"}, +         {short_desc, "Print current configuration state"}, +         {desc, "Display rebar configuration for debugging purpose"}, +         {opts, []}]), +    State1 = rebar_state:add_provider(State, Provider), +    {ok, State1}. + +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. +do(State) -> +    L = rebar_state:to_list(State), +    ?CONSOLE("State:", []), +    [?CONSOLE("  ~w: ~p", [K, V]) || {K,V} <- L], +    {ok, State}. + +-spec format_error(any()) -> iolist(). +format_error(Reason) -> +    io_lib:format("~p", [Reason]). diff --git a/src/rebar_relx.erl b/src/rebar_relx.erl index 45e1c96..125da47 100644 --- a/src/rebar_relx.erl +++ b/src/rebar_relx.erl @@ -25,7 +25,7 @@ do(Module, Command, Provider, State) ->      AllOptions = string:join([Command | Options], " "),      Cwd = rebar_state:dir(State),      Providers = rebar_state:providers(State), -    rebar_hooks:run_all_hooks(Cwd, pre, Provider, Providers, State), +    rebar_hooks:run_project_and_app_hooks(Cwd, pre, Provider, Providers, State),      try          case rebar_state:get(State, relx, []) of              [] -> @@ -37,7 +37,7 @@ do(Module, Command, Provider, State) ->                            ,{config, Config1}                            ,{caller, api} | output_dir(OutputDir, Options)], AllOptions)          end, -        rebar_hooks:run_all_hooks(Cwd, post, Provider, Providers, State), +        rebar_hooks:run_project_and_app_hooks(Cwd, post, Provider, Providers, State),          {ok, State}      catch          throw:T -> diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 30eff2f..a613a00 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -36,6 +36,8 @@           deps_names/1, +         to_list/1, +           resources/1, resources/2, add_resource/2,           providers/1, providers/2, add_provider/2,           allow_provider_overrides/1, allow_provider_overrides/2 @@ -418,6 +420,21 @@ create_logic_providers(ProviderModules, State0) ->              throw({error, "Failed creating providers. Run with DEBUG=1 for stacktrace."})      end. +to_list(#state_t{} = State) -> +    Fields = record_info(fields, state_t), +    Values = tl(tuple_to_list(State)), +    DictSz = tuple_size(dict:new()), +    lists:zip(Fields, [reformat(I, DictSz) || I <- Values]). + +reformat({K,V}, DSz) when is_list(V) -> +    {K, [reformat(I, DSz) || I <- V]}; +reformat(V, DSz) when is_tuple(V), element(1,V) =:= dict, tuple_size(V) =:= DSz -> +    [reformat(I, DSz) || I <- dict:to_list(V)]; +reformat({K,V}, DSz) when is_tuple(V), element(1,V) =:= dict, tuple_size(V) =:= DSz -> +    {K, [reformat(I, DSz) || I <- dict:to_list(V)]}; +reformat(Other, _DSz) -> +    Other. +  %% ===================================================================  %% Internal functions  %% =================================================================== | 
