diff options
| author | ruki <[email protected]> | 2025-11-17 23:23:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2025-11-17 23:23:03 +0800 |
| commit | 80b4ebb7033748c8cf1b132b1c0a68c3810229ef (patch) | |
| tree | 986d97db7a7b924878e100c457773022049a1ea1 /xmake/modules/private/utils/package.lua | |
| parent | 934b2f410cf91fd54003576e615faa8db65f4aa3 (diff) | |
improve to parse require
Diffstat (limited to 'xmake/modules/private/utils/package.lua')
| -rw-r--r-- | xmake/modules/private/utils/package.lua | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/xmake/modules/private/utils/package.lua b/xmake/modules/private/utils/package.lua index 66a755ca8..6df309f5f 100644 --- a/xmake/modules/private/utils/package.lua +++ b/xmake/modules/private/utils/package.lua @@ -54,3 +54,102 @@ function fetchinfo_set_concat(fetchinfo) debug.setmetatable(fetchinfo, {__concat = _concat_packages}) end end + +-- +-- parse require string +-- +-- basic +-- - add_requires("zlib") +-- +-- semver +-- - add_requires("tbox >=1.5.1", "zlib >=1.2.11") +-- - add_requires("tbox", {version = ">=1.5.1"}) +-- +-- git branch/tag +-- - add_requires("zlib master") +-- +-- with the given repository +-- - add_requires("xmake-repo@tbox >=1.5.1") +-- +-- with the given configs +-- - add_requires("aaa_bbb_ccc >=1.5.1 <1.6.0", {optional = true, alias = "mypkg", debug = true}) +-- - add_requires("tbox", {config = {coroutine = true, abc = "xxx"}}) +-- +-- with namespace and the 3rd package manager +-- - add_requires("xmake::xmake-repo@tbox >=1.5.1") +-- - add_requires("vcpkg::ffmpeg") +-- - add_requires("conan::OpenSSL/1.0.2n@conan/stable") +-- - add_requires("conan::openssl/1.1.1g") -- new +-- - add_requires("brew::pcre2/libpcre2-8 10.x", {alias = "pcre2"}) +-- +-- clone as a standalone package with the different configs +-- we can install and use these three packages at the same time. +-- - add_requires("zlib") +-- - add_requires("zlib~debug", {debug = true}) +-- - add_requires("zlib~shared", {configs = {shared = true}, alias = "zlib_shared"}) +-- +-- - add_requires("zlib~label1") +-- - add_requires("zlib", {label = "label2"}) +-- +-- private package, only for installation, do not export any links/includes and environments to target +-- - add_requires("zlib", {private = true}) +-- +-- {system = nil/true/false}: +-- nil: get remote or system packages +-- true: only get system package +-- false: only get remote packages +-- +-- {build = true}: always build packages, we do not use the precompiled artifacts +-- +-- simply configs as string: +-- add_requires("boost[iostreams,system,thread,key=value] >=1.78.0") +-- add_requires("boost[iostreams,thread=n] >=1.78.0") +-- add_requires("libplist[shared,debug,codecs=[foo,bar,zoo]]") +-- +function parse_requirestr(require_str) + + -- split package and version info + local splitinfo = require_str:split('%s+') + assert(splitinfo and #splitinfo > 0, "require(\"%s\"): invalid!", require_str) + + -- get package info + local packageinfo = splitinfo[1] + + -- get version + -- + -- e.g. + -- + -- latest + -- >=1.5.1 <1.6.0 + -- master || >1.4 + -- ~1.2.3 + -- ^1.1 + -- + local version = "latest" + if #splitinfo > 1 then + version = table.concat(table.slice(splitinfo, 2), " ") + end + assert(version, "require(\"%s\"): unknown version!", require_str) + + -- require third-party packages? e.g. brew::pcre2/libpcre2-8 + local reponame = nil + local packagename = nil + if require_str:find("::", 1, true) then + packagename = packageinfo + else + + -- get repository name, package name and package url + local pos = packageinfo:lastof('@', true) + if pos then + packagename = packageinfo:sub(pos + 1) + reponame = packageinfo:sub(1, pos - 1) + else + packagename = packageinfo + end + end + + -- check package name + assert(packagename, "require(\"%s\"): the package name not found!", require_str) + return packagename, version, reponame +end + |
