diff options
| author | ruki <[email protected]> | 2026-01-11 08:47:37 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-01-11 08:47:37 +0800 |
| commit | 458849b4ffa70fe12d9cbb17ceb4250502e50784 (patch) | |
| tree | 392749ced1e5988e68e3453ec66988056277904e /xmake/modules | |
| parent | fedbf62b7e11abac537157b3174e5dfd82333f47 (diff) | |
| parent | b84340552514434dbd213354a98a653bdd7d0d60 (diff) | |
Merge pull request #7189 from xmake-io/scheme
Add package schemes
Diffstat (limited to 'xmake/modules')
4 files changed, 115 insertions, 75 deletions
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua index d7310149a..676bd8be5 100644 --- a/xmake/modules/private/action/require/impl/actions/install.lua +++ b/xmake/modules/private/action/require/impl/actions/install.lua @@ -420,21 +420,29 @@ function _enable_ccache(package) end end +function _get_package_tipname(package) + local package_tipname = package:displayname() + local current_scheme = package:current_scheme() + if package:version_str() then + package_tipname = package_tipname .. " " .. package:version_str() + end + if current_scheme and not current_scheme:is_default() then + local scheme_name = current_scheme:name() + if current_scheme:is_precompiled() then + scheme_name = "precompiled" + end + package_tipname = package_tipname .. " ${dim}(" .. scheme_name .. ")${clear}" + end + return package_tipname +end function main(package) - - -- enter working directory local oldir = _enter_workdir(package) - -- init tipname - local tipname = package:name() - if package:version_str() then - tipname = tipname .. "-" .. package:version_str() - end - -- install it local ok = true local oldenvs = os.getenvs() + local package_tipname = _get_package_tipname(package) try { function () @@ -498,7 +506,7 @@ function main(package) if option.get("verbose") or option.get("diagnosis") then print(fetchinfo) end - assert(fetchinfo, "fetch %s failed!", tipname) + assert(fetchinfo, "fetch %s failed!", package_tipname) -- this package is installed now if installed_now then @@ -520,7 +528,7 @@ function main(package) -- trace tty.erase_line_to_start().cr() - cprint("${yellow} => ${clear}install %s %s .. ${color.success}${text.success}", package:displayname(), package:version_str() or "") + cprint("${yellow} => ${clear}install %s .. ${color.success}${text.success}", package_tipname) end, catch @@ -539,7 +547,7 @@ function main(package) -- trace tty.erase_line_to_start().cr() - cprint("${yellow} => ${clear}install %s %s .. ${color.failure}${text.failure}", package:displayname(), package:version_str() or "") + cprint("${yellow} => ${clear}install %s .. ${color.failure}${text.failure}", package_tipname) -- leave the package environments os.setenvs(oldenvs) @@ -555,8 +563,11 @@ function main(package) end os.tryrm(installdir) - -- is precompiled package? we can fallback to source package and try reinstall it again - if package:is_precompiled() then + -- is not last scheme? we can fallback to next scheme and try reinstall it again + local current_scheme = package:current_scheme() + local schemes_orderlist = package:schemes_orderlist() + local last_scheme = schemes_orderlist[#schemes_orderlist] + if current_scheme ~= last_scheme then ok = false else -- failed diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index 39d7d0bd4..359f9ac47 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -495,25 +495,26 @@ function _do_install_packages(packages_install, packages_download, installdeps) packages_in_group[group] = 0 end - -- download this package first - local downloaded = true - if packages_download[tostring(instance)] then - packages_downloading[index] = instance - action_check(instance) - downloaded = action_download(instance) - packages_downloading[index] = nil - end + -- install package from the multiple schemes + for _, scheme in ipairs(instance:schemes_orderlist()) do + instance:prepare_install_scheme(scheme) - -- install this package - packages_installing[index] = instance - if downloaded then - if not action_install(instance) then - assert(instance:is_precompiled(), "package(%s) should be precompiled", instance:name()) - -- we need to disable built and re-download and re-install it - instance:fallback_build() + -- download this package first + local downloaded = true + if packages_download[tostring(instance)] then + packages_downloading[index] = instance + packages_installing[index] = nil action_check(instance) - action_download(instance) - action_install(instance) + downloaded = action_download(instance) + packages_downloading[index] = nil + end + + packages_installing[index] = instance + if downloaded then + if action_install(instance) then + -- install ok + break + end end end diff --git a/xmake/modules/private/action/require/impl/package.lua b/xmake/modules/private/action/require/impl/package.lua index 90efb3751..2d44238db 100644 --- a/xmake/modules/private/action/require/impl/package.lua +++ b/xmake/modules/private/action/require/impl/package.lua @@ -342,24 +342,12 @@ function _add_package_configurations(package) package:add("configs", "shflags", {builtin = true, description = "Set the shared library linker flags."}) end --- select package version -function _select_package_version(package, requireinfo, locked_requireinfo) - - -- get it from the locked requireinfo - if locked_requireinfo then - local version = locked_requireinfo.version - local source = "version" - if locked_requireinfo.branch then - source = "branch" - elseif locked_requireinfo.tag then - source = "tag" - end - return version, source - end +-- select version from scheme +function _select_version_from_scheme(scheme, requireinfo) -- has git url? local has_giturl = false - for _, url in ipairs(package:urls()) do + for _, url in ipairs(scheme:urls()) do if git.checkurl(url) then has_giturl = true break @@ -372,7 +360,7 @@ function _select_package_version(package, requireinfo, locked_requireinfo) local require_version = requireinfo.version local require_verify = requireinfo.verify local is_system = requireinfo.system - local has_versionlist = package:get("versions") or package:get("versionfiles") + local has_versionlist = scheme:get("versions") or scheme:get("versionfiles") if (not has_versionlist or require_verify == false) and (semver.is_valid(require_version) or semver.is_valid_range(require_version)) then -- no version list in package() or need not verify sha256sum? try selecting this version directly @@ -382,8 +370,8 @@ function _select_package_version(package, requireinfo, locked_requireinfo) -- https://github.com/xmake-io/xmake/issues/3551 version = require_version source = "version" - elseif #package:versions() > 0 then -- select version? - version, source = try { function () return semver.select(require_version, package:versions()) end } + elseif #scheme:versions() > 0 then -- select version? + version, source = try { function () return semver.select(require_version, scheme:versions()) end } end if not version and has_giturl then -- select branch? if require_version and #require_version == 40 and require_version:match("%w+") then @@ -393,10 +381,53 @@ function _select_package_version(package, requireinfo, locked_requireinfo) end end -- local source package? we use a phony version - if not version and require_version == "latest" and #package:urls() == 0 then + if not version and require_version == "latest" and #scheme:urls() == 0 then version = "latest" source = "version" end + return version, source +end + +-- select package version +function _select_package_version(package, requireinfo, locked_requireinfo) + + -- get it from the locked requireinfo + if locked_requireinfo then + local version = locked_requireinfo.version + local source = "version" + if locked_requireinfo.branch then + source = "branch" + elseif locked_requireinfo.tag then + source = "tag" + end + package:version_set(version, source) + return version, source + end + + -- select version from schemes + local version, source + table.remove_if(package:schemes_orderlist(), function (i, scheme) + local scheme_version, scheme_source = _select_version_from_scheme(scheme, requireinfo) + if scheme_version then + scheme:version_set(scheme_version, scheme_source) + if version then + if scheme_version ~= version then + raise("package(%s): the version lists of schemes are mismatch.\n -> scheme(%s): %s not found!", + package:name(), scheme:name(), version) + end + else + version = scheme_version + source = scheme_source + end + else + -- remove this scheme if version is not matched + package:schemes()[scheme:name()] = nil + -- reset current scheme cache, we need to resolve new current scheme + package:current_scheme_set(nil) + return true + end + end) + if not version and not package:is_thirdparty() and is_system ~= true then raise("package(%s): version(%s) not found!", package:name(), require_version) end @@ -793,7 +824,7 @@ function _select_artifacts(package, artifacts_manifest) artifacts_info = _select_artifacts_for_generic(package, artifacts_manifest) end if artifacts_info then - package:artifacts_set(artifacts_info) + package:use_precompiled_artifacts(artifacts_info) end end @@ -946,7 +977,6 @@ function _load_package(packagename, requireinfo, opt) -- select package version local version, source = _select_package_version(package, requireinfo, locked_requireinfo) if version then - package:version_set(version, source) package:data_set("__locked_requireinfo", locked_requireinfo) end @@ -1025,14 +1055,7 @@ function _load_package(packagename, requireinfo, opt) -- do load package:_load() - -- load all components - for _, component in pairs(package:components()) do - component:_load() - end - - -- load environments from the manifest to enable the environments of on_install() - package:envs_load() - + -- check api check_api(package, {load = true}) -- save this package package to cache diff --git a/xmake/modules/private/action/require/info.lua b/xmake/modules/private/action/require/info.lua index d065388d2..f1be7a01b 100644 --- a/xmake/modules/private/action/require/info.lua +++ b/xmake/modules/private/action/require/info.lua @@ -111,24 +111,29 @@ function main(requires_raw) -- show urls local urls = instance:urls() - if instance:is_precompiled() then - instance:fallback_build() - local urls_raw = instance:urls() - if urls_raw then - urls = table.join(urls, urls_raw) - end - end if urls and #urls > 0 then cprint(" -> ${color.dump.string_quote}urls${clear}:") - for _, url in ipairs(urls) do - print(" -> %s", filter.handle(url, instance)) - if git.asgiturl(url) then - local url_alias = instance:url_alias(url) - cprint(" -> ${yellow}%s", instance:revision(url_alias) or instance:tag() or instance:version_str()) - else - local sourcehash = instance:sourcehash(instance:url_alias(url)) - if sourcehash then - cprint(" -> ${yellow}%s", sourcehash) + local schemes = instance:schemes_orderlist() + if schemes then + for _, scheme in ipairs(schemes) do + if not scheme:is_precompiled() then + local urls = scheme:urls() + if urls and #urls > 0 then + local scheme_name = scheme:is_default() and "default" or scheme:name() + cprint(" -> ${magenta}%s${clear}:", scheme_name) + for _, url in ipairs(urls) do + print(" -> %s", filter.handle(url, instance)) + if git.asgiturl(url) then + local url_alias = scheme:url_alias(url) + cprint(" -> ${yellow}%s", scheme:revision(url_alias) or scheme:tag() or scheme:version_str()) + else + local sourcehash = scheme:sourcehash(scheme:url_alias(url)) + if sourcehash then + cprint(" -> ${yellow}%s", sourcehash) + end + end + end + end end end end |
