diff options
| author | ruki <[email protected]> | 2022-03-02 23:20:48 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-03-02 23:20:48 +0800 |
| commit | cfdffbc896a2999c594caccfdaa323df16e3950b (patch) | |
| tree | 233d14b1ac1e8c918b0d1e23aa76f87b06e4e69e /xmake/core | |
| parent | 6026401e3bc55e0b5974c0aa18aefe4d7135fe89 (diff) | |
improve table.wrap and unwrap
Diffstat (limited to 'xmake/core')
| -rw-r--r-- | xmake/core/base/interpreter.lua | 28 | ||||
| -rw-r--r-- | xmake/core/base/scopeinfo.lua | 18 | ||||
| -rw-r--r-- | xmake/core/base/table.lua | 2 |
3 files changed, 41 insertions, 7 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 8a4ed906c..a226d3db2 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -1059,8 +1059,18 @@ function interpreter:api_register_set_values(scope_kind, ...) extra_config = nil end - -- expand values - if not extra_config or extra_config.expand ~= false then + -- @note we need mark table value as meta object to avoid wrap/unwrap + -- if these values cannot be expanded, especially when there is only one value + -- + -- e.g. set_shflags({"-Wl,-exported_symbols_list", exportfile}, {force = true, expand = false}) + if extra_config and extra_config.expand == false then + for _, value in ipairs(values) do + if type(value) == "table" then + setmetatable(value, {}) + end + end + else + -- expand values values = table.join(table.unpack(values)) end @@ -1101,8 +1111,18 @@ function interpreter:api_register_add_values(scope_kind, ...) extra_config = nil end - -- expand values - if not extra_config or extra_config.expand ~= false then + -- @note we need mark table value as meta object to avoid wrap/unwrap + -- if these values cannot be expanded, especially when there is only one value + -- + -- e.g. add_shflags({"-Wl,-exported_symbols_list", exportfile}, {force = true, expand = false}) + if extra_config and extra_config.expand == false then + for _, value in ipairs(values) do + if type(value) == "table" then + setmetatable(value, {}) + end + end + else + -- expand values values = table.join(table.unpack(values)) end diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index e3d9a8500..02fb89299 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -113,8 +113,18 @@ function _instance:_api_set_values(name, ...) extra_config = nil end - -- expand values - if not extra_config or extra_config.expand ~= false then + -- @note we need mark table value as meta object to avoid wrap/unwrap + -- if these values cannot be expanded, especially when there is only one value + -- + -- e.g. target:set("shflags", {"-Wl,-exported_symbols_list", exportfile}, {force = true, expand = false}) + if extra_config and extra_config.expand == false then + for _, value in ipairs(values) do + if type(value) == "table" then + setmetatable(value, {}) + end + end + else + -- expand values values = table.join(table.unpack(values)) end @@ -154,6 +164,10 @@ function _instance:_api_add_values(name, ...) extra_config = nil end + -- @note we need mark table value as meta object to avoid wrap/unwrap + -- if these values cannot be expanded, especially when there is only one value + -- + -- e.g. target:add("shflags", {"-Wl,-exported_symbols_list", exportfile}, {force = true, expand = false}) if extra_config and extra_config.expand == false then for _, value in ipairs(values) do if type(value) == "table" then diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index 1c19f588d..73556c9fc 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -310,7 +310,7 @@ end -- unwrap object if be only one function table.unwrap(object) - if type(object) == "table" then + if type(object) == "table" and not getmetatable(object) then if #object == 1 then return object[1] end |
