Bladeren bron

ft: 参数选项优化

master
SisMaker 1 week geleden
bovenliggende
commit
91d610b868
2 gewijzigde bestanden met toevoegingen van 30 en 21 verwijderingen
  1. +2
    -1
      README.md
  2. +28
    -20
      src/eMake.erl

+ 2
- 1
README.md Bestand weergeven

@ -23,7 +23,8 @@ eg
-nfo -nfo
-sfo Num -sfo Num
-nfa -nfa
-nall
-nall
-nprint
-nnohrl -nnohrl
-semakefile Makefile -semakefile Makefile
-iworkcnt Num 编译进程最大数量 -iworkcnt Num 编译进程最大数量

+ 28
- 20
src/eMake.erl Bestand weergeven

@ -6,7 +6,7 @@
]). ]).
-export([ -export([
compileWorker/7
compileWorker/8
, readEMake/0 , readEMake/0
, saveEMake/1 , saveEMake/1
]). ]).
@ -30,13 +30,14 @@ main(Args) ->
ok; ok;
_ -> _ ->
IsAll = maps:is_key("all", MapArgs), IsAll = maps:is_key("all", MapArgs),
IsPrint = maps:is_key("print", MapArgs),
IsNoHrl = maps:is_key("nohrl", MapArgs), IsNoHrl = maps:is_key("nohrl", MapArgs),
EMakeFile = maps:get("emakefile", MapArgs, ?EMakefile), EMakeFile = maps:get("emakefile", MapArgs, ?EMakefile),
WorkCnt = maps:get("workcnt", MapArgs, erlang:system_info(schedulers) - 1), WorkCnt = maps:get("workcnt", MapArgs, erlang:system_info(schedulers) - 1),
OnceCnt = maps:get("oncecnt", MapArgs, ?OnceCnt), OnceCnt = maps:get("oncecnt", MapArgs, ?OnceCnt),
OptsStr = maps:get("opts", MapArgs, "[]"), OptsStr = maps:get("opts", MapArgs, "[]"),
{ok, Opts} = strToTerm(OptsStr), {ok, Opts} = strToTerm(OptsStr),
make(max(1, WorkCnt), max(1, OnceCnt), EMakeFile, Opts, IsAll, IsNoHrl)
make(max(1, WorkCnt), max(1, OnceCnt), EMakeFile, Opts, IsAll, IsNoHrl, IsPrint)
end. end.
%% map %% map
@ -95,7 +96,7 @@ saveEMake(NowTime) ->
ok ok
end. end.
make(WorkerCnt, OnceCnt, EMakeFile, Opts, IsAll, IsNoHrl) ->
make(WorkerCnt, OnceCnt, EMakeFile, Opts, IsAll, IsNoHrl, IsPrint) ->
io:format("compile start use EMakefile: ~ts ~n", [EMakeFile]), io:format("compile start use EMakefile: ~ts ~n", [EMakeFile]),
StartTime = erlang:system_time(second), StartTime = erlang:system_time(second),
{MakeOpts, CompileOpts} = splitOpts(Opts, [], []), {MakeOpts, CompileOpts} = splitOpts(Opts, [], []),
@ -103,7 +104,7 @@ make(WorkerCnt, OnceCnt, EMakeFile, Opts, IsAll, IsNoHrl) ->
LIsAll = IsAll orelse (LastTime /= 0 andalso StartTime =< LastTime), LIsAll = IsAll orelse (LastTime /= 0 andalso StartTime =< LastTime),
case readEMakefile(EMakeFile, CompileOpts, LIsAll) of case readEMakefile(EMakeFile, CompileOpts, LIsAll) of
{ok, Files} -> {ok, Files} ->
Ret = forMake(Files, WorkerCnt, OnceCnt, lists:member(noexec, MakeOpts), load_opt(MakeOpts), LIsAll, IsNoHrl, []),
Ret = forMake(Files, WorkerCnt, OnceCnt, lists:member(noexec, MakeOpts), load_opt(MakeOpts), LIsAll, IsNoHrl, IsPrint, []),
EndTime = erlang:system_time(second), EndTime = erlang:system_time(second),
saveEMake(EndTime), saveEMake(EndTime),
case Ret of case Ret of
@ -231,7 +232,7 @@ foldErl([OneFile | Left], Acc) ->
foldErl(Left, Acc) foldErl(Left, Acc)
end. end.
forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) ->
forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, IsPrint, AllWorkPids) ->
case AllWorkPids of case AllWorkPids of
[] -> [] ->
ok; ok;
@ -243,7 +244,7 @@ forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) -
[] -> [] ->
ok; ok;
_ -> _ ->
forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, NewAllWorkPids)
forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, IsPrint, NewAllWorkPids)
end; end;
{mCompileError, Err} -> {mCompileError, Err} ->
errorStop(Err, AllWorkPids); errorStop(Err, AllWorkPids);
@ -252,20 +253,20 @@ forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) -
{error, _Other} {error, _Other}
end end
end; end;
forMake([{Mods, Opts} | Rest], WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, AllWorkPids) ->
forMake([{Mods, Opts} | Rest], WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, IsPrint, AllWorkPids) ->
case Mods of case Mods of
[] -> [] ->
forMake(Rest, WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, AllWorkPids);
forMake(Rest, WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, IsPrint, AllWorkPids);
_ -> _ ->
case WorkerCnt > 0 of case WorkerCnt > 0 of
true -> true ->
{Files, More} = splitMods(Mods, OnceCnt), {Files, More} = splitMods(Mods, OnceCnt),
WPid = spawn_link(?MODULE, compileWorker, [Files, Opts, self(), NoExec, Load, IsAll, IsNoHrl]),
WPid = spawn_link(?MODULE, compileWorker, [Files, Opts, self(), NoExec, Load, IsAll, IsNoHrl, IsPrint]),
case More of case More of
over -> over ->
forMake(Rest, WorkerCnt - 1, OnceCnt, NoExec, Load, IsAll, IsNoHrl, [WPid | AllWorkPids]);
forMake(Rest, WorkerCnt - 1, OnceCnt, NoExec, Load, IsAll, IsNoHrl, IsPrint, [WPid | AllWorkPids]);
_ -> _ ->
forMake([{More, Opts} | Rest], WorkerCnt - 1, OnceCnt, NoExec, Load, IsAll, IsNoHrl, [WPid | AllWorkPids])
forMake([{More, Opts} | Rest], WorkerCnt - 1, OnceCnt, NoExec, Load, IsAll, IsNoHrl, IsPrint, [WPid | AllWorkPids])
end; end;
_ -> _ ->
receive receive
@ -274,9 +275,9 @@ forMake([{Mods, Opts} | Rest], WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl,
erlang:send(WPid, {mNewFile, Files, Opts}), erlang:send(WPid, {mNewFile, Files, Opts}),
case More of case More of
over -> over ->
forMake(Rest, WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, AllWorkPids);
forMake(Rest, WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, IsPrint, AllWorkPids);
_ -> _ ->
forMake([{More, Opts} | Rest], WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, AllWorkPids)
forMake([{More, Opts} | Rest], WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, IsPrint, AllWorkPids)
end; end;
{mCompileError, Err} -> {mCompileError, Err} ->
errorStop(Err, AllWorkPids); errorStop(Err, AllWorkPids);
@ -319,7 +320,8 @@ errorStop(Err, AllWorkPids) ->
end, end,
{error, compile_error}. {error, compile_error}.
compileWorker(Files, Opts, Parent, NoExec, Load, IsAll, IsNoHrl) ->
compileWorker(Files, Opts, Parent, NoExec, Load, IsAll, IsNoHrl, IsPrint) ->
put(isPrint, IsPrint),
compileWork(Files, Opts, Parent, NoExec, Load, IsAll, IsNoHrl). compileWork(Files, Opts, Parent, NoExec, Load, IsAll, IsNoHrl).
compileWork([], _Opts, Parent, NoExec, Load, IsAll, IsNoHrl) -> compileWork([], _Opts, Parent, NoExec, Load, IsAll, IsNoHrl) ->
@ -398,14 +400,20 @@ include_opt([]) ->
doCompile(File, true, _Load, _Opts) -> doCompile(File, true, _Load, _Opts) ->
io:format("Out of date: ~ts\n", [File]); io:format("Out of date: ~ts\n", [File]);
doCompile(File, false, noload, Opts) -> doCompile(File, false, noload, Opts) ->
% io:format("Recompile: ~ts\n", [File]),
compile:file(File, [report_errors, report_warnings, error_summary | Opts]);
StartTime = erlang:system_time(millisecond),
CRet = compile:file(File, [report_errors, report_warnings, error_summary | Opts]),
get(isPrint) andalso io:format("Recompile: ~ts use time:~pms\n", [File, erlang:system_time(millisecond) - StartTime]),
CRet;
doCompile(File, false, load, Opts) -> doCompile(File, false, load, Opts) ->
% io:format("Recompile: ~ts\n", [File]),
c:c(File, Opts);
StartTime = erlang:system_time(millisecond),
CRet = c:c(File, Opts),
get(isPrint) andalso io:format("Recompile: ~ts use time:~pms\n", [File, erlang:system_time(millisecond) - StartTime]),
CRet;
doCompile(File, false, netload, Opts) -> doCompile(File, false, netload, Opts) ->
% io:format("Recompile: ~ts\n", [File]),
c:nc(File, Opts).
StartTime = erlang:system_time(millisecond),
CRet = c:nc(File, Opts),
get(isPrint) andalso io:format("Recompile: ~ts use time:~pms\n", [File, erlang:system_time(millisecond) - StartTime]),
CRet.
exists(File) -> exists(File) ->
case file:read_file_info(File) of case file:read_file_info(File) of

Laden…
Annuleren
Opslaan