diff options
| author | ruki <[email protected]> | 2021-12-21 22:50:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-12-21 22:50:26 +0800 |
| commit | ce000fa3f72ea6c4ca684a3d08b1e6cf09f5fb68 (patch) | |
| tree | bd5b5b024372040b144ebbef24ad424e24f4187b | |
| parent | a1abfda3ca119979f541876355471b026abcc3f9 (diff) | |
improve to vcpkg.find_package for manifest
| -rw-r--r-- | tests/projects/package/vcpkg_manifest/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/package/manager/vcpkg/find_package.lua | 31 | ||||
| -rw-r--r-- | xmake/modules/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 |
