From b0b81ecbfbab169f0d7ddada678ae174f3eea123 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Tue, 14 Feb 2023 22:01:45 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E7=BC=96=E8=AF=91=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E6=A3=80=E8=BD=A6=E5=A4=B4=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- src/eMake.erl | 60 ++++++++++++++++++++++++++------------------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index c3a54f5..713946a 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,9 @@ Build eg ----- - 参数可选 + 参数可选 all nohrl eMake + eMake all nohrl eMake "./Emakefile" eMake 4 eMake "./Emakefile" 4 diff --git a/src/eMake.erl b/src/eMake.erl index 3cbf492..61f581b 100644 --- a/src/eMake.erl +++ b/src/eMake.erl @@ -6,7 +6,7 @@ ]). -export([ - compileWorker/6 + compileWorker/7 , readEMake/0 , saveEMake/1 ]). @@ -29,21 +29,23 @@ main(Args) -> ok; _ -> IsAll = lists:member("all", Args), - case lists:delete("all", Args) of + IsNoHrl = lists:member("nohrl", Args), + + case lists:delete("all", lists:delete("nohrl", Args)) of [] -> - make(max(1, erlang:system_info(schedulers) - 1), ?EMakefile, [], IsAll); + make(max(1, erlang:system_info(schedulers) - 1), ?EMakefile, [], IsAll, IsNoHrl); [EMakeFileOrWorkCnt] -> try list_to_integer(EMakeFileOrWorkCnt) of Cnt -> - make(max(1, Cnt), ?EMakefile, [], IsAll) + make(max(1, Cnt), ?EMakefile, [], IsAll, IsNoHrl) catch _:_ -> - make(max(1, erlang:system_info(schedulers) - 1), EMakeFileOrWorkCnt, [], IsAll) + make(max(1, erlang:system_info(schedulers) - 1), EMakeFileOrWorkCnt, [], IsAll, IsNoHrl) end; [EMakeFile, WorkCntStr] -> - make(max(1, list_to_integer(WorkCntStr)), EMakeFile, [], IsAll); + make(max(1, list_to_integer(WorkCntStr)), EMakeFile, [], IsAll, IsNoHrl); [EMakeFile, WorkCntStr, OptsStr] -> {ok, Opts} = strToTerm(OptsStr), - make(max(1, list_to_integer(WorkCntStr)), EMakeFile, Opts, IsAll) + make(max(1, list_to_integer(WorkCntStr)), EMakeFile, Opts, IsAll, IsNoHrl) end end. @@ -70,7 +72,7 @@ saveEMake(NowTime) -> ok end. -make(WorkerCnt, EMakeFile, Opts, IsAll) -> +make(WorkerCnt, EMakeFile, Opts, IsAll, IsNoHrl) -> io:format("compile start use EMakefile: ~ts~n", [EMakeFile]), StartTime = erlang:system_time(second), {MakeOpts, CompileOpts} = splitOpts(Opts, [], []), @@ -78,7 +80,7 @@ make(WorkerCnt, EMakeFile, Opts, IsAll) -> {ok, Files} -> LastTime = readEMake(), LIsAll = IsAll orelse (LastTime /= 0 andalso StartTime =< LastTime), - Ret = forMake(Files, WorkerCnt, lists:member(noexec, MakeOpts), load_opt(MakeOpts), LIsAll, []), + Ret = forMake(Files, WorkerCnt, lists:member(noexec, MakeOpts), load_opt(MakeOpts), LIsAll, IsNoHrl, []), EndTime = erlang:system_time(second), saveEMake(EndTime), case Ret of @@ -205,7 +207,7 @@ foldErl([OneFile | Left], Acc) -> foldErl(Left, Acc) end. -forMake([], _Worker, _NoExec, _Load, IsAll, AllWorkPids) -> +forMake([], _Worker, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) -> case AllWorkPids of [] -> ok; @@ -217,7 +219,7 @@ forMake([], _Worker, _NoExec, _Load, IsAll, AllWorkPids) -> [] -> ok; _ -> - forMake([], _Worker, _NoExec, _Load, IsAll, NewAllWorkPids) + forMake([], _Worker, _NoExec, _Load, IsAll, IsNoHrl, NewAllWorkPids) end; {mCompileError, Err} -> errorStop(Err, AllWorkPids); @@ -226,20 +228,20 @@ forMake([], _Worker, _NoExec, _Load, IsAll, AllWorkPids) -> {error, _Other} end end; -forMake([{Mods, Opts} | Rest], Worker, NoExec, Load, IsAll, AllWorkPids) -> +forMake([{Mods, Opts} | Rest], Worker, NoExec, Load, IsAll, IsNoHrl, AllWorkPids) -> case Mods of [] -> - forMake(Rest, Worker, NoExec, Load, IsAll, AllWorkPids); + forMake(Rest, Worker, NoExec, Load, IsAll, IsNoHrl, AllWorkPids); _ -> case Worker > 0 of true -> {Files, More} = splitMods(Mods), - WPid = spawn_link(?MODULE, compileWorker, [Files, Opts, self(), NoExec, Load, IsAll]), + WPid = spawn_link(?MODULE, compileWorker, [Files, Opts, self(), NoExec, Load, IsAll, IsNoHrl]), case More of over -> - forMake(Rest, Worker - 1, NoExec, Load, IsAll, [WPid | AllWorkPids]); + forMake(Rest, Worker - 1, NoExec, Load, IsAll, IsNoHrl, [WPid | AllWorkPids]); _ -> - forMake([{More, Opts} | Rest], Worker - 1, NoExec, Load, IsAll, [WPid | AllWorkPids]) + forMake([{More, Opts} | Rest], Worker - 1, NoExec, Load, IsAll, IsNoHrl, [WPid | AllWorkPids]) end; _ -> receive @@ -248,9 +250,9 @@ forMake([{Mods, Opts} | Rest], Worker, NoExec, Load, IsAll, AllWorkPids) -> erlang:send(WPid, {mNewFile, Files, Opts}), case More of over -> - forMake(Rest, Worker, NoExec, Load, IsAll, AllWorkPids); + forMake(Rest, Worker, NoExec, Load, IsAll, IsNoHrl, AllWorkPids); _ -> - forMake([{More, Opts} | Rest], Worker, NoExec, Load, IsAll, AllWorkPids) + forMake([{More, Opts} | Rest], Worker, NoExec, Load, IsAll, IsNoHrl, AllWorkPids) end; {mCompileError, Err} -> errorStop(Err, AllWorkPids); @@ -279,19 +281,19 @@ errorStop(Err, AllWorkPids) -> end, {error, compile_error}. -compileWorker(Files, Opts, Parent, NoExec, Load, IsAll) -> - compileWork(Files, Opts, Parent, NoExec, Load, IsAll). +compileWorker(Files, Opts, Parent, NoExec, Load, IsAll, IsNoHrl) -> + compileWork(Files, Opts, Parent, NoExec, Load, IsAll, IsNoHrl). -compileWork([], _Opts, Parent, NoExec, Load, IsAll) -> +compileWork([], _Opts, Parent, NoExec, Load, IsAll, IsNoHrl) -> erlang:send(Parent, {mOverCompile, self()}), receive {mNewFile, Files, Opts} -> - compileWork(Files, Opts, Parent, NoExec, Load, IsAll); + compileWork(Files, Opts, Parent, NoExec, Load, IsAll, IsNoHrl); _Other -> io:format("compileWorker [] receive unexpect msg:~p ~n", [_Other]) end; -compileWork([OneFile | Files], Opts, Parent, NoExec, Load, IsAll) -> - case tryCompile(coerce_2_list(OneFile), NoExec, Load, IsAll, Opts) of +compileWork([OneFile | Files], Opts, Parent, NoExec, Load, IsAll, IsNoHrl) -> + case tryCompile(coerce_2_list(OneFile), NoExec, Load, IsAll, IsNoHrl, Opts) of error -> Parent ! {mCompileError, OneFile}, exit(error); @@ -299,10 +301,10 @@ compileWork([OneFile | Files], Opts, Parent, NoExec, Load, IsAll) -> Parent ! {mCompileError, {OneFile, Errors, Warnings}}, exit(error); _ -> - compileWork(Files, Opts, Parent, NoExec, Load, IsAll) + compileWork(Files, Opts, Parent, NoExec, Load, IsAll, IsNoHrl) end. -tryCompile(File, NoExec, Load, IsAll, Opts) -> +tryCompile(File, NoExec, Load, IsAll, IsNoHrl, Opts) -> case IsAll of false -> ObjName = lists:append(filename:basename(File), code:objfile_extension()), @@ -315,7 +317,7 @@ tryCompile(File, NoExec, Load, IsAll, Opts) -> end, case exists(ObjFile) of true -> - reCompile(File, NoExec, Load, Opts, ObjFile); + reCompile(File, NoExec, Load, Opts, ObjFile, IsNoHrl); false -> doCompile(File, NoExec, Load, Opts) end; @@ -323,14 +325,14 @@ tryCompile(File, NoExec, Load, IsAll, Opts) -> doCompile(File, NoExec, Load, Opts) end. -reCompile(File, NoExec, Load, Opts, ObjFile) -> +reCompile(File, NoExec, Load, Opts, ObjFile, IsNoHrl) -> {ok, #file_info{mtime = SrcTime}} = file:read_file_info(lists:append(File, ".erl")), {ok, #file_info{mtime = ObjTime}} = file:read_file_info(ObjFile), case SrcTime > ObjTime of true -> doCompile(File, NoExec, Load, Opts); _ -> - ckIncludeRecompile(ObjTime, File, NoExec, Load, Opts) + IsNoHrl /= true andalso ckIncludeRecompile(ObjTime, File, NoExec, Load, Opts) end. %% recompile2(ObjMTime, File, NoExec, Load, Opts)