From 4b139c33e84d6f2261bea3ec07ec889b44cebd96 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Dec 2021 22:59:51 +0800 Subject: add vcpkg tests for manifest --- tests/projects/package/vcpkg_manifest/.gitignore | 8 ++++ tests/projects/package/vcpkg_manifest/src/main.cpp | 9 +++++ tests/projects/package/vcpkg_manifest/xmake.lua | 8 ++++ .../package/manager/vcpkg/install_package.lua | 44 +++++++++++++++------- .../action/require/impl/install_packages.lua | 1 + 5 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 tests/projects/package/vcpkg_manifest/.gitignore create mode 100644 tests/projects/package/vcpkg_manifest/src/main.cpp create mode 100644 tests/projects/package/vcpkg_manifest/xmake.lua diff --git a/tests/projects/package/vcpkg_manifest/.gitignore b/tests/projects/package/vcpkg_manifest/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/package/vcpkg_manifest/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/package/vcpkg_manifest/src/main.cpp b/tests/projects/package/vcpkg_manifest/src/main.cpp new file mode 100644 index 000000000..7c435d251 --- /dev/null +++ b/tests/projects/package/vcpkg_manifest/src/main.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "hello world!" << endl; + return 0; +} diff --git a/tests/projects/package/vcpkg_manifest/xmake.lua b/tests/projects/package/vcpkg_manifest/xmake.lua new file mode 100644 index 000000000..a10ec2347 --- /dev/null +++ b/tests/projects/package/vcpkg_manifest/xmake.lua @@ -0,0 +1,8 @@ +add_requires("vcpkg::zlib 1.2.11", "vcpkg::fmt >=8.0.1") +--add_requires("vcpkg::boost", {alias = "boost", {configs = {}}}) + +target("test") + set_kind("binary") + add_files("src/*.cpp") + add_packages("vcpkg::zlib", "vcpkg::fmt", "boost") + diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index eaf28710e..071eec03b 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -22,20 +22,13 @@ import("core.base.option") import("lib.detect.find_tool") --- install package --- --- @param name the package name, e.g. pcre2, pcre2/libpcre2-8 --- @param opt the options, e.g. {verbose = true} --- --- @return true or false --- -function main(name, opt) +-- need manifest mode? +function _need_manifest(opt) +-- print("_need_manifest", opt) +end - -- attempt to find vcpkg - local vcpkg = find_tool("vcpkg") - if not vcpkg then - raise("vcpkg not found!") - end +-- install for classic mode +function _install_for_classic(vcpkg, name, opt) -- get arch, plat and mode local arch = opt.arch @@ -81,5 +74,28 @@ function main(name, opt) end -- install package - os.vrunv(vcpkg.program, argv) + os.vrunv(vcpkg, argv) +end + +-- install package +-- +-- @param name the package name, e.g. pcre2, pcre2/libpcre2-8 +-- @param opt the options, e.g. {verbose = true} +-- +-- @return true or false +-- +function main(name, opt) + + -- attempt to find vcpkg + local vcpkg = find_tool("vcpkg") + if not vcpkg then + raise("vcpkg not found!") + end + + -- do install + if _need_manifest(opt) then + _install_for_manifest(vcpkg.program, name, opt) + else + _install_for_classic(vcpkg.program, name, opt) + end end diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index f62a0fb52..c1d9b4791 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -285,6 +285,7 @@ function _install_packages(packages_install, packages_download, installdeps) -- fetch a new package local instance = nil while instance == nil and #packages_pending > 0 do + print("packages_pending", #packages_pending) for idx, pkg in ipairs(packages_pending) do -- all dependences has been installed? we install it now -- cgit v1.3.1 From 6447e8ff1bdd11274049997f3f21b1430546e4f0 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Dec 2021 23:09:16 +0800 Subject: impl vcpkg manifest --- tests/projects/package/vcpkg_manifest/xmake.lua | 6 +- .../package/manager/vcpkg/configurations.lua | 48 ++++++++++ .../modules/package/manager/vcpkg/find_package.lua | 22 +---- .../package/manager/vcpkg/install_package.lua | 106 +++++++++++++++++---- .../action/require/impl/install_packages.lua | 1 - 5 files changed, 138 insertions(+), 45 deletions(-) create mode 100644 xmake/modules/package/manager/vcpkg/configurations.lua diff --git a/tests/projects/package/vcpkg_manifest/xmake.lua b/tests/projects/package/vcpkg_manifest/xmake.lua index a10ec2347..d7150718c 100644 --- a/tests/projects/package/vcpkg_manifest/xmake.lua +++ b/tests/projects/package/vcpkg_manifest/xmake.lua @@ -1,8 +1,8 @@ -add_requires("vcpkg::zlib 1.2.11", "vcpkg::fmt >=8.0.1") ---add_requires("vcpkg::boost", {alias = "boost", {configs = {}}}) +--add_requires("vcpkg::zlib 1.2.11", "vcpkg::fmt >=8.0.1") +add_requires("vcpkg::arrow", {configs = {features = {"json"}}}) target("test") set_kind("binary") add_files("src/*.cpp") - add_packages("vcpkg::zlib", "vcpkg::fmt", "boost") + add_packages("vcpkg::zlib", "vcpkg::fmt", "vcpkg::arrow") diff --git a/xmake/modules/package/manager/vcpkg/configurations.lua b/xmake/modules/package/manager/vcpkg/configurations.lua new file mode 100644 index 000000000..9021edff0 --- /dev/null +++ b/xmake/modules/package/manager/vcpkg/configurations.lua @@ -0,0 +1,48 @@ +--!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, TBOOX Open Source Group. +-- +-- @author ruki +-- @file configurations.lua +-- + +-- get architecture for vcpkg +function arch(arch) + local archs = { + x86_64 = "x64", + i386 = "x86", + + -- android: armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mip64 + -- Offers a doc: https://github.com/microsoft/vcpkg/blob/master/docs/users/android.md + ["armeabi-v7a"] = "arm", + ["arm64-v8a"] = "arm64", + + -- ios: arm64 armv7 armv7s i386 + armv7 = "arm", + armv7s = "arm", + arm64 = "arm64", + } + return archs[arch] or arch +end + +-- get configurations +function main() + return { + baseline = {description = "set the builtin baseline."}, + features = {description = "set the features of dependency."}, + default_features = {description = "enables or disables any defaults provided by the dependency.", default = true} + } +end + diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua index 24500cc2a..e84833958 100644 --- a/xmake/modules/package/manager/vcpkg/find_package.lua +++ b/xmake/modules/package/manager/vcpkg/find_package.lua @@ -25,6 +25,7 @@ import("core.base.option") import("core.project.config") import("core.project.target") import("detect.sdks.find_vcpkgdir") +import("package.manager.vcpkg.configurations") -- find package from the vcpkg package manager -- @@ -50,29 +51,10 @@ function main(name, opt) local arch = opt.arch local plat = opt.plat local mode = opt.mode - - -- mapping plat if plat == "macosx" then plat = "osx" end - - -- archs mapping for vcpkg - local archs = { - x86_64 = "x64", - i386 = "x86", - - -- android: armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mip64 - -- Offers a doc: https://github.com/microsoft/vcpkg/blob/master/docs/users/android.md - ["armeabi-v7a"] = "arm", - ["arm64-v8a"] = "arm64", - - -- ios: arm64 armv7 armv7s i386 - armv7 = "arm", - armv7s = "arm", - arm64 = "arm64", - } - -- mapping arch - arch = archs[arch] or arch + arch = configurations.arch(arch) -- get the vcpkg installed directory local installdir = path.join(vcpkgdir, "installed") diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index 071eec03b..de707d0d1 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -20,11 +20,21 @@ -- imports import("core.base.option") +import("core.base.json") +import("core.base.semver") import("lib.detect.find_tool") +import("package.manager.vcpkg.configurations") -- need manifest mode? function _need_manifest(opt) --- print("_need_manifest", opt) + local require_version = opt.require_version + if require_version ~= nil and require_version ~= "latest" then + return true + end + local configs = opt.configs + if configs and (configs.features or configs.default_features or configs.baseline) then + return true + end end -- install for classic mode @@ -34,29 +44,10 @@ function _install_for_classic(vcpkg, name, opt) local arch = opt.arch local plat = opt.plat local mode = opt.mode - - -- mapping plat if plat == "macosx" then plat = "osx" end - - -- archs mapping for vcpkg - local archs = { - x86_64 = "x64", - i386 = "x86", - - -- android: armeabi armeabi-v7a arm64-v8a x86 x86_64 mips mip64 - -- Offers a doc: https://github.com/microsoft/vcpkg/blob/master/docs/users/android.md - ["armeabi-v7a"] = "arm", - ["arm64-v8a"] = "arm64", - - -- ios: arm64 armv7 armv7s i386 - armv7 = "arm", - armv7s = "arm", - arm64 = "arm64", - } - -- mapping arch - arch = archs[arch] or arch + arch = configurations.arch(arch) -- init triplet local triplet = arch .. "-" .. plat @@ -77,6 +68,78 @@ function _install_for_classic(vcpkg, name, opt) os.vrunv(vcpkg, argv) end +-- install for manifest mode +function _install_for_manifest(vcpkg, name, opt) + + -- get configs + local configs = opt.configs or {} + + --[[ + -- get arch, plat and mode + + -- init triplet + local triplet = arch .. "-" .. plat + if opt.plat == "windows" and opt.shared ~= true then + triplet = triplet .. "-static" + if opt.vs_runtime and opt.vs_runtime:startswith("MD") then + triplet = triplet .. "-md" + end + end]] + + -- init argv + local argv = {"--feature-flags=\"versions\"", "install"} + if option.get("diagnosis") then + table.insert(argv, "--debug") + end + + -- generate platform + local arch = opt.arch + local plat = opt.plat + if plat == "macosx" then + plat = "osx" + end + arch = configurations.arch(arch) + local platform = plat .. " & " .. arch + + -- generate dependencies + local require_version = opt.require_version + if require_version == "latest" then + require_version = nil + end + local minversion = require_version + if minversion and minversion:startswith(">=") then + minversion = minversion:sub(3) + end + local dependencies = {} + table.insert(dependencies, { + name = name, + ["version>="] = minversion, + platform = platform, + features = configs.features, + ["default-features"] = configs.default_features}) + + -- generate overrides to use fixed version + local overrides + if require_version and semver.is_valid(require_version) then + overrides = {{name = name, version = require_version}} + end + + -- generate manifest + local baseline = configs.baseline or "44d94c2edbd44f0c01d66c2ad95eb6982a9a61bc" -- 2021.04.30 + local manifest = { + name = "stub", + version = "1.0", + dependencies = dependencies, + ["builtin-baseline"] = baseline, + overrides = overrides} + local tmpdir = os.tmpfile() .. ".dir" + json.savefile(path.join(tmpdir, "vcpkg.json"), manifest) + + -- install package + os.vrunv(vcpkg, argv, {curdir = tmpdir}) + os.tryrm(tmpdir) +end + -- install package -- -- @param name the package name, e.g. pcre2, pcre2/libpcre2-8 @@ -93,6 +156,7 @@ function main(name, opt) end -- do install + opt = opt or {} if _need_manifest(opt) then _install_for_manifest(vcpkg.program, name, opt) else diff --git a/xmake/modules/private/action/require/impl/install_packages.lua b/xmake/modules/private/action/require/impl/install_packages.lua index c1d9b4791..f62a0fb52 100644 --- a/xmake/modules/private/action/require/impl/install_packages.lua +++ b/xmake/modules/private/action/require/impl/install_packages.lua @@ -285,7 +285,6 @@ function _install_packages(packages_install, packages_download, installdeps) -- fetch a new package local instance = nil while instance == nil and #packages_pending > 0 do - print("packages_pending", #packages_pending) for idx, pkg in ipairs(packages_pending) do -- all dependences has been installed? we install it now -- cgit v1.3.1 From c36a12cccb8639154ac3caf6441a764f6c32a5db Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Dec 2021 23:09:42 +0800 Subject: remove comments --- xmake/modules/package/manager/vcpkg/install_package.lua | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index de707d0d1..114cd538c 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -74,18 +74,6 @@ function _install_for_manifest(vcpkg, name, opt) -- get configs local configs = opt.configs or {} - --[[ - -- get arch, plat and mode - - -- init triplet - local triplet = arch .. "-" .. plat - if opt.plat == "windows" and opt.shared ~= true then - triplet = triplet .. "-static" - if opt.vs_runtime and opt.vs_runtime:startswith("MD") then - triplet = triplet .. "-md" - end - end]] - -- init argv local argv = {"--feature-flags=\"versions\"", "install"} if option.get("diagnosis") then -- cgit v1.3.1 From 39349f1a4fbf510d434c01952fe1f8f7e7505259 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Dec 2021 23:14:50 +0800 Subject: add triplet to vcpkg manifest --- tests/projects/package/vcpkg_manifest/xmake.lua | 2 +- .../package/manager/vcpkg/install_package.lua | 25 +++++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/projects/package/vcpkg_manifest/xmake.lua b/tests/projects/package/vcpkg_manifest/xmake.lua index d7150718c..fd8a23e79 100644 --- a/tests/projects/package/vcpkg_manifest/xmake.lua +++ b/tests/projects/package/vcpkg_manifest/xmake.lua @@ -1,4 +1,4 @@ ---add_requires("vcpkg::zlib 1.2.11", "vcpkg::fmt >=8.0.1") +add_requires("vcpkg::zlib 1.2.11", "vcpkg::fmt >=8.0.1") add_requires("vcpkg::arrow", {configs = {features = {"json"}}}) target("test") diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index 114cd538c..ec00fcb85 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -74,19 +74,28 @@ function _install_for_manifest(vcpkg, name, opt) -- get configs local configs = opt.configs or {} - -- init argv - local argv = {"--feature-flags=\"versions\"", "install"} - if option.get("diagnosis") then - table.insert(argv, "--debug") - end - - -- generate platform + -- init triplet local arch = opt.arch local plat = opt.plat if plat == "macosx" then plat = "osx" end arch = configurations.arch(arch) + local triplet = arch .. "-" .. plat + if opt.plat == "windows" and opt.shared ~= true then + triplet = triplet .. "-static" + if opt.vs_runtime and opt.vs_runtime:startswith("MD") then + triplet = triplet .. "-md" + end + end + + -- init argv + local argv = {"--feature-flags=\"versions\"", "install", "--triplet", triplet} + if option.get("diagnosis") then + table.insert(argv, "--debug") + end + + -- generate platform local platform = plat .. " & " .. arch -- generate dependencies @@ -120,7 +129,7 @@ function _install_for_manifest(vcpkg, name, opt) dependencies = dependencies, ["builtin-baseline"] = baseline, overrides = overrides} - local tmpdir = os.tmpfile() .. ".dir" + local tmpdir = os.tmpfile({ramdisk = false}) .. ".dir" json.savefile(path.join(tmpdir, "vcpkg.json"), manifest) -- install package -- cgit v1.3.1 From a1abfda3ca119979f541876355471b026abcc3f9 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 20 Dec 2021 23:18:02 +0800 Subject: find package stub for vcpkg manifest mode --- tests/projects/package/vcpkg_manifest/xmake.lua | 3 +- .../modules/package/manager/vcpkg/find_package.lua | 40 ++++++++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/tests/projects/package/vcpkg_manifest/xmake.lua b/tests/projects/package/vcpkg_manifest/xmake.lua index fd8a23e79..a6b24f1bc 100644 --- a/tests/projects/package/vcpkg_manifest/xmake.lua +++ b/tests/projects/package/vcpkg_manifest/xmake.lua @@ -1,4 +1,5 @@ -add_requires("vcpkg::zlib 1.2.11", "vcpkg::fmt >=8.0.1") +add_requires("vcpkg::zlib 1.2.11") +add_requires("vcpkg::fmt >=8.0.1", {configs = {baseline = "50fd3d9957195575849a49fa591e645f1d8e7156"}}) add_requires("vcpkg::arrow", {configs = {features = {"json"}}}) target("test") diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua index e84833958..726eceea7 100644 --- a/xmake/modules/package/manager/vcpkg/find_package.lua +++ b/xmake/modules/package/manager/vcpkg/find_package.lua @@ -27,21 +27,8 @@ import("core.project.target") import("detect.sdks.find_vcpkgdir") import("package.manager.vcpkg.configurations") --- find package from the vcpkg package manager --- --- @param name the package name, e.g. zlib, pcre --- @param opt the options, e.g. {verbose = true) --- -function main(name, opt) - - -- attempt to find vcpkg directory - local vcpkgdir = find_vcpkgdir() - if not vcpkgdir then - if option.get("diagnosis") then - cprint("${color.warning}checkinfo: ${clear dim}vcpkg root directory not found, maybe you need set $VCPKG_ROOT!") - end - return - end +-- find it for classic mode +function _find_package_for_classic(vcpkgdir, name, opt) -- fix name, e.g. ffmpeg[x264] as ffmpeg -- @see https://github.com/xmake-io/xmake/issues/925 @@ -137,3 +124,26 @@ function main(name, opt) return result end +-- find it for manifest mode +function _find_package_for_manifest(vcpkgdir, name, opt) +end + +-- find package from the vcpkg package manager +-- +-- @param name the package name, e.g. zlib, pcre +-- @param opt the options, e.g. {verbose = true) +-- +function main(name, opt) + + -- attempt to find vcpkg directory + local vcpkgdir = find_vcpkgdir() + if not vcpkgdir then + if option.get("diagnosis") then + cprint("${color.warning}checkinfo: ${clear dim}vcpkg root directory not found, maybe you need set $VCPKG_ROOT!") + end + return + end + + -- do find + return _find_package_for_manifest(vcpkgdir, name, opt) or _find_package_for_classic(vcpkgdir, name, opt) +end -- cgit v1.3.1 From ce000fa3f72ea6c4ca684a3d08b1e6cf09f5fb68 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 21 Dec 2021 22:50:26 +0800 Subject: improve to vcpkg.find_package for manifest --- tests/projects/package/vcpkg_manifest/xmake.lua | 4 +-- xmake/core/package/package.lua | 23 ++++++++++++---- .../modules/package/manager/vcpkg/find_package.lua | 31 +++++++++++----------- .../package/manager/vcpkg/install_package.lua | 16 +++++++---- 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/tests/projects/package/vcpkg_manifest/xmake.lua b/tests/projects/package/vcpkg_manifest/xmake.lua index a6b24f1bc..5c08f2869 100644 --- a/tests/projects/package/vcpkg_manifest/xmake.lua +++ b/tests/projects/package/vcpkg_manifest/xmake.lua @@ -1,9 +1,9 @@ add_requires("vcpkg::zlib 1.2.11") add_requires("vcpkg::fmt >=8.0.1", {configs = {baseline = "50fd3d9957195575849a49fa591e645f1d8e7156"}}) -add_requires("vcpkg::arrow", {configs = {features = {"json"}}}) +add_requires("vcpkg::libpng", {configs = {features = {"apng"}}}) target("test") set_kind("binary") add_files("src/*.cpp") - add_packages("vcpkg::zlib", "vcpkg::fmt", "vcpkg::arrow") + add_packages("vcpkg::zlib", "vcpkg::fmt", "vcpkg::libpng") diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 88a5d07fb..379d1ddea 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -486,7 +486,7 @@ end -- is local package? -- we will use local installdir and cachedir in current project function _instance:is_local() - return self:is_embed() + return self:is_embed() or self:is_thirdparty() end -- is debug package? (deprecated) @@ -570,10 +570,15 @@ function _instance:cachedir() cachedir = self:get("cachedir") if not cachedir then local name = self:name():lower():gsub("::", "_") + local version_str = self:version_str() + if self:is_thirdparty() then + -- strip `>= <=` + version_str = version_str:gsub("[>=<]", "") + end if self:is_local() then - cachedir = path.join(config.buildir({absolute = true}), ".packages", name:sub(1, 1):lower(), name, self:version_str(), "cache") + cachedir = path.join(config.buildir({absolute = true}), ".packages", name:sub(1, 1):lower(), name, version_str, "cache") else - cachedir = path.join(package.cachedir(), name:sub(1, 1):lower(), name, self:version_str()) + cachedir = path.join(package.cachedir(), name:sub(1, 1):lower(), name, version_str) end end self._CACHEDIR = cachedir @@ -593,8 +598,13 @@ function _instance:installdir(...) else installdir = path.join(package.installdir(), name:sub(1, 1):lower(), name) end - if self:version_str() then - installdir = path.join(installdir, self:version_str()) + local version_str = self:version_str() + if version_str then + if self:is_thirdparty() then + -- strip `>= <=` + version_str = version_str:gsub("[>=<]", "") + end + installdir = path.join(installdir, version_str) end installdir = path.join(installdir, self:buildhash()) end @@ -1054,6 +1064,9 @@ function _instance:buildhash() -- We cannot directly deserialize the table, so the result may be different each time local configs_order = {} for k, v in pairs(table.wrap(configs)) do + if type(v) == "table" then + v = string.serialize(v, {strip = true, indent = false, orderkeys = true}) + end table.insert(configs_order, k .. "=" .. tostring(v)) end table.sort(configs_order) diff --git a/xmake/modules/package/manager/vcpkg/find_package.lua b/xmake/modules/package/manager/vcpkg/find_package.lua index 726eceea7..c28f62b07 100644 --- a/xmake/modules/package/manager/vcpkg/find_package.lua +++ b/xmake/modules/package/manager/vcpkg/find_package.lua @@ -27,8 +27,7 @@ import("core.project.target") import("detect.sdks.find_vcpkgdir") import("package.manager.vcpkg.configurations") --- find it for classic mode -function _find_package_for_classic(vcpkgdir, name, opt) +function _find_package(vcpkgdir, name, opt) -- fix name, e.g. ffmpeg[x264] as ffmpeg -- @see https://github.com/xmake-io/xmake/issues/925 @@ -43,11 +42,11 @@ function _find_package_for_classic(vcpkgdir, name, opt) end arch = configurations.arch(arch) - -- get the vcpkg installed directory - local installdir = path.join(vcpkgdir, "installed") - - -- get the vcpkg info directory - local infodir = path.join(installdir, "vcpkg", "info") + -- get the vcpkg info directories + local infodirs = { + path.join(opt.installdir, "vcpkg_installed", "vcpkg", "info"), + path.join(vcpkgdir, "installed", "vcpkg", "info") + } -- find the package info file, e.g. zlib_1.2.11-3_x86-windows[-static].list local triplet = arch .. "-" .. plat @@ -58,11 +57,15 @@ function _find_package_for_classic(vcpkgdir, name, opt) triplet = triplet .. "-md" end end - local infofile = find_file(format("%s_*_%s.list", name, triplet), infodir) + local infofile = find_file(format("%s_*_%s.list", name, triplet), infodirs) + if not infofile then + return + end + local installdir = path.directory(path.directory(path.directory(infofile))) -- save includedirs, linkdirs and links local result = nil - local info = infofile and io.readfile(infofile) or nil + local info = io.readfile(infofile) if info then for _, line in ipairs(info:split('\n')) do line = line:trim() @@ -104,7 +107,7 @@ function _find_package_for_classic(vcpkgdir, name, opt) end -- save version - if result and infofile then + if result then local infoname = path.basename(infofile) result.version = infoname:match(name .. "_(%d+%.?%d*%.?%d*.-)_" .. arch) if not result.version then @@ -124,10 +127,6 @@ function _find_package_for_classic(vcpkgdir, name, opt) return result end --- find it for manifest mode -function _find_package_for_manifest(vcpkgdir, name, opt) -end - -- find package from the vcpkg package manager -- -- @param name the package name, e.g. zlib, pcre @@ -144,6 +143,6 @@ function main(name, opt) return end - -- do find - return _find_package_for_manifest(vcpkgdir, name, opt) or _find_package_for_classic(vcpkgdir, name, opt) + -- do find package + return _find_package(vcpkgdir, name, opt) end diff --git a/xmake/modules/package/manager/vcpkg/install_package.lua b/xmake/modules/package/manager/vcpkg/install_package.lua index ec00fcb85..9b7ded261 100644 --- a/xmake/modules/package/manager/vcpkg/install_package.lua +++ b/xmake/modules/package/manager/vcpkg/install_package.lua @@ -32,7 +32,7 @@ function _need_manifest(opt) return true end local configs = opt.configs - if configs and (configs.features or configs.default_features or configs.baseline) then + if configs and (configs.features or configs.default_features == false or configs.baseline) then return true end end @@ -129,12 +129,18 @@ function _install_for_manifest(vcpkg, name, opt) dependencies = dependencies, ["builtin-baseline"] = baseline, overrides = overrides} - local tmpdir = os.tmpfile({ramdisk = false}) .. ".dir" - json.savefile(path.join(tmpdir, "vcpkg.json"), manifest) + local installdir = assert(opt.installdir, "installdir not found!") + json.savefile(path.join(installdir, "vcpkg.json"), manifest) + if not os.isdir(installdir) then + os.mkdir(installdir) + end + if option.get("diagnosis") then + vprint(path.join(installdir, "vcpkg.json")) + vprint(manifest) + end -- install package - os.vrunv(vcpkg, argv, {curdir = tmpdir}) - os.tryrm(tmpdir) + os.vrunv(vcpkg, argv, {curdir = installdir}) end -- install package -- cgit v1.3.1