From d18d20def0ca10fda04bae01381e61895b970a43 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Mar 2026 22:41:51 +0800 Subject: improve install vcpkg package --- .../package/manager/vcpkg/install_package.lua | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index e7c0fa930..c0db41d1b 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.base.json") import("core.base.semver") +import("core.base.utils") import("lib.detect.find_tool") import("package.manager.vcpkg.configurations") @@ -56,9 +57,24 @@ function _install_for_classic(vcpkg, name, opt) table.insert(argv, "--debug") end - -- allow rebuilding packages when features change + -- check if the base package is already installed with different features, + -- if so, prompt user before rebuilding with --recurse -- @see https://github.com/xmake-io/xmake/issues/7388 - table.insert(argv, "--recurse") + local basename = name:gsub("%[.-%]", "") + if basename ~= name then + local listinfo = try { function () + return os.iorunv(vcpkg, {"list", basename .. ":" .. triplet}) + end} + if listinfo and listinfo:trim() ~= "" then + local confirm = utils.confirm({default = true, + description = format("%s:%s is already installed with other features, installing %s will rebuild it and its dependencies, continue?", basename, triplet, name)}) + if confirm then + table.insert(argv, "--recurse") + else + raise("install %s:%s cancelled!", name, triplet) + end + end + end -- install package os.vrunv(vcpkg, argv) -- cgit v1.3.1 From 5375a87440cca2533e6c3919df98c5989dc13723 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Mar 2026 22:42:36 +0800 Subject: remove utils --- xmake/modules/package/manager/vcpkg/install_package.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index c0db41d1b..decbb6faa 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -22,7 +22,6 @@ import("core.base.option") import("core.base.json") import("core.base.semver") -import("core.base.utils") import("lib.detect.find_tool") import("package.manager.vcpkg.configurations") -- cgit v1.3.1 From 273ed3b3183e43520cc8a0b062c51ade88574ce8 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Mar 2026 22:48:44 +0800 Subject: add vcpkg utils --- .../modules/package/manager/vcpkg/find_package.lua | 8 ++-- .../package/manager/vcpkg/install_package.lua | 7 ++-- xmake/modules/package/manager/vcpkg/utils.lua | 46 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 xmake/modules/package/manager/vcpkg/utils.lua diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua index 563521889..39254e6fa 100644 --- a/xmake/modules/package/manager/vcpkg/find_package.lua +++ b/xmake/modules/package/manager/vcpkg/find_package.lua @@ -26,6 +26,7 @@ import("core.project.config") import("core.project.target") import("detect.sdks.find_vcpkgdir") import("package.manager.vcpkg.configurations") +import("package.manager.vcpkg.utils", {alias = "vcpkg_utils"}) import("package.manager.pkgconfig.find_package", {alias = "find_package_from_pkgconfig"}) -- we iterate over each pkgconfig file to extract the required data @@ -131,14 +132,11 @@ function _get_package_info(name, triplet, infodirs, arch, plat, mode) return result end --- check if the required features are installed via `vcpkg list` +-- check if all required features are installed -- @see https://github.com/xmake-io/xmake/issues/7388 function _has_installed_features(vcpkg, name, triplet, required_features) for _, feature in ipairs(required_features) do - local listinfo = try { function () - return os.iorunv(vcpkg, {"list", name .. "[" .. feature .. "]:" .. triplet}) - end} - if not listinfo or listinfo:trim() == "" then + if not vcpkg_utils.is_installed(vcpkg, name .. "[" .. feature .. "]", triplet) then return false end end diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index decbb6faa..055e51e83 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -22,8 +22,10 @@ import("core.base.option") import("core.base.json") import("core.base.semver") +import("core.base.utils") import("lib.detect.find_tool") import("package.manager.vcpkg.configurations") +import("package.manager.vcpkg.utils", {alias = "vcpkg_utils"}) -- need manifest mode? function _need_manifest(opt) @@ -61,10 +63,7 @@ function _install_for_classic(vcpkg, name, opt) -- @see https://github.com/xmake-io/xmake/issues/7388 local basename = name:gsub("%[.-%]", "") if basename ~= name then - local listinfo = try { function () - return os.iorunv(vcpkg, {"list", basename .. ":" .. triplet}) - end} - if listinfo and listinfo:trim() ~= "" then + if vcpkg_utils.is_installed(vcpkg, basename, triplet) then local confirm = utils.confirm({default = true, description = format("%s:%s is already installed with other features, installing %s will rebuild it and its dependencies, continue?", basename, triplet, name)}) if confirm then diff --git a/xmake/modules/package/manager/vcpkg/utils.lua b/xmake/modules/package/manager/vcpkg/utils.lua new file mode 100644 index 000000000..ca1cabcac --- /dev/null +++ b/xmake/modules/package/manager/vcpkg/utils.lua @@ -0,0 +1,46 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, Xmake Open Source Community. +-- +-- @author ruki +-- @file utils.lua +-- + +-- define module +local utils = utils or {} + +-- check if a package (with optional features) is installed for the given triplet +-- e.g. is_installed(vcpkg, "curl", "x64-windows-static-md") +-- is_installed(vcpkg, "curl[mbedtls]", "x64-windows-static-md") +-- +-- @see https://github.com/xmake-io/xmake/issues/7388 +-- +function utils.is_installed(vcpkg, name, triplet) + local listinfo = try { function () + return os.iorunv(vcpkg, {"list", name .. ":" .. triplet, "--x-full-desc"}) + end} + if listinfo then + local exact_prefix = name .. ":" .. triplet + for _, line in ipairs(listinfo:split("\n", {plain = true})) do + if line:startswith(exact_prefix) then + return true + end + end + end + return false +end + +-- return module +return utils -- cgit v1.3.1 From b6592501bdef4db1ae117b6c6a20a8a230e33907 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Mar 2026 22:49:51 +0800 Subject: fix vcpkg utils --- xmake/modules/package/manager/vcpkg/utils.lua | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/xmake/modules/package/manager/vcpkg/utils.lua b/xmake/modules/package/manager/vcpkg/utils.lua index ca1cabcac..9eabe7cee 100644 --- a/xmake/modules/package/manager/vcpkg/utils.lua +++ b/xmake/modules/package/manager/vcpkg/utils.lua @@ -18,16 +18,13 @@ -- @file utils.lua -- --- define module -local utils = utils or {} - -- check if a package (with optional features) is installed for the given triplet -- e.g. is_installed(vcpkg, "curl", "x64-windows-static-md") -- is_installed(vcpkg, "curl[mbedtls]", "x64-windows-static-md") -- -- @see https://github.com/xmake-io/xmake/issues/7388 -- -function utils.is_installed(vcpkg, name, triplet) +function is_installed(vcpkg, name, triplet) local listinfo = try { function () return os.iorunv(vcpkg, {"list", name .. ":" .. triplet, "--x-full-desc"}) end} @@ -41,6 +38,3 @@ function utils.is_installed(vcpkg, name, triplet) end return false end - --- return module -return utils -- cgit v1.3.1 From e3f6cfa48dcc66c6f6a7994c442bc8c2be7cf445 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Mar 2026 22:50:37 +0800 Subject: fix vcpkg utils --- xmake/modules/package/manager/vcpkg/utils.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xmake/modules/package/manager/vcpkg/utils.lua b/xmake/modules/package/manager/vcpkg/utils.lua index 9eabe7cee..b7dd7237b 100644 --- a/xmake/modules/package/manager/vcpkg/utils.lua +++ b/xmake/modules/package/manager/vcpkg/utils.lua @@ -31,7 +31,8 @@ function is_installed(vcpkg, name, triplet) if listinfo then local exact_prefix = name .. ":" .. triplet for _, line in ipairs(listinfo:split("\n", {plain = true})) do - if line:startswith(exact_prefix) then + local first = line:split("%s")[1] + if first == exact_prefix then return true end end -- cgit v1.3.1 From 33c48ddc479f6332a4539144e9c1277801e99b85 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Mar 2026 22:50:52 +0800 Subject: fix vcpkg utils --- xmake/modules/package/manager/vcpkg/install_package.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index 055e51e83..7c4141861 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -22,7 +22,6 @@ import("core.base.option") import("core.base.json") import("core.base.semver") -import("core.base.utils") import("lib.detect.find_tool") import("package.manager.vcpkg.configurations") import("package.manager.vcpkg.utils", {alias = "vcpkg_utils"}) -- cgit v1.3.1 From 17442f8fa917430ccc95fb4cb0993ba64a06beb7 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Mar 2026 22:51:24 +0800 Subject: improve vcpkg utils --- xmake/modules/package/manager/vcpkg/find_package.lua | 13 +------------ xmake/modules/package/manager/vcpkg/utils.lua | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua index 39254e6fa..7cc6af548 100644 --- a/xmake/modules/package/manager/vcpkg/find_package.lua +++ b/xmake/modules/package/manager/vcpkg/find_package.lua @@ -132,17 +132,6 @@ function _get_package_info(name, triplet, infodirs, arch, plat, mode) return result end --- check if all required features are installed --- @see https://github.com/xmake-io/xmake/issues/7388 -function _has_installed_features(vcpkg, name, triplet, required_features) - for _, feature in ipairs(required_features) do - if not vcpkg_utils.is_installed(vcpkg, name .. "[" .. feature .. "]", triplet) then - return false - end - end - return true -end - function _find_package(vcpkg, vcpkgdir, name, opt) -- get configs @@ -182,7 +171,7 @@ function _find_package(vcpkg, vcpkgdir, name, opt) -- check that required features are installed -- @see https://github.com/xmake-io/xmake/issues/7388 - if required_features and not _has_installed_features(vcpkg, name, triplet, required_features) then + if required_features and not vcpkg_utils.has_installed_features(vcpkg, name, triplet, required_features) then return end diff --git a/xmake/modules/package/manager/vcpkg/utils.lua b/xmake/modules/package/manager/vcpkg/utils.lua index b7dd7237b..da321cda0 100644 --- a/xmake/modules/package/manager/vcpkg/utils.lua +++ b/xmake/modules/package/manager/vcpkg/utils.lua @@ -39,3 +39,17 @@ function is_installed(vcpkg, name, triplet) end return false end + +-- check if all required features are installed +-- e.g. has_installed_features(vcpkg, "curl", "x64-windows-static-md", {"openssl", "mbedtls"}) +-- +-- @see https://github.com/xmake-io/xmake/issues/7388 +-- +function has_installed_features(vcpkg, name, triplet, required_features) + for _, feature in ipairs(required_features) do + if not is_installed(vcpkg, name .. "[" .. feature .. "]", triplet) then + return false + end + end + return true +end -- cgit v1.3.1 From 737959ac2cb795665ccae272997cd0c85d9d5199 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 13 Mar 2026 22:52:05 +0800 Subject: improve vcpkg check --- xmake/modules/package/manager/vcpkg/install_package.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index 7c4141861..2c2c520f3 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -62,13 +62,15 @@ function _install_for_classic(vcpkg, name, opt) -- @see https://github.com/xmake-io/xmake/issues/7388 local basename = name:gsub("%[.-%]", "") if basename ~= name then - if vcpkg_utils.is_installed(vcpkg, basename, triplet) then - local confirm = utils.confirm({default = true, - description = format("%s:%s is already installed with other features, installing %s will rebuild it and its dependencies, continue?", basename, triplet, name)}) - if confirm then - table.insert(argv, "--recurse") - else - raise("install %s:%s cancelled!", name, triplet) + if not vcpkg_utils.is_installed(vcpkg, name, triplet) then + if vcpkg_utils.is_installed(vcpkg, basename, triplet) then + local confirm = utils.confirm({default = true, + description = format("%s:%s is already installed (possibly with different features). Installing %s will require a rebuild of it and its dependencies. Continue?", basename, triplet, name)}) + if confirm then + table.insert(argv, "--recurse") + else + raise("install %s:%s cancelled!", name, triplet) + end end end end -- cgit v1.3.1