mirror of
https://jturnerusa.dev/cgit/gentoo-utils/
synced 2025-12-02 19:18:35 -06:00
build-id must not start with zero
This commit is contained in:
@@ -58,13 +58,16 @@ pub struct VersionSuffix {
|
|||||||
#[derive(Debug, Clone, Get)]
|
#[derive(Debug, Clone, Get)]
|
||||||
pub struct VersionSuffixes(#[get(method = "get", kind = "deref")] Vec<VersionSuffix>);
|
pub struct VersionSuffixes(#[get(method = "get", kind = "deref")] Vec<VersionSuffix>);
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Get, PartialEq, Eq)]
|
||||||
|
pub struct BuildId(#[get(method = "get", kind = "deref")] String);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Get)]
|
#[derive(Clone, Debug, Get)]
|
||||||
pub struct Version {
|
pub struct Version {
|
||||||
numbers: VersionNumbers,
|
numbers: VersionNumbers,
|
||||||
letter: Option<char>,
|
letter: Option<char>,
|
||||||
suffixes: VersionSuffixes,
|
suffixes: VersionSuffixes,
|
||||||
rev: Option<VersionNumber>,
|
rev: Option<VersionNumber>,
|
||||||
build_id: Option<VersionNumber>,
|
build_id: Option<BuildId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
@@ -207,6 +210,22 @@ impl VersionNumber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for BuildId {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for BuildId {
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
// build-id may not start with a zero so we dont need to strip them
|
||||||
|
self.get()
|
||||||
|
.len()
|
||||||
|
.cmp(&other.get().len())
|
||||||
|
.then_with(|| self.get().cmp(other.get()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PartialEq for VersionSuffix {
|
impl PartialEq for VersionSuffix {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.kind == other.kind
|
self.kind == other.kind
|
||||||
@@ -373,7 +392,7 @@ impl PartialEq for Version {
|
|||||||
(None, None) => true,
|
(None, None) => true,
|
||||||
}
|
}
|
||||||
&& match (&self.build_id, &other.build_id) {
|
&& match (&self.build_id, &other.build_id) {
|
||||||
(Some(a), Some(b)) => matches!(a.cmp_as_ints(b), Ordering::Equal),
|
(Some(a), Some(b)) => a == b,
|
||||||
(Some(_), None) | (None, Some(_)) => false,
|
(Some(_), None) | (None, Some(_)) => false,
|
||||||
(None, None) => true,
|
(None, None) => true,
|
||||||
}
|
}
|
||||||
@@ -426,7 +445,7 @@ impl Ord for Version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match (&self.build_id, &other.build_id) {
|
match (&self.build_id, &other.build_id) {
|
||||||
(Some(a), Some(b)) => a.cmp_as_ints(b),
|
(Some(a), Some(b)) => a.cmp(b),
|
||||||
(Some(_), None) => Ordering::Greater,
|
(Some(_), None) => Ordering::Greater,
|
||||||
(None, Some(_)) => Ordering::Less,
|
(None, Some(_)) => Ordering::Less,
|
||||||
(None, None) => Ordering::Equal,
|
(None, None) => Ordering::Equal,
|
||||||
@@ -484,6 +503,12 @@ impl fmt::Display for VersionNumber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for BuildId {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "{}", self.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for VersionSuffixKind {
|
impl fmt::Display for VersionSuffixKind {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
use core::option::Option::None;
|
use core::option::Option::None;
|
||||||
|
|
||||||
use mon::{
|
use mon::{
|
||||||
Parser, ParserIter, ascii_alphanumeric, ascii_numeric1, eof, r#if, input::InputIter, one_of,
|
Parser, ParserIter, ascii_alphanumeric, ascii_numeric, ascii_numeric1, eof, r#if,
|
||||||
tag,
|
input::InputIter, one_of, tag,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Parseable,
|
Parseable,
|
||||||
atom::{
|
atom::{
|
||||||
Atom, Blocker, Category, Cp, Cpv, Name, Repo, Slot, SlotName, SlotOperator, UseDep,
|
Atom, Blocker, BuildId, Category, Cp, Cpv, Name, Repo, Slot, SlotName, SlotOperator,
|
||||||
UseDepCondition, UseDepNegate, UseDepSign, Version, VersionNumber, VersionNumbers,
|
UseDep, UseDepCondition, UseDepNegate, UseDepSign, Version, VersionNumber, VersionNumbers,
|
||||||
VersionOperator, VersionSuffix, VersionSuffixKind, VersionSuffixes, Wildcard,
|
VersionOperator, VersionSuffix, VersionSuffixKind, VersionSuffixes, Wildcard,
|
||||||
},
|
},
|
||||||
useflag::UseFlag,
|
useflag::UseFlag,
|
||||||
@@ -47,6 +47,20 @@ impl<'a> Parseable<'a, &'a str> for VersionNumber {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> Parseable<'a, &'a str> for BuildId {
|
||||||
|
type Parser = impl Parser<&'a str, Output = Self>;
|
||||||
|
|
||||||
|
fn parser() -> Self::Parser {
|
||||||
|
let start = ascii_numeric().and_not(tag("0"));
|
||||||
|
let rest = ascii_numeric().repeated().many();
|
||||||
|
|
||||||
|
start
|
||||||
|
.and(rest)
|
||||||
|
.recognize()
|
||||||
|
.map(|output: &str| BuildId(output.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a> Parseable<'a, &'a str> for VersionSuffixKind {
|
impl<'a> Parseable<'a, &'a str> for VersionSuffixKind {
|
||||||
type Parser = impl Parser<&'a str, Output = Self>;
|
type Parser = impl Parser<&'a str, Output = Self>;
|
||||||
|
|
||||||
@@ -97,7 +111,7 @@ impl<'a> Parseable<'a, &'a str> for Version {
|
|||||||
|
|
||||||
fn parser() -> Self::Parser {
|
fn parser() -> Self::Parser {
|
||||||
let rev = VersionNumber::parser().preceded_by(tag("-r"));
|
let rev = VersionNumber::parser().preceded_by(tag("-r"));
|
||||||
let build_id = VersionNumber::parser().preceded_by(tag("-"));
|
let build_id = BuildId::parser().preceded_by(tag("-"));
|
||||||
|
|
||||||
VersionNumbers::parser()
|
VersionNumbers::parser()
|
||||||
.and(r#if(|c: &char| c.is_ascii_alphabetic() && c.is_ascii_lowercase()).opt())
|
.and(r#if(|c: &char| c.is_ascii_alphabetic() && c.is_ascii_lowercase()).opt())
|
||||||
|
|||||||
Reference in New Issue
Block a user