diff options
| author | ruki <[email protected]> | 2017-09-18 22:54:13 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-18 11:25:24 +0800 |
| commit | 8f55f2e39ae47b7e9bc206d5ddf62a99d25c9d0f (patch) | |
| tree | 18ddc8e1a86fe0c8123be6924ab1d02d1013e177 /xmake/core/project/target.lua | |
| parent | 9e730f52fd7a2dfecefc88ca620db855d6aa668b (diff) | |
add add_imports to bulk import modules
Diffstat (limited to 'xmake/core/project/target.lua')
| -rw-r--r-- | xmake/core/project/target.lua | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index f2c12bbd2..99649216a 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -26,18 +26,20 @@ local target = target or {} -- load modules -local os = require("base/os") -local path = require("base/path") -local utils = require("base/utils") -local table = require("base/table") -local deprecated = require("base/deprecated") -local option = require("project/option") -local config = require("project/config") -local tool = require("tool/tool") -local linker = require("tool/linker") -local compiler = require("tool/compiler") -local platform = require("platform/platform") -local language = require("language/language") +local os = require("base/os") +local path = require("base/path") +local utils = require("base/utils") +local table = require("base/table") +local deprecated = require("base/deprecated") +local option = require("project/option") +local config = require("project/config") +local tool = require("tool/tool") +local linker = require("tool/linker") +local compiler = require("tool/compiler") +local platform = require("platform/platform") +local language = require("language/language") +local sandbox = require("sandbox/sandbox") +local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- get the filename from the given target name and kind function target.filename(targetname, targetkind, targetformat) @@ -694,8 +696,9 @@ function target:script(name, generic) -- get script local script = self:get(name) + local result = nil if type(script) == "function" then - return script + result = script elseif type(script) == "table" then -- match script for special plat and arch @@ -703,23 +706,40 @@ function target:script(name, generic) local pattern = plat .. '|' .. (config.get("arch") or "") for _pattern, _script in pairs(script) do if not _pattern:startswith("__") and pattern:find('^' .. _pattern .. '$') then - return _script + result = _script + break end end -- match script for special plat - for _pattern, _script in pairs(script) do - if not _pattern:startswith("__") and plat:find('^' .. _pattern .. '$') then - return _script + if result == nil then + for _pattern, _script in pairs(script) do + if not _pattern:startswith("__") and plat:find('^' .. _pattern .. '$') then + result = _script + break + end end end -- get generic script - return script["__generic__"] or generic + result = result or script["__generic__"] or generic end -- only generic script - return generic + result = result or generic + + -- imports some modules first + if result then + local scope = getfenv(result) + if scope then + for _, modulename in ipairs(table.wrap(self:get("imports"))) do + scope[sandbox_module.name(modulename)] = sandbox_module.import(modulename, {anonymous = true}) + end + end + end + + -- ok + return result end -- get the config header prefix |
