summaryrefslogtreecommitdiff
path: root/xmake/modules/private/action/require/impl/package.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-04-15 00:44:18 +0800
committerruki <[email protected]>2021-04-15 00:44:18 +0800
commite2f886e49eb5d6047410e9990db77dadb6984b9d (patch)
treea4f134a9aa462b1cf22a9702d6d7fb99ab35bae6 /xmake/modules/private/action/require/impl/package.lua
parentdaba45f8fe5736f18b1af82c9bca2da7c2835da8 (diff)
improve export packages
Diffstat (limited to 'xmake/modules/private/action/require/impl/package.lua')
-rw-r--r--xmake/modules/private/action/require/impl/package.lua101
1 files changed, 75 insertions, 26 deletions
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index 72ea3807a..fa11d4fc5 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -605,32 +605,6 @@ function _load_package(packagename, requireinfo, opt)
return package
end
--- this package should be install?
-function should_install(package)
- if package:exists() then
- return false
- end
- -- we need not install it if this package need only be fetched
- if package:is_fetchonly() then
- return false
- end
- -- only get system package? e.g. add_requires("xxx", {system = true})
- local requireinfo = package:requireinfo()
- if requireinfo and requireinfo.system then
- return false
- end
- if package:parents() then
- -- if all the packages that depend on it already exist, then there is no need to install it
- for _, parent in pairs(package:parents()) do
- if should_install(parent) and not parent:exists() then
- return true
- end
- end
- else
- return true
- end
-end
-
-- load all required packages
function _load_packages(requires, opt)
@@ -687,6 +661,81 @@ function cachedir()
return path.join(global.directory(), "cache", "packages")
end
+-- this package should be install?
+function should_install(package)
+ if package:exists() then
+ return false
+ end
+ -- we need not install it if this package need only be fetched
+ if package:is_fetchonly() then
+ return false
+ end
+ -- only get system package? e.g. add_requires("xxx", {system = true})
+ local requireinfo = package:requireinfo()
+ if requireinfo and requireinfo.system then
+ return false
+ end
+ if package:parents() then
+ -- if all the packages that depend on it already exist, then there is no need to install it
+ for _, parent in pairs(package:parents()) do
+ if should_install(parent) and not parent:exists() then
+ return true
+ end
+ end
+ else
+ return true
+ end
+end
+
+-- get package parents string
+function _get_parents_str(package)
+ local parents = package:parents()
+ if parents then
+ local parentnames = {}
+ for _, parent in pairs(parents) do
+ table.insert(parentnames, parent:displayname())
+ end
+ if #parentnames == 0 then
+ return
+ end
+ return table.concat(parentnames, ",")
+ end
+end
+
+-- get package configs string
+function get_configs_str(package)
+ local configs = {}
+ if package:is_optional() then
+ table.insert(configs, "optional")
+ end
+ local requireinfo = package:requireinfo()
+ if requireinfo then
+ if requireinfo.plat then
+ table.insert(configs, requireinfo.plat)
+ end
+ if requireinfo.arch then
+ table.insert(configs, requireinfo.arch)
+ end
+ for k, v in pairs(requireinfo.configs) do
+ if type(v) == "boolean" then
+ table.insert(configs, k .. ":" .. (v and "y" or "n"))
+ else
+ table.insert(configs, k .. ":" .. v)
+ end
+ end
+ end
+ local parents_str = _get_parents_str(package)
+ if parents_str then
+ table.insert(configs, "from:" .. parents_str)
+ end
+ local configs_str = #configs > 0 and "[" .. table.concat(configs, ", ") .. "]" or ""
+ local limitwidth = os.getwinsize().width * 2 / 3
+ if #configs_str > limitwidth then
+ configs_str = configs_str:sub(1, limitwidth) .. " ..)"
+ end
+ return configs_str
+end
+
-- load requires
function load_requires(requires, requires_extra, opt)
opt = opt or {}