diff options
| author | ruki <[email protected]> | 2017-08-09 11:02:00 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-08-09 11:02:00 +0800 |
| commit | 467e97b99dc9b16dd3db3a5ad743ea954185d497 (patch) | |
| tree | b97f06286577155b4aa6814ab92cc85458558b43 | |
| parent | 874aae23f8f36de978263e1f295e8c7143025f53 (diff) | |
add extra info for interpreter values and pathes
| -rw-r--r-- | xmake/core/base/interpreter.lua | 47 | ||||
| -rw-r--r-- | xmake/core/base/table.lua | 38 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 27 |
3 files changed, 42 insertions, 70 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index 32d38cf84..28d4994c7 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -320,7 +320,7 @@ function interpreter:_api_register_xxx_script(scope_kind, action, ...) end -- translate api pathes -function interpreter:_api_translate_pathes(...) +function interpreter:_api_translate_pathes(values) -- check assert(self and self._PRIVATE) @@ -335,15 +335,11 @@ function interpreter:_api_translate_pathes(...) -- translate the relative path local results = {} - for _, p in ipairs({...}) do - if type(p) == "string" then - if not p:find("^%s-%$%(.-%)") and not path.is_absolute(p) then - table.insert(results, path.relative(path.absolute(p, curdir), self._PRIVATE._ROOTDIR)) - else - table.insert(results, p) - end + for _, p in ipairs(values) do + assert(type(p) == "string", "invalid path value: " .. tostring(p)) + if not p:find("^%s-%$%(.-%)") and not path.is_absolute(p) then + table.insert(results, path.relative(path.absolute(p, curdir), self._PRIVATE._ROOTDIR)) else - -- @note do not translate non-string value, .e.g set_xxx("/xx/xx/xx", {arg = ""}) table.insert(results, p) end end @@ -1072,7 +1068,12 @@ function interpreter:api_register_set_values(scope_kind, ...) -- define implementation local implementation = function (self, scope, name, ...) - scope[name] = {...} + local values = {...} + if table.is_dictionary(values[#values]) then + scope["__extra_" .. name] = values[#values] -- save extra info + table.remove(values) + end + scope[name] = values end -- register implementation @@ -1087,8 +1088,12 @@ function interpreter:api_register_add_values(scope_kind, ...) -- define implementation local implementation = function (self, scope, name, ...) - scope[name] = scope[name] or {} - table.append(scope[name], ...) + local values = {...} + if table.is_dictionary(values[#values]) then + scope["__extra_" .. name] = table.join2(scope["__extra_" .. name] or {}, values[#values]) -- save extra info + table.remove(values) + end + scope[name] = table.join2(scope[name] or {}, values) end -- register implementation @@ -1256,9 +1261,12 @@ function interpreter:api_register_set_pathes(scope_kind, ...) -- define implementation local implementation = function (self, scope, name, ...) - -- update values? - scope[name] = {} - table.join2(scope[name], self:_api_translate_pathes(...)) + local values = {...} + if table.is_dictionary(values[#values]) then + scope["__extra_" .. name] = values[#values] -- save extra info + table.remove(values) + end + scope[name] = self:_api_translate_pathes(values) end -- register implementation @@ -1274,9 +1282,12 @@ function interpreter:api_register_add_pathes(scope_kind, ...) -- define implementation local implementation = function (self, scope, name, ...) - -- append values? - scope[name] = scope[name] or {} - table.join2(scope[name], self:_api_translate_pathes(...)) + local values = {...} + if table.is_dictionary(values[#values]) then + scope["__extra_" .. name] = table.join2(scope["__extra_" .. name] or {}, values[#values]) -- save extra info + table.remove(values) + end + scope[name] = table.join2(scope[name] or {}, self:_api_translate_pathes(values)) end -- register implementation diff --git a/xmake/core/base/table.lua b/xmake/core/base/table.lua index db06f094f..eb1988cee 100644 --- a/xmake/core/base/table.lua +++ b/xmake/core/base/table.lua @@ -158,43 +158,13 @@ function table.slice(self, first, last, step) end -- is array? -function table.is_array(self) - - -- not table? - if type(self) ~= "table" then - return false - end - - -- is array? - for k, v in pairs(self) do - if type(k) == "number" then - return true - end - break - end - - -- dictionary - return false +function table.is_array(array) + return type(array) == "table" and array[1] ~= nil end -- is dictionary? -function table.is_dictionary(self) - - -- not table? - if type(self) ~= "table" then - return false - end - - -- is dictionary? - for k, v in pairs(self) do - if type(k) == "string" then - return true - end - break - end - - -- array - return false +function table.is_dictionary(dict) + return type(dict) == "table" and dict[1] == nil end -- dump it with the level diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 543b4f51c..0e7c8fbcf 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -669,12 +669,9 @@ function target:configprefix() -- get the config prefix local configprefix = nil - local configheader = self:get("config_header") - if type(configheader) == "table" then - local opt = configheader[2] - if opt then - configprefix = opt.prefix - end + local configheader_extra = self:get("__extra_config_header") + if type(configheader_extra) == "table" then + configprefix = configheader_extra.prefix end if not configprefix then configprefix = self:get("config_h_prefix") or (self:name():upper() .. "_CONFIG") @@ -688,22 +685,16 @@ end function target:configheader(outputdir) -- get config header - local configheader = self:get("config_header") -- set_config_header("/xxx/config.h", {prefix = XX_CONFIG}) - if type(configheader) == "table" then - configheader = configheader[1] - end - if not configheader then - configheader = self:get("config_h") - - -- mark as deprecated - if configheader then - deprecated.add("set_config_header(\"%s\", {prefix = \"...\"})", "set_config_h(\"%s\")", path.relative(configheader, os.projectdir())) - end - end + local configheader = self:get("config_header") or self:get("config_h") if not configheader then return end + -- mark as deprecated + if self:get("config_h") then + deprecated.add("set_config_header(\"%s\", {prefix = \"...\"})", "set_config_h(\"%s\")", path.relative(self:get("config_h"), os.projectdir())) + end + -- get the root directory local rootdir, count = configheader:gsub("|.*$", ""):gsub("%(.*%)$", "") if count == 0 then |
