diff options
| author | ruki <[email protected]> | 2020-12-22 00:54:06 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-12-22 00:54:06 +0800 |
| commit | 03ea42dd480b1397394c2363a61b09f438498283 (patch) | |
| tree | 7fbbfc885d5ca3b179738b2ec8ebcaf8cf993840 | |
| parent | 7d9cc008773b3ee14036778ae0985518951e8c4a (diff) | |
fix history
| -rw-r--r-- | xmake/core/main.lua | 7 | ||||
| -rw-r--r-- | xmake/core/project/history.lua | 92 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua | 7 | ||||
| -rw-r--r-- | xmake/plugins/macro/main.lua | 49 |
4 files changed, 36 insertions, 119 deletions
diff --git a/xmake/core/main.lua b/xmake/core/main.lua index ad343edb4..8eb3e065b 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -267,7 +267,12 @@ Or you can add `--root` option or XMAKE_ROOT=y to allow run as root temporarily. -- save command lines to history and we need to make sure that the .xmake directory is not generated everywhere local skip_history = (os.getenv('XMAKE_SKIP_HISTORY') or ''):trim() if os.projectfile() and os.isfile(os.projectfile()) and os.isdir(config.directory()) and skip_history == '' then - localcache.set("history", "cmdlines", option.cmdline()) + local cmdlines = table.wrap(localcache.get("history", "cmdlines")) + if #cmdlines > 64 then + table.remove(cmdlines, 1) + end + table.insert(cmdlines, option.cmdline()) + localcache.set("history", "cmdlines", cmdlines) localcache.save("history") end diff --git a/xmake/core/project/history.lua b/xmake/core/project/history.lua deleted file mode 100644 index f34874fd1..000000000 --- a/xmake/core/project/history.lua +++ /dev/null @@ -1,92 +0,0 @@ ---!A cross-platform build utility based on Lua --- --- Licensed under the Apache License, Version 2.0 (the "License"); --- you may not use this file except in compliance with the License. --- You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, software --- distributed under the License is distributed on an "AS IS" BASIS, --- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --- See the License for the specific language governing permissions and --- limitations under the License. --- --- Copyright (C) 2015-present, TBOOX Open Source Group. --- --- @author ruki --- @file history.lua --- - --- define module: history -local history = history or {} - --- load modules -local os = require("base/os") -local io = require("base/io") -local table = require("base/table") -local utils = require("base/utils") -local string = require("base/string") -local cache = require("cache/localcache") - --- the cache instance --- --- @param scopename local.xxxx --- global.xxxx --- -function history._instance(scopename) - - -- check - assert(scopename) - - -- init instances - history._INSTANCES = history._INSTANCES or {} - local instances = history._INSTANCES - - -- this instance has been initialized? - if instances[scopename] then - return instances[scopename] - end - - -- init instance - local instance = table.inherit(history) - - -- init cache - instance._CACHE = cache(scopename) - - -- save instance - instances[scopename] = instance - - -- ok - return instance -end - --- save history -function history:save(key, value) - - -- check - assert(key and value ~= nil) - - -- load history values first - local values = self:load(key) or {} - - -- remove the oldest value if be full - if #values > 64 then - table.remove(values, 1) - end - - -- append this value - table.insert(values, value) - - -- save history - self._CACHE:set(key, values) - self._CACHE:flush() -end - --- load history -function history:load(key) - return self._CACHE:get(key) -end - --- return module: history -return history._instance diff --git a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua index 89ba5494e..65e85fabe 100644 --- a/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua +++ b/xmake/core/sandbox/modules/import/core/sandbox/sandbox.lua @@ -109,8 +109,13 @@ function sandbox_core_sandbox.interactive() -- save to history local entries = readline.history_list() if #entries > #replhistory then + local historylines = globalcache.get("history", "replhistory") or {} for i = #replhistory + 1, #entries do - globalcache.set("history", "replhistory", entries[i].line) + if #historylines > 64 then + table.remove(historylines, 1) + end + table.insert(historylines, entries[i].line) + globalcache.set("history", "replhistory", historylines) end globalcache.save("history") end diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua index 12c8fc6f8..cf0929792 100644 --- a/xmake/plugins/macro/main.lua +++ b/xmake/plugins/macro/main.lua @@ -194,40 +194,38 @@ end function _end(macroname) -- load the history: cmdlines - local cmdlines = localcache.get("history", "cmdlines") + local cmdlines = table.wrap(localcache.get("history", "cmdlines")) -- get the last macro block local begin = false local block = {} - if cmdlines then - local total = #cmdlines - local index = total - while index ~= 0 do + local total = #cmdlines + local index = total + while index ~= 0 do - -- the command line - local cmdline = cmdlines[index] + -- the command line + local cmdline = cmdlines[index] - -- found begin? break it - if cmdline == "__macro_begin__" then - begin = true - break - end - - -- found end? break it - if cmdline == "__macro_end__" then - break - end + -- found begin? break it + if cmdline == "__macro_begin__" then + begin = true + break + end - -- ignore "xmake m .." and "xmake macro .." - if not cmdline:find("xmake%s+macro%s*") and not cmdline:find("xmake%s+m%s*") then + -- found end? break it + if cmdline == "__macro_end__" then + break + end - -- save this command line to block - table.insert(block, 1, cmdline) - end + -- ignore "xmake m .." and "xmake macro .." + if not cmdline:find("xmake%s+macro%s*") and not cmdline:find("xmake%s+m%s*") then - -- the previous line - index = index - 1 + -- save this command line to block + table.insert(block, 1, cmdline) end + + -- the previous line + index = index - 1 end -- the begin tag not found? @@ -236,7 +234,8 @@ function _end(macroname) end -- patch end tag to the history: cmdlines - localcache.set("history", "cmdlines", "__macro_end__") + table.insert(cmdlines, "__macro_end__") + localcache.set("history", "cmdlines", cmdlines) localcache.save("history") -- open the macro file |
