diff options
Diffstat (limited to 'src/rebar3.erl')
-rw-r--r-- | src/rebar3.erl | 66 |
1 files changed, 46 insertions, 20 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl index 1a02407..c501709 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -56,7 +56,7 @@ main(Args) -> %% Erlang-API entry point run(BaseState, Commands) -> - _ = application:load(rebar), + start_and_load_apps(), BaseState1 = rebar_state:set(BaseState, task, Commands), BaseState2 = rebar_state:set(BaseState1, caller, api), run_aux(BaseState2, Commands). @@ -66,7 +66,7 @@ run(BaseState, Commands) -> %% ==================================================================== run(RawArgs) -> - _ = application:load(rebar), + start_and_load_apps(), BaseState = init_config(), BaseState1 = rebar_state:set(BaseState, caller, command_line), @@ -83,16 +83,6 @@ run(RawArgs) -> run_aux(BaseState2, RawArgs). run_aux(State, RawArgs) -> - %% Make sure crypto is running - case crypto:start() of - ok -> ok; - {error,{already_started,crypto}} -> ok - end, - application:start(asn1), - application:start(public_key), - application:start(ssl), - inets:start(), - State2 = case os:getenv("REBAR_PROFILE") of false -> State; @@ -105,13 +95,12 @@ run_aux(State, RawArgs) -> %% Process each command, resetting any state between each one BaseDir = rebar_state:get(State, base_dir, ?DEFAULT_BASE_DIR), State3 = rebar_state:set(State2, base_dir, - filename:join(filename:absname(rebar_state:dir(State2)), BaseDir)), + filename:join(filename:absname(rebar_state:dir(State2)), BaseDir)), {ok, Providers} = application:get_env(rebar, providers), - State4 = rebar_plugins:install(State3), - %% Providers can modify profiles stored in opts, so set default after initializing providers - State5 = rebar_state:create_logic_providers(Providers, State4), + State4 = rebar_state:create_logic_providers(Providers, State3), + State5 = rebar_plugins:project_apps_install(State4), State6 = rebar_state:default(State5, rebar_state:opts(State5)), {Task, Args} = parse_args(RawArgs), @@ -131,8 +120,7 @@ init_config() -> ConfigFile -> rebar_config:consult_file(ConfigFile) end, - - Config1 = rebar_config:merge_locks(Config, rebar_config:consult_file(?LOCK_FILE)), + Config1 = rebar_config:merge_locks(Config, rebar_config:consult_lock_file(?LOCK_FILE)), %% If $HOME/.config/rebar3/config exists load and use as global config GlobalConfigFile = rebar_dir:global_config(), @@ -140,8 +128,19 @@ init_config() -> true -> ?DEBUG("Load global config file ~p", [GlobalConfigFile]), - GlobalConfig = rebar_state:new(rebar_config:consult_file(GlobalConfigFile)), - rebar_state:new(GlobalConfig, Config1); + GlobalConfigTerms = rebar_config:consult_file(GlobalConfigFile), + GlobalConfig = rebar_state:new(GlobalConfigTerms), + + %% We don't want to worry about global plugin install state effecting later + %% usage. So we throw away the global profile state used for plugin install. + GlobalConfigThrowAway = rebar_state:current_profiles(GlobalConfig, [global]), + GlobalState = rebar_plugins:handle_plugins(global, + rebar_state:get(GlobalConfigThrowAway, plugins, []), + GlobalConfigThrowAway), + GlobalPlugins = rebar_state:providers(GlobalState), + GlobalConfig2 = rebar_state:set(GlobalConfig, plugins, []), + GlobalConfig3 = rebar_state:set(GlobalConfig2, {plugins, global}, rebar_state:get(GlobalConfigThrowAway, plugins, [])), + rebar_state:providers(rebar_state:new(GlobalConfig3, Config1), GlobalPlugins); false -> rebar_state:new(Config1) end, @@ -255,5 +254,32 @@ handle_error(Error) -> %% Dump this error to console ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []), ?DEBUG("Uncaught error: ~p", [Error]), + case erlang:get_stacktrace() of + [] -> ok; + Trace -> + ?DEBUG("Stack trace to the error location: ~p", [Trace]) + end, ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []), erlang:halt(1). + +start_and_load_apps() -> + _ = application:load(rebar), + %% Make sure crypto is running + case crypto:start() of + ok -> ok; + {error,{already_started,crypto}} -> ok + end, + application:start(asn1), + application:start(public_key), + application:start(ssl), + inets:start(), + inets:start(httpc, [{profile, hex}]), + http_opts(). + +http_opts() -> + Opts = [{max_sessions, 4}, + {max_keep_alive_length, 4}, + {keep_alive_timeout, 120000}, + {max_pipeline_length, 4}, + {pipeline_timeout, 60000}], + httpc:set_options(Opts, hex). |