瀏覽代碼

ft: 选项传递优化

master
SisMaker 1 周之前
父節點
當前提交
cf7eeb5904
共有 2 個檔案被更改,包括 88 行新增49 行删除
  1. +23
    -7
      README.md
  2. +65
    -42
      src/eMake.erl

+ 23
- 7
README.md 查看文件

@ -11,11 +11,27 @@ Build
eg
-----
参数可选 all nohrl
eMake
eMake all nohrl
eMake "./Emakefile"
eMake 4
eMake "./Emakefile" 4
eMake "./Emakefile" 4 "[noexec, debug_info]"
参数的值类型标记F:
-s 字符串 参数的值会保持字符串
-i 整数 参数的值会转成整数
-a 原子 参数的值会转成原子
-f 浮点数 参数的值会转成浮点数
-b 二进制 参数的值会转成binary
-n 没有值 没有参数值 或者 可以配置占位符
参数格式: FKey Value
所有可选参数:
-nfo
-sfo Num
-nfa
-nall
-nnohrl
-semakefile Makefile
-iworkcnt Num 编译进程最大数量
-ioncecnt Nun 单次批量编编译的文件数
-sopts String 编译选项字符串
eg:
eMake -nfo
eMake -ifo 1
eMake -nfa
eMake -nall -nnohrl -semakefile "./Emakefile" -iworkcnt 4 -sopts "[noexec, debug_info]"
可以在编译之后修改代码指定默认的 Emakefile文件

+ 65
- 42
src/eMake.erl 查看文件

