From fbaadb6a0f41d29dd14afb3910e2ff9be3719e04 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 Jan 2021 00:56:23 +0800 Subject: improve config --- xmake/core/project/config.lua | 117 +++++---------------- .../sandbox/modules/import/core/project/config.lua | 14 ++- 2 files changed, 30 insertions(+), 101 deletions(-) diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index f27fc2857..78bdc2907 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -29,32 +29,6 @@ local table = require("base/table") local utils = require("base/utils") local option = require("base/option") --- load the project configure -function config._load(targetname) - - -- check - targetname = targetname or "all" - - -- load configure from the file first - local filepath = config.filepath() - if os.isfile(filepath) then - - -- load it - local results, errors = io.load(filepath) - if not results then - return nil, errors - end - - -- load the target configure - if results._TARGETS then - return table.wrap(results._TARGETS[targetname]) - end - end - - -- empty - return {} -end - -- get the current given configure function config.get(name) @@ -107,18 +81,15 @@ end -- get all options function config.options() - -- check - assert(config._CONFIGS) - -- remove values with "auto" and private item local configs = {} - for name, value in pairs(config._CONFIGS) do - if not name:find("^_%u+") and (type(value) ~= "string" or value ~= "auto") then - configs[name] = value + if config._CONFIGS then + for name, value in pairs(config._CONFIGS) do + if not name:find("^_%u+") and (type(value) ~= "string" or value ~= "auto") then + configs[name] = value + end end end - - -- get it return configs end @@ -169,69 +140,31 @@ function config.directory() return config._DIRECTORY end --- load the project configure -function config.load(targetname) - - -- load configure - local results, errors = config._load(targetname) - if not results then - utils.error(errors) - return false - end - - -- merge the target configure first - local ok = false - for name, value in pairs(results) do - if config.get(name) == nil then - config.set(name, value) - ok = true +-- load the project configuration +function config.load() + local configs, errors + if os.isfile(config.filepath()) then + configs, errors = io.load(config.filepath()) + if not configs then + utils.error(errors) + return false end end - - -- ok? - return ok + config._CONFIGS = configs + return true end --- save the project configure -function config.save(targetname) - - -- check - targetname = targetname or "all" - - -- load the previous results from configure - local results = {} - local filepath = config.filepath() - if os.isfile(filepath) then - results = io.load(filepath) or {} - end - - -- the targets - local targets = results._TARGETS or {} - results._TARGETS = targets - - -- clear target first - targets[targetname] = {} - - -- update target - local target = targets[targetname] - for name, value in pairs(config.options()) do - target[name] = value - end - - -- add version - results.__version = xmake._VERSION_SHORT - - -- save it - return io.save(config.filepath(), results) +-- save the project configuration +function config.save() + return io.save(config.filepath(), config.options()) end --- read value from the configure file directly -function config.read(name, targetname) - - -- load configs - local configs = config._load(targetname) - - -- get it +-- read value from the configuration file directly +function config.read(name) + local configs + if os.isfile(config.filepath()) then + configs = io.load(config.filepath()) + end local value = nil if configs then value = configs[name] @@ -239,8 +172,6 @@ function config.read(name, targetname) value = nil end end - - -- ok? return value end diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 9b122c2e6..76647e313 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -87,23 +87,21 @@ function sandbox_core_project_config.readonly(name) end -- load the configuration -function sandbox_core_project_config.load(targetname) - return config.load(targetname) +function sandbox_core_project_config.load() + return config.load() end -- save the configuration -function sandbox_core_project_config.save(targetname) - - -- save it - local ok, errors = config.save(targetname) +function sandbox_core_project_config.save() + local ok, errors = config.save() if not ok then raise(errors) end end -- read the value from the configuration file directly -function sandbox_core_project_config.read(name, targetname) - return config.read(name, targetname) +function sandbox_core_project_config.read(name) + return config.read(name) end -- clear the configuration -- cgit v1.3.1 From 576784050e14cd1eed1ab9284399e2731a885335 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 Jan 2021 00:58:16 +0800 Subject: improve vs/vsxmake --- xmake/plugins/project/vstudio/impl/vs201x.lua | 10 ++++++++++ xmake/plugins/project/vsxmake/vsxmake.lua | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 8980d0449..e02fd5dec 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -308,6 +308,16 @@ function make(outputdir, vsinfo) vs201x_vcxproj_filters.make(vsinfo, target) end + -- clear config and local cache + config.clear() + config.save() + localcache.clear("config") + localcache.clear("detect") + localcache.clear("option") + localcache.clear("package") + localcache.clear("toolchain") + localcache.save() + -- leave project directory os.cd(oldir) end diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index 926533dbf..3f3617a38 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -24,6 +24,7 @@ import("vstudio.impl.vsinfo", { rootdir = path.directory(os.scriptdir()) }) import("render") import("getinfo") import("core.project.config") +import("core.cache.localcache") local template_root = path.join(os.scriptdir(), "vsproj", "templates") local template_sln = path.join(template_root, "sln", "vsxmake.sln") @@ -215,5 +216,15 @@ function make(version) _trycp(template_items, proj_dir) _trycp(template_itemfil, proj_dir) end + + -- clear config and local cache + config.clear() + config.save() + localcache.clear("config") + localcache.clear("detect") + localcache.clear("option") + localcache.clear("package") + localcache.clear("toolchain") + localcache.save() end end -- cgit v1.3.1 From d9189f7cd7843a39346a288a58a884ea9dcdf792 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 Jan 2021 22:34:13 +0800 Subject: improve config --- xmake/actions/config/menuconf.lua | 2 +- xmake/core/project/config.lua | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/xmake/actions/config/menuconf.lua b/xmake/actions/config/menuconf.lua index 5d06e007f..5d4c53027 100644 --- a/xmake/actions/config/menuconf.lua +++ b/xmake/actions/config/menuconf.lua @@ -360,7 +360,7 @@ function app:load(cache) -- load config from cache if cache then - cache = config.load(option.get("target") or "all") + cache = config.load() end -- clear configs first diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 78bdc2907..a5107e456 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -29,10 +29,8 @@ local table = require("base/table") local utils = require("base/utils") local option = require("base/option") --- get the current given configure +-- get the current given configuration function config.get(name) - - -- get it local value = nil if config._CONFIGS then value = config._CONFIGS[name] @@ -40,8 +38,6 @@ function config.get(name) value = nil end end - - -- get it return value end @@ -150,8 +146,17 @@ function config.load() return false end end - config._CONFIGS = configs - return true + -- merge into the current configuration + local ok = false + if configs then + for name, value in pairs(configs) do + if config.get(name) == nil then + config.set(name, value) + ok = true + end + end + end + return ok end -- save the project configuration -- cgit v1.3.1 From 74908578f6f35f3a9a917e0256cbe55a2bdacbc8 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 Jan 2021 22:38:57 +0800 Subject: improve autoupdate rule --- xmake/plugins/project/vstudio/impl/vs201x.lua | 21 +++++++++++++-------- xmake/plugins/project/vsxmake/vsxmake.lua | 20 ++++++++++++-------- xmake/rules/plugin/vsxmake/xmake.lua | 13 ++++++++++--- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index e02fd5dec..28454ba6e 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -35,6 +35,18 @@ import("actions.require.install", {alias = "install_requires", rootdir = os.prog import("actions.config.configfiles", {alias = "generate_configfiles", rootdir = os.programdir()}) import("actions.config.configheader", {alias = "generate_configheader", rootdir = os.programdir()}) +-- clear cache configuration +function _clear_cacheconf() + config.clear() + config.save() + localcache.clear("config") + localcache.clear("detect") + localcache.clear("option") + localcache.clear("package") + localcache.clear("toolchain") + localcache.save() +end + -- make target info function _make_targetinfo(mode, arch, target) @@ -309,14 +321,7 @@ function make(outputdir, vsinfo) end -- clear config and local cache - config.clear() - config.save() - localcache.clear("config") - localcache.clear("detect") - localcache.clear("option") - localcache.clear("package") - localcache.clear("toolchain") - localcache.save() + _clear_cacheconf() -- leave project directory os.cd(oldir) diff --git a/xmake/plugins/project/vsxmake/vsxmake.lua b/xmake/plugins/project/vsxmake/vsxmake.lua index 3f3617a38..3594cf7e2 100644 --- a/xmake/plugins/project/vsxmake/vsxmake.lua +++ b/xmake/plugins/project/vsxmake/vsxmake.lua @@ -167,6 +167,17 @@ function _writefileifneeded(file, content) io.writefile(file, content) end +function _clear_cacheconf() + config.clear() + config.save() + localcache.clear("config") + localcache.clear("detect") + localcache.clear("option") + localcache.clear("package") + localcache.clear("toolchain") + localcache.save() +end + -- make function make(version) @@ -218,13 +229,6 @@ function make(version) end -- clear config and local cache - config.clear() - config.save() - localcache.clear("config") - localcache.clear("detect") - localcache.clear("option") - localcache.clear("package") - localcache.clear("toolchain") - localcache.save() + _clear_cacheconf() end end diff --git a/xmake/rules/plugin/vsxmake/xmake.lua b/xmake/rules/plugin/vsxmake/xmake.lua index c37c38101..c1e9506ce 100644 --- a/xmake/rules/plugin/vsxmake/xmake.lua +++ b/xmake/rules/plugin/vsxmake/xmake.lua @@ -28,7 +28,8 @@ -- @endcode -- rule("plugin.vsxmake.autoupdate") - after_build(function (target) + set_kind("project") + after_build(function (opt) -- imports import("core.project.depend") @@ -37,17 +38,23 @@ rule("plugin.vsxmake.autoupdate") -- run only once for all xmake process in vs local tmpfile = os.tmpfile(path.join(os.projectdir(), "plugin.vsxmake.autoupdate")) + local dependfile = tmpfile .. ".d" local lockfile = io.openlock(tmpfile .. ".lock") if lockfile:trylock() then if os.getenv("XMAKE_IN_VSTUDIO") then + local sourcefiles = {} + for _, target in pairs(project.targets()) do + table.join2(sourcefiles, (target:sourcefiles())) + end + table.sort(sourcefiles) depend.on_changed(function () -- we use task instead of os.exec("xmake") to avoid the project lock print("update vsxmake project ..") task.run("project", {kind = "vsxmake"}) print("update vsxmake project ok") - end, {dependfile = tmpfile .. ".d", + end, {dependfile = dependfile, files = project.allfiles(), - values = target:sourcefiles()}) + values = sourcefiles}) end lockfile:close() end -- cgit v1.3.1