diff options
| author | ruki <[email protected]> | 2018-12-07 00:54:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2018-12-06 23:24:51 +0800 |
| commit | b4f35402ca2a97708dc46f6e48d60a3f5bf02f5e (patch) | |
| tree | 2295e9ccea8377ea90b9407edce14bdb443e9970 | |
| parent | b03855d7dbc88bc38c07d7b62ea73de0dbbef9f6 (diff) | |
improve set_config
| -rw-r--r-- | xmake/actions/config/main.lua | 9 | ||||
| -rw-r--r-- | xmake/core/base/interpreter.lua | 33 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 18 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_ndk.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/detect/sdks/find_xcode.lua | 2 |
5 files changed, 41 insertions, 23 deletions
diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 57d2e5043..cab2dc2d7 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -242,6 +242,15 @@ function main() end end + -- merge the project options after default options + for name, value in pairs(project.get("config")) do + value = table.unwrap(value) + assert(type(value) == "string", "set_config(%s): too much values", name) + if not config.readonly(name) then + config.set(name, value) + end + end + -- merge the checked configure local recheck = _need_check(options_changed or not configcache) if recheck then diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 0f5f60ebf..9c2d35450 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -1066,6 +1066,11 @@ end -- set_$(name1)("key", "value1") -- set_$(name2)("key", "value1", "value2", ...) -- +-- get: +-- +-- get("name") => {key => values} +-- get("name.key") => values +-- function interpreter:api_register_set_keyvalues(scope_kind, ...) -- define implementation @@ -1080,14 +1085,18 @@ function interpreter:api_register_set_keyvalues(scope_kind, ...) extra_config = nil end - -- save values - name = name .. "." .. key - scope[name] = values + -- save values to "name" + scope[name] = scope[name] or {} + scope[name][key] = values + + -- save values to "name.key" + local name_key = name .. "." .. key + scope[name_key] = values -- save extra config if extra_config then - scope["__extra_" .. name] = scope["__extra_" .. name] or {} - local extrascope = scope["__extra_" .. name] + scope["__extra_" .. name_key] = scope["__extra_" .. name_key] or {} + local extrascope = scope["__extra_" .. name_key] for _, value in ipairs(values) do extrascope[value] = extra_config end @@ -1116,14 +1125,18 @@ function interpreter:api_register_add_keyvalues(scope_kind, ...) extra_config = nil end - -- save values - name = name .. "." .. key - scope[name] = table.join2(scope[name] or {}, values) + -- save values to "name" + scope[name] = scope[name] or {} + scope[name][key] = table.join2(scope[name][key] or {}, values) + + -- save values to "name.key" + local name_key = name .. "." .. key + scope[name_key] = scope[name][key] -- save extra config if extra_config then - scope["__extra_" .. name] = scope["__extra_" .. name] or {} - local extrascope = scope["__extra_" .. name] + scope["__extra_" .. name_key] = scope["__extra_" .. name_key] or {} + local extrascope = scope["__extra_" .. name_key] for _, value in ipairs(values) do extrascope[value] = extra_config end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index c05884590..c9eb33fd9 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -123,13 +123,6 @@ function project._api_has_package(interp, ...) end end --- set config from the given name -function project._api_set_config(interp, name, value) - if not config.readonly(name) then - config.set(name, value) - end -end - -- get config from the given name function project._api_get_config(interp, name) return config.get(name) @@ -217,6 +210,10 @@ function project.interpreter() , "add_requires" , "add_repositories" } + , keyvalues = + { + "set_config" + } , custom = { -- is_xxx @@ -227,8 +224,6 @@ function project.interpreter() , {"is_plat", project._api_is_plat } , {"is_arch", project._api_is_arch } , {"is_config", project._api_is_config } - -- set_xxx - , {"set_config", project._api_set_config } -- get_xxx , {"get_config", project._api_get_config } -- has_xxx @@ -308,8 +303,6 @@ function project.get(name) -- load the global project infos local infos = project._INFOS if not infos then - - -- load infos infos = project._load_scope(nil, true, true) project._INFOS = infos end @@ -509,6 +502,9 @@ end -- load requires function project._load_requires() + -- @note clear the previous cache and reload root configs when call project.get() + project._INFOS = nil + -- parse requires local requires = {} local requires_extra = project.get("__extra_requires") or {} diff --git a/xmake/modules/detect/sdks/find_ndk.lua b/xmake/modules/detect/sdks/find_ndk.lua index 130ad220a..13909e2ce 100644 --- a/xmake/modules/detect/sdks/find_ndk.lua +++ b/xmake/modules/detect/sdks/find_ndk.lua @@ -153,7 +153,7 @@ function main(sdkdir, opt) -- find ndk local ndk = _find_ndk(sdkdir or config.get("ndk") or global.get("ndk"), arch, opt.sdkver or config.get("ndk_sdkver"), opt.toolchains_ver or config.get("ndk_toolchains_ver")) - if ndk then + if ndk and ndk.sdkdir then -- save to config config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua index bf1e4f873..0a71f0d84 100644 --- a/xmake/modules/detect/sdks/find_xcode.lua +++ b/xmake/modules/detect/sdks/find_xcode.lua @@ -118,7 +118,7 @@ function main(sdkdir, opt) -- find xcode local xcode = _find_vscode(sdkdir or config.get("xcode") or global.get("xcode"), opt.sdkver or config.get("xcode_sdkver"), plat, arch) - if xcode then + if xcode and xcode.sdkdir then -- save to config config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) |
