diff options
| author | ruki <[email protected]> | 2026-01-07 23:56:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-01-09 17:59:06 +0800 |
| commit | 3b1f621c6b25958eef72dd98df074fcb6bc81d5e (patch) | |
| tree | 625444e9025b15c55a6a6dfff7c84bdd9f133cb7 /xmake/core/package/scheme.lua | |
| parent | 2c77aafe1a0c1b87c9b423541eaff4a04748e5e5 (diff) | |
improve to select package version for schemes
Diffstat (limited to 'xmake/core/package/scheme.lua')
| -rw-r--r-- | xmake/core/package/scheme.lua | 112 |
1 files changed, 103 insertions, 9 deletions
diff --git a/xmake/core/package/scheme.lua b/xmake/core/package/scheme.lua index 7c8e61f2d..a7166283a 100644 --- a/xmake/core/package/scheme.lua +++ b/xmake/core/package/scheme.lua @@ -90,6 +90,107 @@ function _instance:extraconf_set(name, item, key, value) return self._INFO:extraconf_set(name, item, key, value) end +-- get urls +function _instance:urls() + local urls = self._URLS + if urls == nil then + urls = table.wrap(self:get("urls")) + if #urls == 1 and urls[1] == "" then + urls = {} + end + end + return urls +end + +-- get versions +function _instance:versions() + if self._VERSIONS == nil then + -- we need to sort the build number in semver list + -- https://github.com/xmake-io/xmake/issues/6953 + local versions = {} + for version, _ in table.orderpairs(self:_versions_list()) do + -- remove the url alias prefix if exists + local pos = version:find(':', 1, true) + if pos then + version = version:sub(pos + 1, -1) + end + table.insert(versions, version) + end + self._VERSIONS = table.unique(versions) + end + return self._VERSIONS +end + +-- get versions list +function _instance:_versions_list() + if self._VERSIONS_LIST == nil then + local versions = table.wrap(self:get("versions")) + local versionfiles = self:get("versionfiles") + if versionfiles then + for _, versionfile in ipairs(table.wrap(versionfiles)) do + if not path.is_absolute(versionfile) then + local subpath = versionfile + versionfile = path.join(self:scriptdir(), subpath) + if not os.isfile(versionfile) and self:package() then + versionfile = path.join(self:package():scriptdir(), subpath) + end + end + if os.isfile(versionfile) then + local list = io.readfile(versionfile) + for _, line in ipairs(list:split("\n")) do + local splitinfo = line:split("%s+") + if #splitinfo == 2 then + local version = splitinfo[1] + local shasum = splitinfo[2] + versions[version] = shasum + end + end + end + end + end + self._VERSIONS_LIST = versions + end + return self._VERSIONS_LIST +end + +-- get version string +function _instance:version_str() + return self._VERSION_STR +end + +-- set version +function _instance:version_set(version, source) + self._VERSION_STR = version + self._VERSION_SOURCE = source + if source == "branch" then + self._BRANCH = version + elseif source == "tag" then + self._TAG = version + elseif source == "commit" then + self._COMMIT = version + end +end + +-- get branch version +function _instance:branch() + return self._BRANCH +end + +-- get tag version +function _instance:tag() + return self._TAG +end + +-- get commit version +function _instance:commit() + return self._COMMIT +end + +-- is git ref? +function _instance:gitref() + return self:branch() or self:tag() or self:commit() +end + -- interpreter function scheme._interpreter() local interp = scheme._INTERPRETER @@ -107,19 +208,12 @@ function scheme.apis() values = { -- scheme.set_xxx "scheme.set_urls", - "scheme.set_policy", -- scheme.add_xxx - "scheme.add_urls", - "scheme.add_patches", - "scheme.add_resources", - "scheme.add_versionfiles", - "scheme.add_versions" + "scheme.add_urls" }, keyvalues = { - -- scheme.set_xxx - "scheme.set_policy" -- scheme.add_xxx - , "scheme.add_patches" + "scheme.add_patches" , "scheme.add_resources" }, paths = { |