@ -12,41 +12,64 @@
]).
-define(MakeOpts, [noexec, load, netload, noload]).
-define(EMakefile, "./Emakefile").
-define(OnceCnt, 16).
-define(EMakefile, "./boot/Emakefile").
-define(OnceCnt, 1).
main(Args) ->
MapArgs = parseArgs(Args),
process_flag(trap_exit, true),
case Args of
["fo"] ->
case MapArgs of
#{"fo" := true} ->
os:cmd("redis-cli FLUSHDB"),
ok;
["fo", DBNumStr | _] ->
#{"fo" := DBNumStr} ->
os:cmd("redis-cli -n " ++ DBNumStr ++ " FLUSHDB"),
ok;
["fa" | _] ->
#{"fa" := true} ->
os:cmd("redis-cli FLUSHALL"),
ok;
_ ->
IsAll = lists:member("all", Args),
IsNoHrl = lists:member("nohrl", Args),
case lists:delete("all", lists:delete("nohrl", Args)) of
[] ->
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, IsNoHrl)
catch _:_ ->
make(max(1, erlang:system_info(schedulers) - 1), EMakeFileOrWorkCnt, [], IsAll, IsNoHrl)
end;
[EMakeFile, WorkCntStr] ->
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, IsNoHrl)
end
IsAll = maps:is_key("all", 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)
end.
%% map
parseArgs(Args) ->
parseArgs(Args, #{}).
parseArgs([], Ret) -> Ret;
parseArgs([Flag | Rest], Ret) ->
case Flag of
[$-, $n | Left] ->
[Value | LRest] = Rest,
case Value of
[$- | _] ->
parseArgs(Rest, Ret#{Left => true});
_ ->
parseArgs(LRest, Ret#{LRest => Value})
end;
[$-, $s | Left] ->
[Value | LRest] = Rest,
parseArgs(LRest, Ret#{Left => Value});
[$-, $i | Left] ->
[Value | LRest] = Rest,
parseArgs(LRest, Ret#{Left => list_to_integer(Value)});
[$-, $a | Left] ->
[Value | LRest] = Rest,
parseArgs(LRest, Ret#{Left => list_to_atom(Value)});
[$-, $f | Left] ->
[Value | LRest] = Rest,
parseArgs(LRest, Ret#{Left => list_to_float(Value)});
[$-, $b | Left] ->
[Value | LRest] = Rest,
parseArgs(LRest, Ret#{Left => list_to_binary(Value)});
_ ->
parseArgs(Rest, Ret)
end.
eMakeFile() ->
@ -72,15 +95,15 @@ saveEMake(NowTime) ->
ok
end.
make(WorkerCnt, EMakeFile, Opts, IsAll, IsNoHrl) ->
io:format("compile start use EMakefile: ~ts~n", [EMakeFile]),
make(WorkerCnt, OnceCnt, EMakeFile, Opts, IsAll, IsNoHrl) ->
io:format("compile start use EMakefile: ~ts ~n", [EMakeFile]),
StartTime = erlang:system_time(second),
{MakeOpts, CompileOpts} = splitOpts(Opts, [], []),
LastTime = readEMake(),
LIsAll = IsAll orelse (LastTime /= 0 andalso StartTime =< LastTime),
case readEMakefile(EMakeFile, CompileOpts, LIsAll) of
{ok, Files} ->
Ret = forMake(Files, WorkerCnt, lists:member(noexec, MakeOpts), load_opt(MakeOpts), LIsAll, IsNoHrl, []),
Ret = forMake(Files, WorkerCnt, OnceCnt, lists:member(noexec, MakeOpts), load_opt(MakeOpts), LIsAll, IsNoHrl, []),
EndTime = erlang:system_time(second),
saveEMake(EndTime),
case Ret of
@ -208,7 +231,7 @@ foldErl([OneFile | Left], Acc) ->
foldErl(Left, Acc)
end.
forMake([], _Worker, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) ->
forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) ->
case AllWorkPids of
[] ->
ok;
@ -220,7 +243,7 @@ forMake([], _Worker, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) ->
[] ->
ok;
_ ->
forMake([], _Worker, _NoExec, _Load, IsAll, IsNoHrl, NewAllWorkPids)
forMake([], _WorkerCnt, _OnceCnt, _NoExec, _Load, IsAll, IsNoHrl, NewAllWorkPids)
end;
{mCompileError, Err} ->
errorStop(Err, AllWorkPids);
@ -229,31 +252,31 @@ forMake([], _Worker, _NoExec, _Load, IsAll, IsNoHrl, AllWorkPids) ->
{error, _Other}
end
end;
forMake([{Mods, Opts} | Rest], Worker, NoExec, Load, IsAll, IsNoHrl, AllWorkPids) ->
forMake([{Mods, Opts} | Rest], WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, AllWorkPids) ->
case Mods of
[] ->
forMake(Rest, Worker, NoExec, Load, IsAll, IsNoHrl, AllWorkPids);
forMake(Rest, WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, AllWorkPids);
_ ->
case Worker > 0 of
case WorkerCnt > 0 of
true ->
{Files, More} = splitMods(Mods),
{Files, More} = splitMods(Mods, OnceCnt),
WPid = spawn_link(?MODULE, compileWorker, [Files, Opts, self(), NoExec, Load, IsAll, IsNoHrl]),
case More of
over ->
forMake(Rest, Worker - 1, NoExec, Load, IsAll, IsNoHrl, [WPid | AllWorkPids]);
forMake(Rest, WorkerCnt - 1, OnceCnt, NoExec, Load, IsAll, IsNoHrl, [WPid | AllWorkPids]);
_ ->
forMake([{More, Opts} | Rest], Worker - 1, NoExec, Load, IsAll, IsNoHrl, [WPid | AllWorkPids])
forMake([{More, Opts} | Rest], WorkerCnt - 1, OnceCnt, NoExec, Load, IsAll, IsNoHrl, [WPid | AllWorkPids])
end;
_ ->
receive
{mOverCompile, WPid} ->
{Files, More} = splitMods(Mods),
{Files, More} = splitMods(Mods, OnceCnt),
erlang:send(WPid, {mNewFile, Files, Opts}),
case More of
over ->
forMake(Rest, Worker, NoExec, Load, IsAll, IsNoHrl, AllWorkPids);
forMake(Rest, WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, AllWorkPids);
_ ->
forMake([{More, Opts} | Rest], Worker, NoExec, Load, IsAll, IsNoHrl, AllWorkPids)
forMake([{More, Opts} | Rest], WorkerCnt, OnceCnt, NoExec, Load, IsAll, IsNoHrl, AllWorkPids)
end;
{mCompileError, Err} ->
errorStop(Err, AllWorkPids);
@ -264,9 +287,9 @@ forMake([{Mods, Opts} | Rest], Worker, NoExec, Load, IsAll, IsNoHrl, AllWorkPids
end
end.
splitMods(Mods) ->
{CurList, Index, LeftList} = splitFiles(?OnceCnt, Mods, 0, []),
case Index < ?OnceCnt of
splitMods(Mods, OnceCnt) ->
{CurList, Index, LeftList} = splitFiles(OnceCnt, Mods, 0, []),
case Index < OnceCnt of
true ->
{TCurList, _TIndex, TLeftList} = splitFiles(1, Mods, 0, []),
case TLeftList of

Loading…
取消
儲存