From e5c93e33653f4017694d8c630648b5cd5de663da Mon Sep 17 00:00:00 2001 From: AICells <1713699517@qq.com> Date: Mon, 13 Apr 2020 12:41:41 +0800 Subject: [PATCH] bug fix --- README.md | 8 ++++---- include/erlSync.hrl | 2 +- src/sync/esScanner.erl | 30 ++++++++++++++++++++---------- src/sync/esUtils.erl | 22 ++++++++++++++-------- 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index a238f13..c42abed 100644 --- a/README.md +++ b/README.md @@ -26,10 +26,10 @@ {erlSync, [ {moduleTime, 30000}, - {srcDirTime, 5000}, - {srcFileTime, 5000}, - {compareBeamTime, 3000}, - {compareSrcFileTime, 3000}, + {srcDirTime, 6000}, + {srcFileTime, 6000}, + {compareBeamTime, 4000}, + {compareSrcFileTime, 4000}, {srcDirs, undefined} {log, all}, {descendant, fix}, diff --git a/include/erlSync.hrl b/include/erlSync.hrl index e1ded85..22e4cc2 100644 --- a/include/erlSync.hrl +++ b/include/erlSync.hrl @@ -12,7 +12,7 @@ -define(onlyMods, onlyMods). -define(excludedMods, excludedMods). -define(descendant, descendant). --define(CfgList, [{?Log, all}, {?moduleTime, 30000}, {?srcDirTime, 5000}, {?srcFileTime, 5000}, {?compareBeamTime, 3000}, {?compareSrcFileTime, 3000}, {?srcDirs, undefined}, {?onlyMods, []}, {?excludedMods, []}, {?descendant, fix}]). +-define(CfgList, [{?Log, all}, {?moduleTime, 30000}, {?srcDirTime, 6000}, {?srcFileTime, 6000}, {?compareBeamTime, 4000}, {?compareSrcFileTime, 4000}, {?srcDirs, undefined}, {?onlyMods, []}, {?excludedMods, []}, {?descendant, fix}]). -define(esCfgSync, esCfgSync). diff --git a/src/sync/esScanner.erl b/src/sync/esScanner.erl index 648d574..0be90ac 100644 --- a/src/sync/esScanner.erl +++ b/src/sync/esScanner.erl @@ -296,9 +296,8 @@ syncLoadModOnAllNodes(Module) -> {Module, Binary, _} = code:get_object_code(Module), FSync = fun(Node) -> - io:format("[~s:~p] DEBUG - Node: ~p", [?MODULE, ?LINE, Node]), - Msg = io_lib:format("Reloading '~s' on ~s", [Module, Node]), - esUtils:logSuccess(Msg), + MsgNode = io_lib:format("Reloading '~s' on ~p", [Module, Node]), + esUtils:logSuccess(MsgNode), rpc:call(Node, code, ensure_loaded, [Module]), case rpc:call(Node, code, which, [Module]) of Filename when is_binary(Filename) orelse is_list(Filename) -> @@ -308,7 +307,7 @@ syncLoadModOnAllNodes(Module) -> case rpc:call(Node, code, load_file, [Module]) of {module, Module} -> - Msg = io_lib:format("Reloaded(Beam changed) Mod:~s and write Success on node:~p", [Node, Module]), + Msg = io_lib:format("Reloaded(Beam changed) Mod:~s and write Success on node:~p", [Module, Node]), esUtils:logSuccess(Msg); {error, What} -> Msg = io_lib:format("Reloaded(Beam changed) Mod:~s and write Errors on node:~p Reason:~p", [Module, Node, What]), @@ -318,7 +317,7 @@ syncLoadModOnAllNodes(Module) -> %% File doesn't exist, just load into VM. case rpc:call(Node, code, load_binary, [Module, undefined, Binary]) of {module, Module} -> - Msg = io_lib:format("Reloaded(Beam changed) Mod:~s Success on node:~p", [Node, Module]), + Msg = io_lib:format("Reloaded(Beam changed) Mod:~s Success on node:~p", [Module, Node]), esUtils:logSuccess(Msg); {error, What} -> Msg = io_lib:format("Reloaded(Beam changed) Mod:~s Errors on node:~p Reason:~p", [Module, Node, What]), @@ -466,11 +465,11 @@ recompileSrcFile(SrcFile, _SwSyncNode) -> {ok, Errors, Warnings} end; undefined -> - Msg = io_lib:format("Unable to determine options for ~p", [SrcFile]), + Msg = io_lib:format("Unable to determine options for ~s", [SrcFile]), esUtils:logErrors(Msg) end; _ -> - Msg = io_lib:format("not find the file ~p", [SrcFile]), + Msg = io_lib:format("not find the file ~s", [SrcFile]), esUtils:logErrors(Msg) end. @@ -480,7 +479,6 @@ printResults(_Module, SrcFile, [], []) -> printResults(_Module, SrcFile, [], Warnings) -> Msg = [formatErrors(SrcFile, [], Warnings), io_lib:format("~s Recompiled with ~p warnings", [SrcFile, length(Warnings)])], esUtils:logWarnings(Msg); - printResults(_Module, SrcFile, Errors, Warnings) -> Msg = [formatErrors(SrcFile, Errors, Warnings)], esUtils:logErrors(Msg). @@ -544,7 +542,8 @@ warnDelHrlFiles(HrlFile, SrcFiles) -> case WhoInclude of [] -> ok; _ -> - Msg = io_lib:format("Warning. Deleted ~p file included in existing src files: ~p", [filename:basename(HrlFile), lists:map(fun(File) -> filename:basename(File) end, WhoInclude)]), + Msg = io_lib:format("Warning. Deleted ~p file included in existing src files: ~p", [filename:basename(HrlFile), lists:map(fun(File) -> + filename:basename(File) end, WhoInclude)]), esUtils:logSuccess(lists:flatten(Msg)) end. @@ -664,7 +663,18 @@ setOptions(SrcDir, Options) -> undefined -> erlang:put(SrcDir, Options); OldOptions -> - NewOptions = lists:usort(Options ++ OldOptions), + NewOptions = + case lists:keytake(compile_info, 1, Options) of + {value, {compile_info, ValList1}, Options1} -> + case lists:keytake(compile_info, 1, OldOptions) of + {value, {compile_info, ValList2}, Options2} -> + [{compile_info, lists:usort(ValList1 ++ ValList2)} | lists:usort(Options1 ++ Options2)]; + _ -> + lists:usort(Options ++ OldOptions) + end; + _ -> + lists:usort(Options ++ OldOptions) + end, erlang:put(SrcDir, NewOptions) end. diff --git a/src/sync/esUtils.erl b/src/sync/esUtils.erl index 843b74e..b2274e9 100644 --- a/src/sync/esUtils.erl +++ b/src/sync/esUtils.erl @@ -37,7 +37,7 @@ getModSrcDir(Module) -> %% is not a descendant, but we allow them, so good to go {true, false, allow} -> Source; %% is not a descendant, and we fix non-descendants, so let's fix it - {_, false, fix} -> fixDescendantSource(Source); + {_, false, fix} -> fixDescendantSource(Source, IsFile); %% Anything else, and we don't know what to do, so let's just bail. _ -> undefined end, @@ -102,7 +102,7 @@ transformInclude(_, _, Other) -> Other. maybeAddCompileInfo(Options) -> - case lists:member(predetermined, Options) of + case lists:member(compile_info, Options) of true -> Options; false -> addCompileInfo(Options) end. @@ -142,7 +142,7 @@ getFileType(Source) when is_list(Source) -> %% above. determineIncludeDir(IncludeDir, BeamDir, SrcDir) -> IncludeBase = filename:basename(IncludeDir), - case determineIncludeDirFromBeamDir(IncludeBase, BeamDir) of + case determineIncludeDirFromBeamDir(IncludeBase, IncludeDir, BeamDir) of {ok, D} -> {ok, D}; undefined -> {ok, Cwd} = file:get_cwd(), @@ -156,11 +156,17 @@ determineIncludeDir(IncludeDir, BeamDir, SrcDir) -> end. %% First try to see if we have an include file alongside our ebin directory, which is typically the case -determineIncludeDirFromBeamDir(IncludeBase, BeamDir) -> +determineIncludeDirFromBeamDir(IncludeBase, IncludeDir, BeamDir) -> BeamBasedIncDir = filename:join(filename:dirname(BeamDir), IncludeBase), case filelib:is_dir(BeamBasedIncDir) of true -> {ok, BeamBasedIncDir}; - false -> undefined + false -> + BeamBasedIncDir2 = filename:join(filename:dirname(BeamDir), IncludeDir), + case filelib:is_dir(BeamBasedIncDir2) of + true -> {ok, BeamBasedIncDir2}; + _ -> + undefined + end end. %% Then we dig back through the parent directories until we find our include directory @@ -190,13 +196,13 @@ findIncludeDirFromAncestors(Cwd, IncludeBase, Dir) -> %% path one by one prefixing it with the current working directory until it %% either finds a match, or fails. If it succeeds, it returns the Path to the %% new Source file. -fixDescendantSource([]) -> +fixDescendantSource([], _IsFile) -> undefined; -fixDescendantSource(Path) -> +fixDescendantSource(Path, IsFile) -> {ok, Cwd} = file:get_cwd(), PathParts = filename:split(Path), case makeDescendantSource(Cwd, PathParts) of - undefined -> Path; + undefined -> case IsFile of true -> Path; _ -> undefined end; FoundPath -> FoundPath end.