Skip to content

Commit

Permalink
fix configure error after host changed
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jul 6, 2016
1 parent 33d0208 commit d24fcdd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 23 deletions.
7 changes: 6 additions & 1 deletion xmake/actions/config/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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

Expand Down
76 changes: 54 additions & 22 deletions xmake/core/project/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand Down
7 changes: 7 additions & 0 deletions xmake/core/sandbox/modules/import/core/project/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d24fcdd

Please sign in to comment.