diff options
| author | ruki <[email protected]> | 2019-01-04 22:51:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-01-04 11:09:58 +0800 |
| commit | 76cf129b49dba3abd63de5610900265c63603458 (patch) | |
| tree | c88b20b6a4ab9dfc980e8c2d353059787281fce1 | |
| parent | a5d9cb41fef552951bec41ba5f8c4261953f6bd5 (diff) | |
improve project and history cache
| -rw-r--r-- | xmake/actions/config/main.lua | 27 | ||||
| -rw-r--r-- | xmake/actions/require/clear.lua | 6 | ||||
| -rw-r--r-- | xmake/actions/require/impl/package.lua | 1 | ||||
| -rw-r--r-- | xmake/core/project/cache.lua | 7 | ||||
| -rw-r--r-- | xmake/core/project/history.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/option.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 33 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/cache.lua | 60 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/history.lua | 42 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/detect/cache.lua | 2 | ||||
| -rw-r--r-- | xmake/plugins/macro/main.lua | 20 |
11 files changed, 55 insertions, 147 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index d6538602d..21994603f 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -28,7 +28,7 @@ import("core.project.config") import("core.base.global") import("core.project.project") import("core.platform.platform") -import("core.project.cache", {nocache = true}) +import("core.project.cache") import("lib.detect.cache", {alias = "detectcache"}) import("scangen") import("menuconf", {alias = "menuconf_show"}) @@ -70,8 +70,9 @@ function _need_check(changed) local mtimes = project.mtimes() -- get the previous mtimes + local configcache = cache("local.config") if not changed then - local mtimes_prev = cache.get("mtimes") + local mtimes_prev = configcache:get("mtimes") if mtimes_prev then -- check for all project files @@ -88,7 +89,7 @@ function _need_check(changed) end -- update mtimes - cache.set("mtimes", mtimes) + configcache:set("mtimes", mtimes) -- changed? return changed @@ -182,8 +183,8 @@ function main() -- the target name local targetname = option.get("target") or "all" - -- enter cache scope - cache.enter("local.config") + -- get config cache + local configcache = cache("local.config") -- load the project configure -- @@ -203,7 +204,7 @@ function main() local options_changed = false local options_history = {} if not option.get("clean") then - options_history = cache.get("options_" .. targetname) or {} + options_history = configcache:get("options_" .. targetname) or {} options = options or options_history end for name, value in pairs(options) do @@ -220,9 +221,9 @@ function main() -- @note we cannot load cache config when switching platform, arch .. -- so we need known whether options have been changed -- - local configcache = false + local configcache_loaded = false if not options_changed and not option.get("clean") and not _host_changed(targetname) then - configcache = config.load(targetname) + configcache_loaded = config.load(targetname) end -- merge the global configure @@ -249,7 +250,7 @@ function main() end -- merge the checked configure - local recheck = _need_check(options_changed or not configcache) + local recheck = _need_check(options_changed or not configcache_loaded) if recheck then -- clear detect cache @@ -293,16 +294,16 @@ function main() -- save options and configure for the given target config.save(targetname) - cache.set("options_" .. targetname, options) + configcache:set("options_" .. targetname, options) -- save options and configure for each targets if be all if targetname == "all" then for _, target in pairs(project.targets()) do config.save(target:name()) - cache.set("options_" .. target:name(), options) + configcache:set("options_" .. target:name(), options) end end - -- flush cache - cache.flush() + -- flush config cache + configcache:flush() end diff --git a/xmake/actions/require/clear.lua b/xmake/actions/require/clear.lua index 5b4d67a18..ffe73ed26 100644 --- a/xmake/actions/require/clear.lua +++ b/xmake/actions/require/clear.lua @@ -33,8 +33,8 @@ function main() os.rm(package.cachedir()) -- clear require cache - cache.enter("local.require") - cache.clear() - cache.flush() + local require_cache = cache("local.require") + require_cache:clear() + require_cache:flush() end diff --git a/xmake/actions/require/impl/package.lua b/xmake/actions/require/impl/package.lua index 5826e3a5b..c661bd986 100644 --- a/xmake/actions/require/impl/package.lua +++ b/xmake/actions/require/impl/package.lua @@ -26,7 +26,6 @@ import("core.base.semver") import("core.base.option") import("core.base.global") -import("core.project.cache") import("lib.detect.cache", {alias = "detectcache"}) import("core.project.project") import("core.package.package", {alias = "core_package"}) diff --git a/xmake/core/project/cache.lua b/xmake/core/project/cache.lua index 558acb64d..2394b605c 100644 --- a/xmake/core/project/cache.lua +++ b/xmake/core/project/cache.lua @@ -119,11 +119,14 @@ function cache:flush() -- memory cache? ignore it directly if not self._CACHEPATH then - return true + return end -- save to file - return io.save(self._CACHEPATH, self._CACHEDATA) + local ok, errors = io.save(self._CACHEPATH, self._CACHEDATA) + if not ok then + os.raise(errors) + end end -- return module diff --git a/xmake/core/project/history.lua b/xmake/core/project/history.lua index 60c78d3e0..f988652aa 100644 --- a/xmake/core/project/history.lua +++ b/xmake/core/project/history.lua @@ -89,8 +89,6 @@ end -- load history function history:load(key) - - -- load it return self._CACHE:get(key) end diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 1dd480197..5d59f91b4 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -219,7 +219,7 @@ function option:check() self:enable(false) end - -- no check? save this option to configure directly + -- need not check? only save this option to configuration directly elseif config.get(name) then self:_save() end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 199756ab0..31019db59 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -558,15 +558,36 @@ function project._load_options(disable_filter) -- check options local options = {} for optionname, optioninfo in pairs(results) do - + + -- TODO + -- load it from cache first (@note will discard scripts) + --[[ + local instance = option.load(optionname) + if instance then + + -- patch scripts (e.g. on_check ..) + for k, v in pairs(optioninfo) do + if type(v) == "function" then + instance:set(k, v) + end + end + else + + -- init a option instance + instance = table.inherit(option) + + -- save name and info + instance._NAME = optionname + instance._INFO = optioninfo + end]] + -- init a option instance local instance = table.inherit(option) - assert(instance) -- save name and info instance._NAME = optionname instance._INFO = optioninfo - + -- save it options[optionname] = instance @@ -645,10 +666,8 @@ function project._load_requires() return requires end --- load packages +-- load the packages from the the project file and disable filter, we will process filter after a while function project._load_packages() - - -- load the packages from the the project file and disable filter, we will process filter after a while return project._load_scope("package", true, false) end @@ -716,8 +735,6 @@ end function project.requires() if not project._REQUIRES then - - -- load requires local requires, errors = project._load_requires() if not requires then os.raise(errors) diff --git a/xmake/core/sandbox/modules/import/core/project/cache.lua b/xmake/core/sandbox/modules/import/core/project/cache.lua index 168843f29..98133a967 100644 --- a/xmake/core/sandbox/modules/import/core/project/cache.lua +++ b/xmake/core/sandbox/modules/import/core/project/cache.lua @@ -22,64 +22,6 @@ -- @file cache.lua -- --- define module -local sandbox_core_project_cache = sandbox_core_project_cache or {} - --- load modules -local cache = require("project/cache") -local raise = require("sandbox/modules/raise") -local instance = nil - --- enter the cache scope -function sandbox_core_project_cache.enter(scopename) - - -- get the cache instance - instance = cache(scopename) -end - --- get the value -function sandbox_core_project_cache.get(name) - - -- check - assert(instance) - - -- get it - return instance:get(name) -end - --- set the value -function sandbox_core_project_cache.set(name, value) - - -- check - assert(instance) - - -- set it - instance:set(name, value) -end - --- clear all -function sandbox_core_project_cache:clear() - - -- check - assert(instance) - - -- clear it - instance:clear() -end - --- flush to sandbox_core_project_cache file -function sandbox_core_project_cache:flush() - - -- check - assert(instance) - - -- flush it - local ok, errors = instance:flush() - if not ok then - raise(errors) - end -end - -- return module -return sandbox_core_project_cache +return require("project/cache") diff --git a/xmake/core/sandbox/modules/import/core/project/history.lua b/xmake/core/sandbox/modules/import/core/project/history.lua index 61f412c1a..77a92ebd6 100644 --- a/xmake/core/sandbox/modules/import/core/project/history.lua +++ b/xmake/core/sandbox/modules/import/core/project/history.lua @@ -22,45 +22,5 @@ -- @file history.lua -- --- define module -local sandbox_core_project_history = sandbox_core_project_history or {} - --- load modules -local os = require("base/os") -local io = require("base/io") -local table = require("base/table") -local option = require("base/option") -local string = require("base/string") -local history = require("project/history") -local raise = require("sandbox/modules/raise") -local instance = nil - --- enter the history scope -function sandbox_core_project_history.enter(scopename) - - -- get the history instance - instance = history(scopename) -end - --- load the history data -function sandbox_core_project_history.load(key) - - -- check - assert(instance) - - -- load it - return instance:load(key) -end - --- save the history data -function sandbox_core_project_history.save(key, value) - - -- check - assert(instance) - - -- save it - instance:save(key, value) -end - -- return module -return sandbox_core_project_history +return require("project/history") diff --git a/xmake/core/sandbox/modules/import/lib/detect/cache.lua b/xmake/core/sandbox/modules/import/lib/detect/cache.lua index c8719a414..0cf2da998 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/cache.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/cache.lua @@ -42,8 +42,6 @@ function sandbox_lib_detect_cache._instance() -- get it local detectcache = sandbox_lib_detect_cache._INSTANCE or cache(utils.ifelse(os.isfile(project.file()), "local.detect", "memory.detect")) sandbox_lib_detect_cache._INSTANCE = detectcache - - -- ok? return detectcache end diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua index ed4cf6016..d2faa1413 100644 --- a/xmake/plugins/macro/main.lua +++ b/xmake/plugins/macro/main.lua @@ -24,9 +24,8 @@ -- imports import("core.base.option") -import("core.project.cache", {nocache = true}) import("core.project.config") -import("core.project.history", {nocache = true}) +import("core.project.history") -- the macro directories function _directories() @@ -201,21 +200,15 @@ end -- begin to record macro function _begin() - -- enter local history - history.enter("local.history") - -- patch begin tag to the history: cmdlines - history.save("cmdlines", "__macro_begin__") + history("local.history"):save("cmdlines", "__macro_begin__") end -- end to record macro function _end(macroname) - -- enter local history - history.enter("local.history") - -- load the history: cmdlines - local cmdlines = history.load("cmdlines") + local cmdlines = history("local.history"):load("cmdlines") -- get the last macro block local begin = false @@ -257,7 +250,7 @@ function _end(macroname) end -- patch end tag to the history: cmdlines - history.save("cmdlines", "__macro_end__") + history("local.history"):save("cmdlines", "__macro_end__") -- open the macro file local file = io.open(_wfile(macroname), "w") @@ -291,11 +284,8 @@ function _run(macroname) -- run last command? if macroname == ".." then - -- enter local history - history.enter("local.history") - -- load the history: cmdlines - local cmdlines = history.load("cmdlines") + local cmdlines = history("local.history"):load("cmdlines") -- get the last command local lastcmd = nil |
