diff options
| author | ruki <[email protected]> | 2021-01-20 01:30:43 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-01-20 01:30:43 +0800 |
| commit | 9d11596bc4af13d11f08a17ec6c416fb7673c70d (patch) | |
| tree | 2a0e2480ac14e21816f1881de36ff6dc3d8cb884 | |
| parent | abd2bcb586035ac27358e7c6f31f446284ae36be (diff) | |
| parent | 74908578f6f35f3a9a917e0256cbe55a2bdacbc8 (diff) | |
Merge pull request #1202 from xmake-io/autoupdate
Fix vsxmake autoupdate + cache issue
| -rw-r--r-- | xmake/actions/config/menuconf.lua | 2 | ||||
| -rw-r--r-- | xmake/core/project/config.lua | 126 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/core/project/config.lua | 14 | ||||
| -rw-r--r-- | xmake/plugins/project/vstudio/impl/vs201x.lua | 15 | ||||
| -rw-r--r-- | xmake/plugins/project/vsxmake/vsxmake.lua | 15 | ||||
| -rw-r--r-- | xmake/rules/plugin/vsxmake/xmake.lua | 13 |
6 files changed, 78 insertions, 107 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 f27fc2857..a5107e456 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -29,36 +29,8 @@ 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 +-- get the current given configuration function config.get(name) - - -- get it local value = nil if config._CONFIGS then value = config._CONFIGS[name] @@ -66,8 +38,6 @@ function config.get(name) value = nil end end - - -- get it return value end @@ -107,18 +77,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 +136,40 @@ 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 +-- 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 - - -- merge the target configure first + -- merge into the current configuration local ok = false - for name, value in pairs(results) do - if config.get(name) == nil then - config.set(name, value) - ok = true + 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 - - -- ok? return ok 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 +177,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 diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 8980d0449..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) @@ -308,6 +320,9 @@ function make(outputdir, vsinfo) vs201x_vcxproj_filters.make(vsinfo, target) end + -- clear config and local cache + _clear_cacheconf() + -- 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..3594cf7e2 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") @@ -166,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) @@ -215,5 +227,8 @@ function make(version) _trycp(template_items, proj_dir) _trycp(template_itemfil, proj_dir) end + + -- clear config and local cache + _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 |
