Extract SemanticVersion into its own crate (#9956)

This PR extracts the `SemanticVersion` out of `util` and into its own
`SemanticVersion` crate.

This allows for making use of `SemanticVersion` without needing to pull
in some of the heavier dependencies included in the `util` crate.

As part of this the public API for `SemanticVersion` has been tidied up
a bit.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2024-03-29 12:11:57 -04:00
committed by GitHub
parent 77f1cc95b8
commit 16e6f5643c
28 changed files with 147 additions and 110 deletions
+2 -10
View File
@@ -353,19 +353,11 @@ impl Platform for LinuxPlatform {
}
fn os_version(&self) -> Result<SemanticVersion> {
Ok(SemanticVersion {
major: 1,
minor: 0,
patch: 0,
})
Ok(SemanticVersion::new(1, 0, 0))
}
fn app_version(&self) -> Result<SemanticVersion> {
Ok(SemanticVersion {
major: 1,
minor: 0,
patch: 0,
})
Ok(SemanticVersion::new(1, 0, 0))
}
fn app_path(&self) -> Result<PathBuf> {
+5 -5
View File
@@ -718,11 +718,11 @@ impl Platform for MacPlatform {
unsafe {
let process_info = NSProcessInfo::processInfo(nil);
let version = process_info.operatingSystemVersion();
Ok(SemanticVersion {
major: version.majorVersion as usize,
minor: version.minorVersion as usize,
patch: version.patchVersion as usize,
})
Ok(SemanticVersion::new(
version.majorVersion as usize,
version.minorVersion as usize,
version.patchVersion as usize,
))
}
}
+12 -11
View File
@@ -12,13 +12,14 @@ use std::{
sync::{Arc, OnceLock},
};
use ::util::{ResultExt, SemanticVersion};
use ::util::ResultExt;
use anyhow::{anyhow, Context, Result};
use async_task::Runnable;
use copypasta::{ClipboardContext, ClipboardProvider};
use futures::channel::oneshot::{self, Receiver};
use itertools::Itertools;
use parking_lot::{Mutex, RwLock};
use semantic_version::SemanticVersion;
use smallvec::SmallVec;
use time::UtcOffset;
use windows::{
@@ -513,11 +514,11 @@ impl Platform for WindowsPlatform {
let mut info = unsafe { std::mem::zeroed() };
let status = unsafe { RtlGetVersion(&mut info) };
if status.is_ok() {
Ok(SemanticVersion {
major: info.dwMajorVersion as _,
minor: info.dwMinorVersion as _,
patch: info.dwBuildNumber as _,
})
Ok(SemanticVersion::new(
info.dwMajorVersion as _,
info.dwMinorVersion as _,
info.dwBuildNumber as _,
))
} else {
Err(anyhow::anyhow!(
"unable to get Windows version: {}",
@@ -606,11 +607,11 @@ impl Platform for WindowsPlatform {
let version_info = unsafe { &*(version_info_raw as *mut VS_FIXEDFILEINFO) };
// https://learn.microsoft.com/en-us/windows/win32/api/verrsrc/ns-verrsrc-vs_fixedfileinfo
if version_info.dwSignature == 0xFEEF04BD {
return Ok(SemanticVersion {
major: ((version_info.dwProductVersionMS >> 16) & 0xFFFF) as usize,
minor: (version_info.dwProductVersionMS & 0xFFFF) as usize,
patch: ((version_info.dwProductVersionLS >> 16) & 0xFFFF) as usize,
});
return Ok(SemanticVersion::new(
((version_info.dwProductVersionMS >> 16) & 0xFFFF) as usize,
(version_info.dwProductVersionMS & 0xFFFF) as usize,
((version_info.dwProductVersionLS >> 16) & 0xFFFF) as usize,
));
} else {
log::error!(
"no version info present: {}",