summaryrefslogtreecommitdiff
path: root/xmake/modules/private/action/require/impl/package.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-02-13 00:39:27 +0800
committerruki <[email protected]>2021-02-13 00:39:27 +0800
commit5d26d21e31b9ba443208f1f027b5ac8b6cdc44df (patch)
tree94eab07b083797ef561102759679a1893cee0511 /xmake/modules/private/action/require/impl/package.lua
parente66d6878040a80e6512db851750185b8ab35b127 (diff)
split impl.package
Diffstat (limited to 'xmake/modules/private/action/require/impl/package.lua')
-rw-r--r--xmake/modules/private/action/require/impl/package.lua448
1 files changed, 0 insertions, 448 deletions
diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua
index a3d69a982..38a3991b4 100644
--- a/xmake/modules/private/action/require/impl/package.lua
+++ b/xmake/modules/private/action/require/impl/package.lua
@@ -22,19 +22,12 @@
import("core.base.semver")
import("core.base.option")
import("core.base.global")
-import("core.base.hashset")
-import("core.base.scheduler")
-import("core.base.tty")
import("private.async.runjobs")
import("private.utils.progress")
import("core.cache.memcache")
-import("core.cache.localcache")
import("core.project.project")
import("core.package.package", {alias = "core_package"})
-import("actions.install", {alias = "action_install"})
-import("actions.download", {alias = "action_download"})
import("devel.git")
-import("net.fasturl")
import("private.action.require.impl.repository")
-- get memcache
@@ -192,19 +185,6 @@ function _load_package_from_repository(packagename, reponame)
end
end
--- search packages from repositories
-function _search_packages(name)
-
- local packages = {}
- for _, packageinfo in ipairs(repository.searchdirs(name)) do
- local package = core_package.load_from_repository(packageinfo.name, packageinfo.repo, packageinfo.packagedir)
- if package then
- table.insert(packages, package)
- end
- end
- return packages
-end
-
-- sort package deps
--
-- e.g.
@@ -645,297 +625,6 @@ function _load_packages(requires, opt)
return packages
end
--- sort packages urls
-function _sort_packages_urls(packages)
-
- -- add all urls to fasturl and prepare to sort them together
- for _, package in pairs(packages) do
- fasturl.add(package:urls())
- end
-
- -- sort and update urls
- for _, package in pairs(packages) do
- package:urls_set(fasturl.sort(package:urls()))
- end
-end
-
--- get package parents string
-function _get_package_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_package_configs_str(package)
- local configs = {}
- if package:optional() then
- table.insert(configs, "optional")
- end
- local requireinfo = package:requireinfo()
- if requireinfo then
- 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_package_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
-
--- get user confirm
-function _get_confirm(packages)
-
- -- no confirmed packages?
- if #packages == 0 then
- return true
- end
-
- -- get confirm
- local confirm = utils.confirm({default = true, description = function ()
-
- -- get packages for each repositories
- local packages_repo = {}
- local packages_group = {}
- for _, package in ipairs(packages) do
- -- achive packages by repository
- local reponame = package:repo() and package:repo():name() or (package:isSys() and "system" or "")
- if package:is3rd() then
- reponame = package:name():lower():split("::")[1]
- end
- packages_repo[reponame] = packages_repo[reponame] or {}
- table.insert(packages_repo[reponame], package)
-
- -- achive packages by group
- local group = package:group()
- if group then
- packages_group[group] = packages_group[group] or {}
- table.insert(packages_group[group], package)
- end
- end
-
- -- show tips
- cprint("${bright color.warning}note: ${clear}try installing these packages (pass -y to skip confirm)?")
- for reponame, packages in pairs(packages_repo) do
- if reponame ~= "" then
- print("in %s:", reponame)
- end
- local packages_showed = {}
- for _, package in ipairs(packages) do
- if not packages_showed[tostring(package)] then
- local group = package:group()
- if group and packages_group[group] and #packages_group[group] > 1 then
- for idx, package_in_group in ipairs(packages_group[group]) do
- cprint(" ${yellow}%s${clear} %s %s ${dim}%s", idx == 1 and "->" or " or", package_in_group:displayname(), package_in_group:version_str() or "", _get_package_configs_str(package_in_group))
- packages_showed[tostring(package_in_group)] = true
- end
- packages_group[group] = nil
- else
- cprint(" ${yellow}->${clear} %s %s ${dim}%s", package:displayname(), package:version_str() or "", _get_package_configs_str(package))
- packages_showed[tostring(package)] = true
- end
- end
- end
- end
- end})
- return confirm
-end
-
--- install packages
-function _install_packages(packages_install, packages_download)
-
- -- we need hide wait characters if is not a tty
- local show_wait = io.isatty()
-
- -- do install
- local progress_helper = show_wait and progress.new() or nil
- local packages_installing = {}
- local packages_downloading = {}
- local packages_pending = table.copy(packages_install)
- local packages_in_group = {}
- local installing_count = 0
- local parallelize = true
- runjobs("install_packages", function (index)
-
- -- fetch a new package
- local package = nil
- while package == nil and #packages_pending > 0 do
- for idx, pkg in ipairs(packages_pending) do
-
- -- all dependences has been installed? we install it now
- local ready = true
- local dep_not_found = nil
- for _, dep in ipairs(pkg:orderdeps()) do
- if not dep:exists() then
- ready = false
- dep_not_found = dep
- break
- end
- end
- local group = pkg:group()
- if ready and group then
- -- this group has been installed? skip it
- local group_status = packages_in_group[group]
- if group_status == 1 then
- table.remove(packages_pending, idx)
- break
- -- this group is installing? wait it
- elseif group_status == 0 then
- ready = false
- end
- end
-
- -- get a package with the ready status
- if ready then
- package = pkg
- table.remove(packages_pending, idx)
- break
- elseif installing_count == 0 then
- if #packages_pending == 1 and dep_not_found then
- raise("package(%s): cannot be installed, there are dependencies(%s) that cannot be installed!", pkg:displayname(), dep_not_found:displayname())
- elseif #packages_pending == 1 then
- raise("package(%s): cannot be installed!", pkg:displayname())
- end
- end
- end
- if package == nil and #packages_pending > 0 then
- scheduler.co_yield()
- end
- end
- if package then
-
- -- only install the first package in same group
- local group = package:group()
- if not group or not packages_in_group[group] then
-
- -- disable parallelize?
- if not package:parallelize() then
- parallelize = false
- end
- if not parallelize then
- while installing_count > 0 do
- scheduler.co_yield()
- end
- end
- installing_count = installing_count + 1
-
- -- mark this group as 'installing'
- if group then
- packages_in_group[group] = 0
- end
-
- -- download this package first
- local downloaded = true
- if packages_download[tostring(package)] then
- packages_downloading[index] = package
- downloaded = action_download(package)
- packages_downloading[index] = nil
- end
-
- -- install this package
- packages_installing[index] = package
- if downloaded then
- action_install(package)
- end
- packages_installing[index] = nil
-
- -- mark this group as 'installed' or 'failed'
- if group then
- packages_in_group[group] = package:exists() and 1 or -1
- end
-
- -- enable parallelize
- parallelize = true
- installing_count = installing_count - 1
- end
- end
- packages_installing[index] = nil
- packages_downloading[index] = nil
-
- end, {total = #packages_install, comax = (option.get("verbose") or option.get("diagnosis")) and 1 or 4, on_timer = function (running_jobs_indices)
-
- -- do not print progress info if be verbose
- if option.get("verbose") or not show_wait then
- return
- end
-
- -- make installing and downloading packages list
- local installing = {}
- local downloading = {}
- for _, index in ipairs(running_jobs_indices) do
- local package = packages_installing[index]
- if package then
- table.insert(installing, package:displayname())
- end
- local package = packages_downloading[index]
- if package then
- table.insert(downloading, package:displayname())
- end
- end
-
- -- get waitobjs tips
- local tips = nil
- local waitobjs = scheduler.co_group_waitobjs("install_packages")
- if waitobjs:size() > 0 then
- local names = {}
- for _, obj in waitobjs:keys() do
- if obj:otype() == scheduler.OT_PROC then
- table.insert(names, obj:name())
- elseif obj:otype() == scheduler.OT_SOCK then
- table.insert(names, "sock")
- elseif obj:otype() == scheduler.OT_PIPE then
- table.insert(names, "pipe")
- end
- end
- names = table.unique(names)
- if #names > 0 then
- names = table.concat(names, ",")
- if #names > 16 then
- names = names:sub(1, 16) .. ".."
- end
- tips = string.format("(%d/%s)", waitobjs:size(), names)
- end
- end
-
- -- trace
- progress_helper:clear()
- tty.erase_line_to_start().cr()
- cprintf("${yellow} => ")
- if #downloading > 0 then
- cprintf("downloading ${magenta}%s", table.concat(downloading, ", "))
- end
- if #installing > 0 then
- cprintf("%sinstalling ${magenta}%s", #downloading > 0 and ", " or "", table.concat(installing, ", "))
- end
- cprintf(" .. %s", tips and ("${dim}" .. tips .. "${clear} ") or "")
- progress_helper:write()
- end, exit = function(errors)
- if errors then
- tty.erase_line_to_start().cr()
- io.flush()
- end
- end})
-end
-
-- the cache directory
function cachedir()
return path.join(global.directory(), "cache", "packages")
@@ -967,140 +656,3 @@ function load_packages(requires, opt)
return packages
end
--- install packages
-function install_packages(requires, opt)
-
- -- init options
- opt = opt or {}
-
- -- load packages
- local packages = load_packages(requires, opt)
-
- -- fetch packages (with system) from local first
- runjobs("fetch_packages", function (index)
- local package = packages[index]
- if package and (not option.get("force") or (option.get("shallow") and package:parents())) then
- package:envs_enter()
- package:fetch()
- package:envs_leave()
- end
- end, {total = #packages})
-
- -- filter packages
- local packages_install = {}
- local packages_download = {}
- local packages_unsupported = {}
- for _, package in ipairs(packages) do
- if not package:exists() then
- if package:supported() then
- if #package:urls() > 0 then
- packages_download[tostring(package)] = package
- end
- table.insert(packages_install, package)
- elseif not package:optional() then
- table.insert(packages_unsupported, package)
- end
- end
- end
-
- -- exists unsupported packages?
- if #packages_unsupported > 0 then
- -- show tips
- cprint("${bright color.warning}note: ${clear}the following packages are unsupported for $(plat)/$(arch)!")
- for _, package in ipairs(packages_unsupported) do
- print(" -> %s %s", package:displayname(), package:version_str() or "")
- end
- raise()
- end
-
- -- get user confirm
- if not _get_confirm(packages_install) then
- local packages_must = {}
- for _, package in ipairs(packages_install) do
- if not package:optional() then
- table.insert(packages_must, package:displayname())
- end
- end
- if #packages_must > 0 then
- raise("packages(%s): must be installed!", table.concat(packages_must, ", "))
- else
- -- continue other actions
- return
- end
- end
-
- -- sort package urls
- _sort_packages_urls(packages_download)
-
- -- install all required packages from repositories
- _install_packages(packages_install, packages_download)
-
- -- ok
- return packages
-end
-
--- uninstall packages
-function uninstall_packages(requires, opt)
-
- -- init options
- opt = opt or {}
-
- -- do not remove dependent packages
- opt.nodeps = true
-
- -- clear the local cache
- localcache.clear()
-
- -- remove all packages
- local packages = {}
- for _, instance in ipairs(load_packages(requires, opt)) do
- if os.isfile(instance:manifest_file()) then
- table.insert(packages, instance)
- end
- os.tryrm(instance:installdir())
- end
- return packages
-end
-
--- export packages
-function export_packages(requires, opt)
-
- -- init options
- opt = opt or {}
-
- -- get the export directory
- local exportdir = assert(opt.exportdir)
-
- -- export all packages
- local packages = {}
- for _, instance in ipairs(load_packages(requires, opt)) do
-
- -- get the exported name
- local name = instance:name():lower():gsub("::", "_")
- if instance:version_str() then
- name = name .. "_" .. instance:version_str()
- end
- name = name .. "_" .. instance:buildhash()
-
- -- export this package
- if instance:fetch() then
- os.cp(instance:installdir(), path.join(exportdir, name))
- table.insert(packages, instance)
- end
- end
- return packages
-end
-
--- search packages
-function search_packages(names)
-
- -- search all names
- local results = {}
- for _, name in ipairs(names) do
- local packages = _search_packages(name)
- if packages then
- results[name] = packages
- end
- end
- return results
-end