Skip to content

Commit d24fcdd

Browse files
committed
fix configure error after host changed
1 parent 33d0208 commit d24fcdd

File tree

3 files changed

+67
-23
lines changed

3 files changed

+67
-23
lines changed

xmake/actions/config/main.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ function _option_filter(name)
3434
return name and name ~= "target" and name ~= "file" and name ~= "project" and name ~= "verbose"
3535
end
3636

37+
-- host changed?
38+
function _host_changed(targetname)
39+
return os.host() ~= config.read("host", targetname)
40+
end
41+
3742
-- need check
3843
function _need_check()
3944

@@ -194,7 +199,7 @@ function main()
194199
end
195200

196201
-- merge the cached configure
197-
if not option.get("clean") then
202+
if not option.get("clean") and not _host_changed(targetname) then
198203
config.load(targetname)
199204
end
200205

xmake/core/project/config.lua

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ function config._file()
3939
return path.join(config.directory(), "xmake.conf")
4040
end
4141

42+
-- load the project configure
43+
function config._load(targetname)
44+
45+
-- check
46+
targetname = targetname or "all"
47+
48+
-- load configure from the file first
49+
local filepath = config._file()
50+
if os.isfile(filepath) then
51+
52+
-- load it
53+
local results, errors = io.load(filepath)
54+
if not results then
55+
return nil, errors
56+
end
57+
58+
-- load the target configure
59+
if results._TARGETS then
60+
return table.wrap(results._TARGETS[targetname])
61+
end
62+
end
63+
64+
-- empty
65+
return {}
66+
end
67+
4268
-- get the current given configure
4369
function config.get(name)
4470

@@ -98,29 +124,16 @@ end
98124
-- load the project configure
99125
function config.load(targetname)
100126

101-
-- check
102-
targetname = targetname or "all"
103-
104-
-- load configure from the file first
105-
local filepath = config._file()
106-
if os.isfile(filepath) then
107-
108-
-- load it
109-
local results, errors = io.load(filepath)
127+
local results, errors = config._load(targetname)
128+
if not results then
129+
utils.error(errors)
130+
return true
131+
end
110132

111-
-- error?
112-
if not results then
113-
utils.error(errors)
114-
return true
115-
end
116-
117-
-- merge the target configure first
118-
if results._TARGETS then
119-
for name, value in pairs(table.wrap(results._TARGETS[targetname])) do
120-
if config.get(name) == nil then
121-
config.set(name, value)
122-
end
123-
end
133+
-- merge the target configure first
134+
for name, value in pairs(results) do
135+
if config.get(name) == nil then
136+
config.set(name, value)
124137
end
125138
end
126139

@@ -161,6 +174,25 @@ function config.save(targetname)
161174
return io.save(config._file(), results)
162175
end
163176

177+
-- read value from the configure file directly
178+
function config.read(name, targetname)
179+
180+
-- load configs
181+
local configs = config._load(targetname)
182+
183+
-- get it
184+
local value = nil
185+
if configs then
186+
value = configs[name]
187+
if type(value) == "string" and value == "auto" then
188+
value = nil
189+
end
190+
end
191+
192+
-- ok?
193+
return value
194+
end
195+
164196
-- init the config
165197
function config.init()
166198

xmake/core/sandbox/modules/import/core/project/config.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ function sandbox_core_project_config.save(targetname)
109109
end
110110
end
111111

112+
-- read the value from the configure file directly
113+
function sandbox_core_project_config.read(name, targetname)
114+
115+
-- read it
116+
return config.read(name, targetname)
117+
end
118+
112119
-- the configure has been changed for the given target?
113120
function sandbox_core_project_config.changed(targetname)
114121

0 commit comments

Comments
 (0)