diff options
| author | ruki <[email protected]> | 2019-04-20 00:43:39 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-04-19 22:21:57 +0800 |
| commit | 15f2387b83a470f0d01e79613ac4a90cfc25e8ea (patch) | |
| tree | 64542a4510a56d0f058e573b6654c3dff67295f8 | |
| parent | 11e80baf5a40fcfb7165a85142791c9a45c83051 (diff) | |
impl build envs
| -rw-r--r-- | xmake/core/package/package.lua | 49 | ||||
| -rw-r--r-- | xmake/core/platform/platform.lua | 4 |
2 files changed, 50 insertions, 3 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 1192bcaa5..c7dfe761c 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -34,7 +34,9 @@ local interpreter = require("base/interpreter") local sandbox = require("sandbox/sandbox") local config = require("project/config") local platform = require("platform/platform") +local platform_menu = require("platform/menu") local language = require("language/language") +local language_menu = require("language/menu") local sandbox = require("sandbox/sandbox") local sandbox_os = require("sandbox/modules/os") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") @@ -389,7 +391,52 @@ function _instance:addenv(name, ...) self:envs()[name] = table.join(self:envs()[name] or {}, ...) end --- get user private data +-- get the given build environment variable +function _instance:build_getenv(name) + return self:build_envs()[name] +end + +-- set the given build environment variable +function _instance:build_setenv(name, ...) + self:build_envs()[name] = table.unwrap({...}) +end + +-- add the given build environment variable +function _instance:build_addenv(name, ...) + self:build_envs()[name] = table.unwrap(table.join(table.wrap(self:build_envs()[name]), ...)) +end + +-- get the build environments +function _instance:build_envs() + local build_envs = self._BUILD_ENVS + if build_envs == nil then + + -- get build environments from the project configurations + build_envs = {} + + for _, opt in ipairs(table.join(language_menu.options("config"), platform_menu.options("config"))) do + local optname = opt[2] + if type(optname) == "string" then + local value = config.get(optname) + if value == nil then + value = platform.get(optname, self:plat()) + end + if value == nil then + value = platform.tool(optname, self:plat()) + end + if value ~= nil then + build_envs[optname] = value + end + end + end + + -- save build environments + self._BUILD_ENVS = build_envs + end + return build_envs +end + +-- get the user private data function _instance:data(name) return self._DATA and self._DATA[name] or nil end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 36c3ca2b3..3d79c52bc 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -308,7 +308,7 @@ end -- -- .e.g cc, cxx, mm, mxx, as, ar, ld, sh, .. -- -function platform.tool(toolkind) +function platform.tool(toolkind, plat) -- attempt to get program from config first local program = config.get(toolkind) @@ -316,7 +316,7 @@ function platform.tool(toolkind) if program == nil then -- get the current platform - local instance, errors = platform.load() + local instance, errors = platform.load(plat) if not instance then os.raise(errors) end |
