summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2019-04-20 00:47:48 +0800
committerruki <[email protected]>2019-04-19 22:46:48 +0800
commitb835afb346d35a898d457fdb837cb40529ccf26c (patch)
tree9a642814d5b522f057423a445dda3946cbe99e69
parent15f2387b83a470f0d01e79613ac4a90cfc25e8ea (diff)
improve the build envs
-rw-r--r--xmake/core/package/package.lua46
1 files changed, 27 insertions, 19 deletions
diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua
index c7dfe761c..b08e23ecb 100644
--- a/xmake/core/package/package.lua
+++ b/xmake/core/package/package.lua
@@ -393,45 +393,53 @@ end
-- get the given build environment variable
function _instance:build_getenv(name)
- return self:build_envs()[name]
+ return self:build_envs(true)[name]
end
-- set the given build environment variable
function _instance:build_setenv(name, ...)
- self:build_envs()[name] = table.unwrap({...})
+ self:build_envs(true)[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]), ...))
+ self:build_envs(true)[name] = table.unwrap(table.join(table.wrap(self:build_envs()[name]), ...))
end
-- get the build environments
-function _instance:build_envs()
+function _instance:build_envs(lazy_loading)
local build_envs = self._BUILD_ENVS
if build_envs == nil then
-
- -- get build environments from the project configurations
+ -- lazy loading the given environment value and cache it
build_envs = {}
+ setmetatable(build_envs, { __index = function (tbl, key)
+ local value = config.get(key)
+ if value == nil then
+ value = platform.get(key, self:plat())
+ end
+ if value == nil then
+ value = platform.tool(key, self:plat())
+ end
+ if value ~= nil then
+ rawset(tbl, key, value)
+ return value
+ end
+ return rawget(tbl, key)
+ end})
+
+ -- save build environments
+ self._BUILD_ENVS = build_envs
+ end
+ -- force to load all values if need
+ if not lazy_loading then
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
+ -- we need only index it to force load it's value
+ local value = build_envs[optname]
end
end
-
- -- save build environments
- self._BUILD_ENVS = build_envs
end
return build_envs
end