summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2026-03-13 22:48:44 +0800
committerruki <[email protected]>2026-03-13 22:48:44 +0800
commit273ed3b3183e43520cc8a0b062c51ade88574ce8 (patch)
treee2c076c1b93208d3de53377af25d2329215f2cf8
parent5375a87440cca2533e6c3919df98c5989dc13723 (diff)
add vcpkg utils
-rw-r--r--xmake/modules/package/manager/vcpkg/find_package.lua8
-rw-r--r--xmake/modules/package/manager/vcpkg/install_package.lua7
-rw-r--r--xmake/modules/package/manager/vcpkg/utils.lua46
3 files changed, 52 insertions, 9 deletions
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