summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-07-19 21:12:51 +0800
committerruki <[email protected]>2017-07-19 21:12:51 +0800
commit1ea7269e5078041df9c170b020953273ea176675 (patch)
treecade92c9dd13d9bc69f62007d5f41f717c4124ff
parent2b52ec7d069e2a5b297b52f6696f70f3d53ff385 (diff)
fix config and add readonly mode
-rw-r--r--xmake/actions/config/main.lua41
-rw-r--r--xmake/actions/global/main.lua18
-rw-r--r--xmake/core/base/global.lua42
-rw-r--r--xmake/core/project/config.lua33
-rw-r--r--xmake/core/project/option.lua6
-rw-r--r--xmake/core/sandbox/modules/import/core/base/global.lua9
-rw-r--r--xmake/core/sandbox/modules/import/core/project/config.lua9
7 files changed, 94 insertions, 64 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua
index 835eb4845..90af3209d 100644
--- a/xmake/actions/config/main.lua
+++ b/xmake/actions/config/main.lua
@@ -55,14 +55,11 @@ function _host_changed(targetname)
end
-- need check
-function _need_check(override)
+function _need_check(changed)
-- clean?
- local changed = option.get("clean")
-
- -- the configure has been changed? reconfig it
- if not changed and override then
- changed = true
+ if not changed then
+ changed = option.get("clean")
end
-- get the current mtimes
@@ -177,6 +174,9 @@ function main()
-- the target name
local targetname = option.get("target") or "all"
+ -- enter cache scope
+ cache.enter("local.config")
+
-- load global configure
global.load()
@@ -184,16 +184,11 @@ function main()
--
-- priority: option > option_cache > global > option_default > config_check > project_check > config_cache
--
- local override = false
- if not option.get("clean") then
- if not config.load() then
- override = true
- end
+ local configcache = false
+ if not option.get("clean") and not _host_changed(targetname) then
+ configcache = config.load(targetname)
end
- -- enter cache scope
- cache.enter("local.config")
-
-- get the options
local options = nil
for name, value in pairs(option.options()) do
@@ -204,14 +199,17 @@ function main()
end
-- override configure from the options or cache
+ local changed = false
if not option.get("clean") then
options = options or cache.get("options_" .. targetname)
end
for name, value in pairs(options) do
- if config.get(name) ~= value then
- config.set(name, value)
- override = true
- end
+
+ -- the config value is changed by argument options?
+ changed = changed or config.get(name) ~= value
+
+ -- @note override it and mark as readonly
+ config.set(name, value, true)
end
-- merge the global configure
@@ -229,7 +227,7 @@ function main()
end
-- merge the checked configure
- local recheck = _need_check(override)
+ local recheck = _need_check(changed or not configcache)
if recheck then
-- check configure
@@ -245,11 +243,6 @@ function main()
detectcache.clear()
end
- -- merge the cached configure
- if not option.get("clean") and not _host_changed(targetname) then
- config.load(targetname)
- end
-
-- load platform
platform.load(config.plat())
diff --git a/xmake/actions/global/main.lua b/xmake/actions/global/main.lua
index 412e0fe6e..de3d9ea51 100644
--- a/xmake/actions/global/main.lua
+++ b/xmake/actions/global/main.lua
@@ -33,20 +33,20 @@ function main()
--
-- priority: option > option_default > config_check > global_cache
--
- local override = false
+ local configcache = false
if not option.get("clean") then
- if not global.load() then
- override = true
- end
+ configcache = global.load()
end
-- override the option configure
+ local changed = false
for name, value in pairs(option.options()) do
if name ~= "verbose" then
- if global.get(name) ~= value then
- global.set(name, value)
- override = true
- end
+ -- the config value is changed by argument options?
+ changed = changed or global.get(name) ~= value
+
+ -- @note override it and mark as readonly
+ global.set(name, value, true)
end
end
@@ -58,7 +58,7 @@ function main()
end
-- check the global configure
- if override then
+ if changed or not configcache then
global.check()
end
diff --git a/xmake/core/base/global.lua b/xmake/core/base/global.lua
index 3bf93bde7..823603722 100644
--- a/xmake/core/base/global.lua
+++ b/xmake/core/base/global.lua
@@ -37,31 +37,45 @@ function global._file()
return path.join(global.directory(), "xmake.conf")
end
--- get the current given configure from
+-- get the current given configure
function global.get(name)
- -- get configs
- local configs = global._CONFIGS or {}
-
- -- the value
- local value = configs[name]
- if type(value) == "string" and value == "auto" then
- value = nil
+ -- get it
+ local value = nil
+ if global._CONFIGS then
+ value = global._CONFIGS[name]
+ if type(value) == "string" and value == "auto" then
+ value = nil
+ end
end
-- get it
return value
end
--- set the current given configure
-function global.set(name, value)
+-- this global name is readonly?
+function global.readonly(name)
+ return global._MODES and global._MODES["__readonly_" .. name]
+end
+
+-- set the given configure to the current
+function global.set(name, value, readonly)
- -- get configs
- local configs = global._CONFIGS or {}
- global._CONFIGS = configs
+ -- check
+ assert(name)
+
+ -- check readonly
+ assert(not global.readonly(name), "cannot set readonly global: " .. name)
-- set it
- configs[name] = value
+ global._CONFIGS = global._CONFIGS or {}
+ global._CONFIGS[name] = value
+
+ -- mark as readonly
+ if readonly then
+ global._MODES = global._MODES or {}
+ global._MODES["__readonly_" .. name] = true
+ end
end
-- get all options
diff --git a/xmake/core/project/config.lua b/xmake/core/project/config.lua
index 643665173..1fa1ac856 100644
--- a/xmake/core/project/config.lua
+++ b/xmake/core/project/config.lua
@@ -67,31 +67,42 @@ end
-- get the current given configure
function config.get(name)
- -- get configs
- local configs = config._CONFIGS or {}
-
-- get it
- local value = configs[name]
- if type(value) == "string" and value == "auto" then
- value = nil
+ local value = nil
+ if config._CONFIGS then
+ value = config._CONFIGS[name]
+ if type(value) == "string" and value == "auto" then
+ value = nil
+ end
end
-- get it
return value
end
+-- this config name is readonly?
+function config.readonly(name)
+ return config._MODES and config._MODES["__readonly_" .. name]
+end
+
-- set the given configure to the current
-function config.set(name, value)
+function config.set(name, value, readonly)
-- check
assert(name)
- -- get configs
- local configs = config._CONFIGS or {}
- config._CONFIGS = configs
+ -- check readonly
+ assert(not config.readonly(name), "cannot set readonly config: " .. name)
-- set it
- configs[name] = value
+ config._CONFIGS = config._CONFIGS or {}
+ config._CONFIGS[name] = value
+
+ -- mark as readonly
+ if readonly then
+ config._MODES = config._MODES or {}
+ config._MODES["__readonly_" .. name] = true
+ end
end
-- get all options
diff --git a/xmake/core/project/option.lua b/xmake/core/project/option.lua
index 0400fd1d3..d8e347ca9 100644
--- a/xmake/core/project/option.lua
+++ b/xmake/core/project/option.lua
@@ -245,10 +245,12 @@ end
function option:enable(enabled)
-- enable or disable this option?
- config.set(self:name(), enabled)
+ if not config.readonly(self:name()) then
+ config.set(self:name(), enabled)
+ end
-- save or clear this option in cache
- if enabled then
+ if self:enabled() then
self:_save()
else
self:_clear()
diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua
index 377f3384b..65d72b26d 100644
--- a/xmake/core/sandbox/modules/import/core/base/global.lua
+++ b/xmake/core/sandbox/modules/import/core/base/global.lua
@@ -37,8 +37,13 @@ function sandbox_core_base_global.get(name)
end
-- set the configure
-function sandbox_core_base_global.set(name, value)
- global.set(name, value)
+function sandbox_core_base_global.set(name, value, readonly)
+ global.set(name, value, readonly)
+end
+
+-- this config name is readonly?
+function sandbox_core_base_global.readonly(name)
+ return config.readonly(name)
end
-- dump the configure
diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua
index 3bf6d1e62..2a4e8261e 100644
--- a/xmake/core/sandbox/modules/import/core/project/config.lua
+++ b/xmake/core/sandbox/modules/import/core/project/config.lua
@@ -72,8 +72,13 @@ function sandbox_core_project_config.get(name)
end
-- set the given configure to the current
-function sandbox_core_project_config.set(name, value)
- return config.set(name, value)
+function sandbox_core_project_config.set(name, value, readonly)
+ return config.set(name, value, readonly)
+end
+
+-- this config name is readonly?
+function sandbox_core_project_config.readonly(name)
+ return config.readonly(name)
end
-- load the configure