diff options
-rw-r--r-- | src/rebar3.erl | 2 | ||||
-rw-r--r-- | src/rebar_base_compiler.erl | 80 | ||||
-rw-r--r-- | src/rebar_git_resource.erl | 2 | ||||
-rw-r--r-- | src/rebar_prv_compile.erl | 32 | ||||
-rw-r--r-- | src/rebar_prv_dialyzer.erl | 4 | ||||
-rw-r--r-- | src/rebar_state.erl | 49 | ||||
-rw-r--r-- | src/rebar_templater.erl | 2 |
7 files changed, 43 insertions, 128 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl index 4f54c89..d80773b 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -45,7 +45,7 @@ main(Args) -> case catch(run(Args)) of {ok, _State} -> - ok; + erlang:halt(0); rebar_abort -> erlang:halt(1); {error, rebar_abort} -> diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl index 293b4d8..265ea80 100644 --- a/src/rebar_base_compiler.erl +++ b/src/rebar_base_compiler.erl @@ -40,20 +40,7 @@ run(Config, FirstFiles, RestFiles, CompileFn) -> %% Compile the first files in sequence - compile_each(FirstFiles, Config, CompileFn), - - %% Spin up workers for the rest of the files - case RestFiles of - [] -> - ok; - _ -> - Self = self(), - F = fun() -> compile_worker(Self, Config, CompileFn) end, - Jobs = rebar_state:get(Config, jobs, 3), - ?DEBUG("Starting ~B compile worker(s)", [Jobs]), - Pids = [spawn_monitor(F) || _I <- lists:seq(1,Jobs)], - compile_queue(Config, Pids, RestFiles) - end. + compile_each(FirstFiles++RestFiles, Config, CompileFn). run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt, Compile3Fn) -> @@ -146,71 +133,6 @@ compile_each([Source | Rest], Config, CompileFn) -> end, compile_each(Rest, Config, CompileFn). -compile_queue(_Config, [], []) -> - ok; -compile_queue(Config, Pids, Targets) -> - receive - {next, Worker} -> - case Targets of - [] -> - Worker ! empty, - compile_queue(Config, Pids, Targets); - [Source | Rest] -> - Worker ! {compile, Source}, - compile_queue(Config, Pids, Rest) - end; - - {fail, {_, {source, Source}}=Error} -> - ?ERROR("Compiling ~s failed:", - [maybe_absname(Config, Source)]), - maybe_report(Error), - ?DEBUG("Worker compilation failed: ~p", [Error]), - ?FAIL; - - {compiled, Source, Warnings} -> - report(Warnings), - ?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), filename:basename(Source)]), - compile_queue(Config, Pids, Targets); - - {compiled, Source} -> - ?DEBUG("~sCompiled ~s", [rebar_utils:indent(1), filename:basename(Source)]), - compile_queue(Config, Pids, Targets); - {skipped, Source} -> - ?DEBUG("~sSkipped ~s", [rebar_utils:indent(1), filename:basename(Source)]), - compile_queue(Config, Pids, Targets); - {'DOWN', Mref, _, Pid, normal} -> - ?DEBUG("Worker exited cleanly", []), - Pids2 = lists:delete({Pid, Mref}, Pids), - compile_queue(Config, Pids2, Targets); - - {'DOWN', _Mref, _, _Pid, Info} -> - ?DEBUG("Worker failed: ~p", [Info]), - ?FAIL - end. - -compile_worker(QueuePid, Config, CompileFn) -> - QueuePid ! {next, self()}, - receive - {compile, Source} -> - case catch(compile(Source, Config, CompileFn)) of - {ok, Ws} -> - QueuePid ! {compiled, Source, Ws}, - compile_worker(QueuePid, Config, CompileFn); - ok -> - QueuePid ! {compiled, Source}, - compile_worker(QueuePid, Config, CompileFn); - skipped -> - QueuePid ! {skipped, Source}, - compile_worker(QueuePid, Config, CompileFn); - Error -> - QueuePid ! {fail, {{error, Error}, {source, Source}}}, - ok - end; - - empty -> - ok - end. - format_errors(Config, Source, Errors) -> format_errors(Config, Source, "", Errors). diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index 7626772..3b77da2 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -120,7 +120,7 @@ make_vsn(Dir) -> collect_default_refcount() -> %% Get the tag timestamp and minimal ref from the system. The %% timestamp is really important from an ordering perspective. - AbortMsg1 = "Gtting log of git dependency failed in " ++ rebar_dir:get_cwd(), + AbortMsg1 = "Getting log of git dependency failed in " ++ rebar_dir:get_cwd(), {ok, String} = rebar_utils:sh("git log -n 1 --pretty=format:'%h\n' ", [{use_stdout, false}, diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 937b9bf..0b70f22 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -13,17 +13,12 @@ -define(PROVIDER, compile). -define(DEPS, [lock]). --define(DEFAULT_JOBS, 3). - %% =================================================================== %% Public API %% =================================================================== -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. init(State) -> - JobsHelp = io_lib:format( - "Number of concurrent workers the compiler may use. Default: ~B", - [?DEFAULT_JOBS]), State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER}, {module, ?MODULE}, {bare, false}, @@ -31,34 +26,28 @@ init(State) -> {example, "rebar3 compile"}, {short_desc, "Compile apps .app.src and .erl files."}, {desc, ""}, - {opts, [ - {jobs, $j, "jobs", integer, JobsHelp} - ]}])), + {opts, []}])), {ok, State1}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - {ok, State1} = handle_args(State), - Jobs = rebar_state:get(State1, jobs), - - ProjectApps = rebar_state:project_apps(State1), - Deps = rebar_state:deps_to_build(State1), + ProjectApps = rebar_state:project_apps(State), + Deps = rebar_state:deps_to_build(State), Cwd = rebar_dir:get_cwd(), - rebar_hooks:run_compile_hooks(Cwd, pre_hooks, compile, State1), + rebar_hooks:run_compile_hooks(Cwd, pre_hooks, compile, State), %% Need to allow global config vars used on deps %% Right now no way to differeniate and just give deps a new state EmptyState = rebar_state:new(), - EmptyState1 = rebar_state:set(EmptyState, jobs, Jobs), - build_apps(EmptyState1, Deps), + build_apps(EmptyState, Deps), %% Use the project State for building project apps %% Set hooks to empty so top-level hooks aren't run for each project app - State2 = rebar_state:set(rebar_state:set(State1, post_hooks, []), pre_hooks, []), + State2 = rebar_state:set(rebar_state:set(State, post_hooks, []), pre_hooks, []), ProjectApps1 = build_apps(State2, ProjectApps), - rebar_hooks:run_compile_hooks(Cwd, post_hooks, compile, State1), + rebar_hooks:run_compile_hooks(Cwd, post_hooks, compile, State), - {ok, rebar_state:project_apps(State1, ProjectApps1)}. + {ok, rebar_state:project_apps(State, ProjectApps1)}. -spec format_error(any()) -> iolist(). format_error(Reason) -> @@ -103,11 +92,6 @@ compile(State, AppInfo) -> %% Internal functions %% =================================================================== -handle_args(State) -> - {Args, _} = rebar_state:command_parsed_args(State), - Jobs = proplists:get_value(jobs, Args, ?DEFAULT_JOBS), - {ok, rebar_state:set(State, jobs, Jobs)}. - copy_app_dirs(State, OldAppDir, AppDir) -> case ec_cnv:to_binary(filename:absname(OldAppDir)) =/= ec_cnv:to_binary(filename:absname(AppDir)) of diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl index fe9a141..24e276d 100644 --- a/src/rebar_prv_dialyzer.erl +++ b/src/rebar_prv_dialyzer.erl @@ -296,8 +296,8 @@ build_proj_plt(State, Plt, Files) -> end. get_base_plt_location(State) -> - GlobalConfigDir = rebar_dir:global_config_dir(State), - BaseDir = rebar_state:get(State, dialyzer_base_plt_dir, GlobalConfigDir), + GlobalCacheDir = rebar_dir:global_cache_dir(State), + BaseDir = rebar_state:get(State, dialyzer_base_plt_dir, GlobalCacheDir), BasePlt = rebar_state:get(State, dialyzer_base_plt, default_plt()), filename:join(BaseDir, BasePlt). diff --git a/src/rebar_state.erl b/src/rebar_state.erl index e77a259..008f202 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -97,9 +97,8 @@ new(ParentState, Config, Dir) -> dict:from_list([{{deps, default}, D} | Config]) end, - NewOpts = dict:merge(fun(_Key, Value1, _Value2) -> - Value1 - end, LocalOpts, Opts), + NewOpts = merge_opts(LocalOpts, Opts), + ParentState#state_t{dir=Dir ,opts=NewOpts ,default=NewOpts}. @@ -213,23 +212,8 @@ apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Prof State#state_t{current_profiles=CurrentProfiles++Profiles1, opts=NewOpts}. merge_opts(Profile, NewOpts, OldOpts) -> - Opts = dict:merge(fun(_Key, NewValue, OldValue) when is_list(NewValue) -> - case io_lib:printable_list(NewValue) of - true when NewValue =:= [] -> - case io_lib:printable_list(OldValue) of - true -> - NewValue; - false -> - OldValue - end; - true -> - NewValue; - false -> - OldValue ++ NewValue - end; - (_Key, NewValue, _OldValue) -> - NewValue - end, NewOpts, OldOpts), + Opts = merge_opts(NewOpts, OldOpts), + case dict:find(deps, NewOpts) of {ok, Value} -> dict:store({deps, Profile}, Value, Opts); @@ -237,6 +221,31 @@ merge_opts(Profile, NewOpts, OldOpts) -> Opts end. +merge_opts(NewOpts, OldOpts) -> + dict:merge(fun(deps, NewValue, _OldValue) -> + NewValue; + ({deps, _}, NewValue, _OldValue) -> + NewValue; + (profiles, NewValue, OldValue) -> + dict:to_list(merge_opts(dict:from_list(NewValue), dict:from_list(OldValue))); + (_Key, NewValue, OldValue) when is_list(NewValue) -> + case io_lib:printable_list(NewValue) of + true when NewValue =:= [] -> + case io_lib:printable_list(OldValue) of + true -> + NewValue; + false -> + OldValue + end; + true -> + NewValue; + false -> + lists:umerge(lists:sort(NewValue), lists:sort(OldValue)) + end; + (_Key, NewValue, _OldValue) -> + NewValue + end, NewOpts, OldOpts). + dir(#state_t{dir=Dir}) -> Dir. diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index 824d376..143c28b 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -328,7 +328,7 @@ prioritize_templates([{Name, Type, File} | Rest], Valid) -> prioritize_templates(Rest, Valid); {_, file, _} -> ?DEBUG("Skipping template ~p, due to presence of a custom " - "template at ~s~n", [File]), + "template at ~s~n", [Name, File]), prioritize_templates(Rest, Valid) end. |