diff options
| author | ruki <[email protected]> | 2020-12-23 23:49:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-12-23 23:49:51 +0800 |
| commit | 414e6f39860680b693263fd97daa77c48dc5e143 (patch) | |
| tree | 9b99a62fcf5f0f30ad18beb8e1ba56cad320bb82 | |
| parent | 50f826bb2df51dd80eb67054e446a496f2b6d15a (diff) | |
improve project
| -rw-r--r-- | xmake/core/project/option.lua | 8 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 135 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/project.lua | 6 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 14 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/getinfo.lua | 11 |
5 files changed, 82 insertions, 92 deletions
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua index 4cee0d494..e7d1c159c 100644 --- a/xmake/core/project/option.lua +++ b/xmake/core/project/option.lua @@ -239,21 +239,13 @@ end -- set the option value function _instance:set_value(value) - - -- set value to option config.set(self:name(), value) - - -- save option self:_save() end -- clear the option status and need recheck it function _instance:clear() - - -- clear config config.set(self:name(), nil) - - -- clear this option in cache self:_clear() end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 28b7daddf..db00493ea 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -32,6 +32,7 @@ local global = require("base/global") local process = require("base/process") local deprecated = require("base/deprecated") local interpreter = require("base/interpreter") +local memcache = require("cache/memcache") local rule = require("project/rule") local target = require("project/target") local config = require("project/config") @@ -107,7 +108,7 @@ end -- some packages are enabled? function project._api_has_package(interp, ...) -- only for loading targets - local requires = project._REQUIRES + local requires = project._memcache():get("requires") if requires then for _, name in ipairs(table.join(...)) do local pkg = requires[name] @@ -151,7 +152,7 @@ end function project._load(force, disable_filter) -- has already been loaded? - if project._INFO and not force then + if project._memcache():get("rootinfo") and not force then return true end @@ -195,7 +196,7 @@ function project._load(force, disable_filter) for name, value in pairs(rootinfo_target:info()) do rootinfo:set("target." .. name, value) end - project._INFO = rootinfo + project._memcache():set("rootinfo", rootinfo) -- leave the project directory oldir, errors = os.cd(oldir) @@ -401,7 +402,7 @@ function project._load_targets() -- mark targets have been loaded even if it may fail to load. -- because once loaded, there will be some cached state, such as options, -- so if we load it a second time, there will be some hidden state inconsistencies. - project._TARGETS_LOADED = true + project._memcache():set("targets_loaded", true) -- load all requires first and reload the project file to ensure has_package() works for targets local requires = project.requires() @@ -671,16 +672,21 @@ function project._sort_targets(targets, ordertargets, targetrefs, target) end end +-- get project memcache +function project._memcache() + return memcache.cache("core.project.project") +end + -- get project toolchain infos (@note only with toolchain info) function project._toolchains() - local toolchains = project._TOOLCHAINS + local toolchains = project._memcache():get("toolchains") if not toolchains then local errors toolchains, errors = project._load_toolchains() if not toolchains then os.raise(errors) end - project._TOOLCHAINS = toolchains + project._memcache():set("toolchains", toolchains) end return toolchains end @@ -880,7 +886,8 @@ end -- get the project info from the given name function project.get(name) - return project._INFO and project._INFO:get(name) or nil + local rootinfo = project._memcache():get("rootinfo") + return rootinfo and rootinfo:get(name) or nil end -- get the project name @@ -901,10 +908,10 @@ end -- get the project policy, the root policy of the target scope function project.policy(name) - local policies = project._POLICIES + local policies = project._memcache():get("policies") if not policies then policies = project.get("target.policy") - project._POLICIES = policies + project._memcache():set("policies", policies) if policies then local defined_policies = policy.policies() for name, _ in pairs(policies) do @@ -917,32 +924,9 @@ function project.policy(name) return policy.check(name, policies and policies[name]) end --- clear project cache to reload targets and options -function project.clear() - - -- clear options status in config file first - for _, opt in ipairs(table.wrap(project._OPTIONS)) do - opt:clear() - end - - -- clear cache - project._INFO = nil - project._TARGETS = nil - project._TARGETS_LOADED = false - project._ORDERTARGETS = nil - project._OPTIONS = nil - project._REQUIRES = nil - project._REQUIRES_STR = nil - project._REQUIRES_EXTRA = nil - project._RULES = nil - project._TASKS = nil - project._PACKAGES = nil - project._POLICIES = nil -end - -- project has been loaded? function project.is_loaded() - return project._TARGETS_LOADED + return project._memcache():get("targets_loaded") end -- get the given target @@ -952,24 +936,27 @@ end -- get targets function project.targets() - if not project._TARGETS then - local targets, ordertargets, errors = project._load_targets() + local targets = project._memcache():get("targets") + if not targets then + local ordertargets, errors + targets, ordertargets, errors = project._load_targets() if not targets or not ordertargets then os.raise(errors) end - project._TARGETS = targets - project._ORDERTARGETS = ordertargets + project._memcache():set("targets", targets) + project._memcache():set("ordertargets", ordertargets) end - return project._TARGETS + return targets end -- get order targets function project.ordertargets() - if not project._ORDERTARGETS then - -- ensure _ORDERTARGETS to be initialized + local ordertargets = project._memcache():get("ordertargets") + if not ordertargets then + -- ensure ordertargets to be cached project.targets() end - return project._ORDERTARGETS + return ordertargets end -- get the given option @@ -979,18 +966,16 @@ end -- get options function project.options() - - -- load options and enable filter - if not project._OPTIONS then - local options, errors = project._load_options() + local options = project._memcache():get("options") + if not options then + local errors + options, errors = project._load_options() if not options then os.raise(errors) end - project._OPTIONS = options + project._memcache():set("options", options) end - - -- ok - return project._OPTIONS + return options end -- get the given require info @@ -1000,19 +985,23 @@ end -- get requires info function project.requires() - if not project._REQUIRES then - local requires, errors = project._load_requires() + local requires = project._memcache():get("requires") + if not requires then + local errors + requires, errors = project._load_requires() if not requires then os.raise(errors) end - project._REQUIRES = requires + project._memcache():set("requires", requires) end - return project._REQUIRES + return requires end -- get string requires function project.requires_str() - if not project._REQUIRES_STR then + local requires_str = project._memcache():get("requires_str") + local requires_extra = project._memcache():get("requires_extra") + if not requires_str then -- reload the project file to handle `has_config()` local ok, errors = project._load(true) @@ -1021,11 +1010,11 @@ function project.requires_str() end -- get raw requires - local requires_str, requires_extra = project.get("requires"), project.get("__extra_requires") - project._REQUIRES_STR = requires_str or false - project._REQUIRES_EXTRA = requires_extra + requires_str, requires_extra = project.get("requires"), project.get("__extra_requires") + project._memcache():set("requires_str", requires_str or false) + project._memcache():set("requires_extra", requires_extra) end - return project._REQUIRES_STR or nil, project._REQUIRES_EXTRA + return requires_str or nil, requires_extra end -- get the given rule @@ -1035,14 +1024,16 @@ end -- get project rules function project.rules() - if not project._RULES then - local rules, errors = project._load_rules() + local rules = project._memcache():get("rules") + if not rules then + local errors + rules, errors = project._load_rules() if not rules then os.raise(errors) end - project._RULES = rules + project._memcache():set("rules", rules) end - return project._RULES + return rules end -- get the given toolchain @@ -1065,26 +1056,30 @@ end -- get tasks function project.tasks() - if not project._TASKS then - local tasks, errors = project._load_tasks() + local tasks = project._memcache():get("tasks") + if not tasks then + local errors + tasks, errors = project._load_tasks() if not tasks then os.raise(errors) end - project._TASKS = tasks + project._memcache():set("tasks", tasks) end - return project._TASKS + return tasks end -- get packages function project.packages() - if not project._PACKAGES then - local packages, errors = project._load_packages() + local packages = project._memcache():get("packages") + if not packages then + local errors + packages, errors = project._load_packages() if not packages then return nil, errors end - project._PACKAGES = packages + project._memcache():set("packages", packages) end - return project._PACKAGES + return packages end -- get the mtimes diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index 8095971c2..1e5faa2a9 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -50,7 +50,6 @@ sandbox_core_project.rootfile = project.rootfile sandbox_core_project.allfiles = project.allfiles sandbox_core_project.rcfile = project.rcfile sandbox_core_project.directory = project.directory -sandbox_core_project.clear = project.clear sandbox_core_project.name = project.name sandbox_core_project.modes = project.modes sandbox_core_project.mtimes = project.mtimes @@ -63,11 +62,6 @@ sandbox_core_project.tmpdir = project.tmpdir sandbox_core_project.tmpfile = project.tmpfile sandbox_core_project.is_loaded = project.is_loaded --- load project -function sandbox_core_project.load() - deprecated.add("project.clear() or only remove it", "project.load()") -end - -- check project options function sandbox_core_project.check() diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index cdb18a828..f0a98ac53 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -233,17 +233,19 @@ function make(outputdir, vsinfo) -- reload config, project and platform if mode ~= config.mode() or arch ~= config.arch() then - -- clear cache - memcache.clear() - localcache.clear() - -- modify config config.set("as", nil, {force = true}) -- force to re-check as for ml/ml64 config.set("mode", mode, {readonly = true, force = true}) config.set("arch", arch, {readonly = true, force = true}) - -- clear project to reload and recheck it - project.clear() + -- clear all options + for _, opt in ipairs(project.options()) do + opt:clear() + end + + -- clear cache + memcache.clear() + localcache.clear() -- check platform platform.load(config.plat(), arch):check() diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index e7b7cc556..a3a978111 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -27,6 +27,7 @@ import("core.project.project") import("core.platform.platform") import("core.tool.compiler") import("core.tool.linker") +import("core.cache.memcache") import("core.cache.localcache") import("lib.detect.find_tool") import("private.action.run.make_runenvs") @@ -292,8 +293,14 @@ function main(outputdir, vsinfo) config.set("mode", mode, {readonly = true, force = true}) config.set("arch", arch, {readonly = true, force = true}) - -- clear project to reload and recheck it - project.clear() + -- clear all options + for _, opt in ipairs(project.options()) do + opt:clear() + end + + -- clear cache + memcache.clear() + localcache.clear() -- check platform platform.load(config.plat(), arch):check() |
