diff --git a/README.md b/README.md index 92253dd..077e7c5 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,8 @@ eg -nfo -sfo Num -nfa - -nall + -nall + -nprint -nnohrl -semakefile Makefile -iworkcnt Num 编译进程最大数量 diff --git a/src/eMake.erl b/src/eMake.erl index ddf8af0..1f76664 100644 --- a/src/eMake.erl +++ b/src/eMake.erl @@ -6,7 +6,7 @@ ]). -export([ - compileWorker/7 + compileWorker/8 , readEMake/0 , saveEMake/1 ]). @@ -30,13 +30,14 @@ main(Args) -> ok; _ -> IsAll = maps:is_key("all", MapArgs), + IsPrint = maps:is_key("print", MapArgs), IsNoHrl = maps:is_key("nohrl", MapArgs), EMakeFile = maps:get("emakefile", MapArgs, ?EMakefile), WorkCnt = maps:get("workcnt", MapArgs, erlang:system_info(schedulers) - 1), OnceCnt = maps:get("oncecnt", MapArgs, ?OnceCnt), OptsStr = maps:get("opts", MapArgs, "[]"), {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. %% 解析命令行参数成map @@ -95,7 +96,7 @@ saveEMake(NowTime) -> ok 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]), StartTime = erlang:system_time(second), {MakeOpts, CompileOpts} = splitOpts(Opts, [], []), @@ -103,7 +104,7 @@ make(WorkerCnt, OnceCnt, EMakeFile, Opts, IsAll, IsNoHrl) -> LIsAll = IsAll orelse (LastTime /= 0 andalso StartTime =< LastTime), case readEMakefile(EMakeFile, CompileOpts, LIsAll) of {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), saveEMake(EndTime), case Ret of @@ -231,7 +232,7 @@ foldErl([OneFile | Left], Acc) -> foldErl(Left, Acc) end. -forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) -> +forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, IsPrint, AllWorkPids) -> case AllWorkPids of [] -> ok; @@ -243,7 +244,7 @@ forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) - [] -> ok; _ -> - forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, NewAllWorkPids) + forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, IsPrint, NewAllWorkPids) end; {mCompileError, Err} -> errorStop(Err, AllWorkPids); @@ -252,20 +253,20 @@ forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) - {error, _Other} 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 [] -> - forMake(Rest, WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, AllWorkPids); + forMake(Rest, WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, IsPrint, AllWorkPids); _ -> case WorkerCnt > 0 of true -> {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 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; _ -> receive @@ -274,9 +275,9 @@ forMake([{Mods, Opts} | Rest], WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, erlang:send(WPid, {mNewFile, Files, Opts}), case More of 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; {mCompileError, Err} -> errorStop(Err, AllWorkPids); @@ -319,7 +320,8 @@ errorStop(Err, AllWorkPids) -> end, {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([], _Opts, Parent, NoExec, Load, IsAll, IsNoHrl) -> @@ -398,14 +400,20 @@ include_opt([]) -> doCompile(File, true, _Load, _Opts) -> io:format("Out of date: ~ts\n", [File]); 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) -> - % 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) -> - % 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) -> case file:read_file_info(File) of