Skip to content

base: deps_version_parser.lua - #47

Closed
MoYingJi wants to merge 5 commits into
openxlings:mainfrom
MoYingJi:main
Closed

MoYingJi wants to merge 5 commits into
openxlings:mainfrom
MoYingJi:main

Conversation

@MoYingJi

@MoYingJi MoYingJi commented Dec 8, 2024

Copy link
Copy Markdown
Collaborator

这样大概可以了? #45

@MoYingJi
MoYingJi requested a review from Sunrisepeak as a code owner December 8, 2024 07:50
@Sunrisepeak

Copy link
Copy Markdown
Member

在调整架构, 等待一起合入

function parse_single_version(version_str)
function parse_single_version_range(version_str)
local version = {}
if version_str == "any" or version_str == "*" then

@nostalume nostalume Dec 16, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local Version = {}
Version.__index = Version

function Version:new(str)
      local self = setmetatable({},Version}
      self:parse(str)
      return self
end

function Version:parse(str)
   local pattern = (...)
   local major,minor,patch,prerelease,build = str:match(pattern)
   self.major = tonumber(major) or 0
   self.minor = tonumber(minor) or 0
   self.patch = tonumber(patch) or 0
   self.prerelease = prerelease or ""
   self.build = build or "" 
end

function Version:compare(other)
    if self.major ~= other.major then
        return self.major - other.major
    end
    if self.minor ~= other.minor then
        return self.minor - other.minor
    end
    if self.patch ~= other.patch then
        return self.patch - other.patch
    end

    if self.prerelease ~= other.prerelease then
        if self.prerelease == "" then
            return 1
        elseif other.prerelease == "" then
            return -1
        else
            return self.prerelease < other.prerelease and 1 or -1
        end
    end

    return 0
end

function Version:__lt(other)
    return self:compare(other) < 0
end

function Version:__le(other)
    return self:compare(other) <= 0
end

function Version:__eq(other)
    return self:compare(other) == 0
end

function Version:__gt(other)
    return self:compare(other) > 0
end

function Version:__ge(other)
    return self:compare(other) >= 0
end


-- 解析复合版本字符串到版本对象
function parse_version(version_str)
function parse_version_ranges(version_str)

@nostalume nostalume Dec 16, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local Constraint = {}
Constraint.__index = Constraint

function Constraint:new(str)
   local self = setmetatable({},Constraint)
   self:parse(str)
   return self
end

function Constraint:parse(str)
   local pattern = (...)
   local op,version_str = str:match(pattern)
   self.op = op
   self.version = Version:new(version_str)
end

function Constraint:include(version)
     if self.operator == "*" then
        return true  -- "*" means any version
    elseif self.operator == "<=" then
        return version <= self.version
    elseif self.operator == "<" then
        return version < self.version
    elseif self.operator == ">=" then
        return version >= self.version
    elseif self.operator == ">" then
        return version > self.version
    elseif self.operator == "=" then
        return version == self.version
    else
        return false
    end
end

@nostalume nostalume Dec 16, 2024 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local Constraints = {}
Constraints.__index = Constraints

function Constraints:new(str)
   local self = setmetatable({},Constraints)
   self:parse(str)
   return self
end

function Constraints:parse(str)
   self.constraints = {}
   for part in str:gmatch(...) do
        table.insert(self.constraints,Constraint:new(part))
    end
end

function Constraints:include(version)
    for _,constraint in ipairs(self.constraints) do
          if not constraint:include(verison) then
                 return false
          end
     end
     return true
end

@MoYingJi
MoYingJi deleted the branch openxlings:main December 22, 2024 11:05
@MoYingJi MoYingJi closed this Dec 22, 2024
@MoYingJi
MoYingJi deleted the main branch December 22, 2024 11:05
Sunrisepeak added a commit that referenced this pull request Oct 8, 2026
…dependent of SubOS scopes)

The client was pinned to #47's fix commit on its PR branch; that branch is
merged and gone, so the pin moves to the squash commit on libxpkg's main.
Same code (the version bump to 0.0.62 is the only addition).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants