From d24fcddbc2f1093f3943a917d99c5a8989ef2644 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 6 Jul 2016 09:12:08 +0800 Subject: [PATCH] fix configure error after host changed --- xmake/actions/config/main.lua | 7 +- xmake/core/project/config.lua | 76 +++++++++++++------ .../modules/import/core/project/config.lua | 7 ++ 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 9b7790f0cc6..8b46f58a172 100755 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -34,6 +34,11 @@ function _option_filter(name) return name and name ~= "target" and name ~= "file" and name ~= "project" and name ~= "verbose" end +-- host changed? +function _host_changed(targetname) + return os.host() ~= config.read("host", targetname) +end + -- need check function _need_check() @@ -194,7 +199,7 @@ function main() end -- merge the cached configure - if not option.get("clean") then + if not option.get("clean") and not _host_changed(targetname) then config.load(targetname) end diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua index 86055d05c15..9772f0d6ea8 100644 --- a/xmake/core/project/config.lua +++ b/xmake/core/project/config.lua @@ -39,6 +39,32 @@ function config._file() return path.join(config.directory(), "xmake.conf") end +-- load the project configure +function config._load(targetname) + + -- check + targetname = targetname or "all" + + -- load configure from the file first + local filepath = config._file() + 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) @@ -98,29 +124,16 @@ end -- load the project configure function config.load(targetname) - -- check - targetname = targetname or "all" - - -- load configure from the file first - local filepath = config._file() - if os.isfile(filepath) then - - -- load it - local results, errors = io.load(filepath) + local results, errors = config._load(targetname) + if not results then + utils.error(errors) + return true + end - -- error? - if not results then - utils.error(errors) - return true - end - - -- merge the target configure first - if results._TARGETS then - for name, value in pairs(table.wrap(results._TARGETS[targetname])) do - if config.get(name) == nil then - config.set(name, value) - end - end + -- merge the target configure first + for name, value in pairs(results) do + if config.get(name) == nil then + config.set(name, value) end end @@ -161,6 +174,25 @@ function config.save(targetname) return io.save(config._file(), results) end +-- read value from the configure file directly +function config.read(name, targetname) + + -- load configs + local configs = config._load(targetname) + + -- get it + local value = nil + if configs then + value = configs[name] + if type(value) == "string" and value == "auto" then + value = nil + end + end + + -- ok? + return value +end + -- init the config function config.init() diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 99f48ace02b..940cdb4723f 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -109,6 +109,13 @@ function sandbox_core_project_config.save(targetname) end end +-- read the value from the configure file directly +function sandbox_core_project_config.read(name, targetname) + + -- read it + return config.read(name, targetname) +end + -- the configure has been changed for the given target? function sandbox_core_project_config.changed(targetname)