refactor: remove once-cell-regex from dependencies (#500)

Co-authored-by: Fabian-Lars <github@fabianlars.de>
This commit is contained in:
sftse
2026-01-15 11:57:09 +01:00
committed by GitHub
parent 4071325984
commit a47ecb963f
26 changed files with 86 additions and 64 deletions

View File

@@ -0,0 +1,5 @@
---
"cargo-mobile2": patch
---
Remove unnecessary once-cell-regex dependency.

13
Cargo.lock generated
View File

@@ -191,11 +191,12 @@ dependencies = [
"java-properties",
"libc",
"log",
"once-cell-regex",
"once_cell",
"os_info",
"os_pipe",
"path_abs",
"plist",
"regex",
"rstest",
"serde",
"serde_json",
@@ -978,16 +979,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "once-cell-regex"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3de7e389a5043420c8f2b95ed03f3f104ad6f4c41f7d7e27298f033abc253e8"
dependencies = [
"once_cell",
"regex",
]
[[package]]
name = "once_cell"
version = "1.21.3"

View File

@@ -68,7 +68,8 @@ home = "0.5"
ignore = "0.4"
java-properties = "2"
log = "0.4"
once-cell-regex = "0.2"
once_cell = "1.21"
regex = "1.11"
path_abs = "0.5"
serde = { version = "1.0", features = ["derive"] }
structopt = { version = "0.3", optional = true }

View File

@@ -1,4 +1,5 @@
use super::{device_name, get_prop};
use crate::regex_multi_line;
use crate::{
android::{
device::{ConnectionStatus, Device},
@@ -9,7 +10,6 @@ use crate::{
target::TargetTrait,
util::cli::{Report, Reportable},
};
use once_cell_regex::regex_multi_line;
use std::{collections::BTreeSet, process::Command};
use thiserror::Error;

View File

@@ -5,11 +5,11 @@ use std::{
};
use super::adb;
use crate::regex;
use crate::{
android::env::Env,
util::cli::{Report, Reportable},
};
use once_cell_regex::regex;
use thiserror::Error;
#[derive(Debug, Error)]

View File

@@ -7,7 +7,11 @@ use crate::{
os::Env as CoreEnv,
util::cli::{Report, Reportable},
};
use std::{collections::HashMap, ffi::OsString, path::PathBuf};
use std::{
collections::HashMap,
ffi::OsString,
path::{Path, PathBuf},
};
use thiserror::Error;
#[derive(Debug, Error)]
@@ -63,8 +67,7 @@ impl Env {
}
})
.or_else(|err| {
if let Some(sdk_root) = std::env::var("ANDROID_SDK_ROOT")
.ok()
if let Some(sdk_root) = std::env::var_os("ANDROID_SDK_ROOT")
.map(PathBuf::from)
.filter(|sdk_root| sdk_root.is_dir())
{
@@ -75,8 +78,7 @@ impl Env {
}
})
.or_else(|err| {
if let Some(sdk_root) = std::env::var("ANDROID_SDK_ROOT")
.ok()
if let Some(sdk_root) = std::env::var_os("ANDROID_SDK_ROOT")
.map(PathBuf::from)
.filter(|sdk_root| sdk_root.is_dir())
{
@@ -102,7 +104,7 @@ impl Env {
}
pub fn platform_tools_path(&self) -> PathBuf {
PathBuf::from(&self.android_home).join("platform-tools")
Path::new(&self.android_home).join("platform-tools")
}
pub fn sdk_version(&self) -> Result<source_props::Revision, source_props::Error> {

View File

@@ -2,6 +2,7 @@ use super::{
source_props::{self, SourceProps},
target::Target,
};
use crate::regex_multi_line;
use crate::{
os::consts,
util::{
@@ -9,7 +10,6 @@ use crate::{
VersionDouble,
},
};
use once_cell_regex::regex_multi_line;
use std::{
collections::HashSet,
fmt::{self, Display},

View File

@@ -1,5 +1,5 @@
use crate::regex;
use crate::util;
use once_cell_regex::regex;
use std::{
collections::HashMap,
fmt::Display,

View File

@@ -13,7 +13,7 @@ use crate::{
CargoCommand,
},
};
use once_cell_regex::exports::once_cell::sync::OnceCell;
use once_cell::sync::OnceCell;
use serde::Serialize;
use std::{collections::BTreeMap, fmt, io, path::PathBuf, str};
use thiserror::Error;

View File

@@ -6,6 +6,7 @@ use super::{
device_ctl_available,
system_profile::{self, DeveloperTools},
};
use crate::regex;
use crate::{
util::{
self,
@@ -14,7 +15,6 @@ use crate::{
},
DuctExpressionExt,
};
use once_cell_regex::regex;
use std::collections::hash_set::HashSet;
use thiserror::Error;

View File

@@ -2,7 +2,7 @@ use super::{
util::{self, CaptureGroupError},
GemCache, PACKAGES,
};
use once_cell_regex::regex;
use crate::regex;
use serde::Deserialize;
use thiserror::Error;

View File

@@ -1,10 +1,9 @@
use once_cell_regex::regex;
use super::{
config::{Config, Metadata},
deps, rust_version_check,
target::Target,
};
use crate::regex;
use crate::{
bicycle,
target::TargetTrait as _,

View File

@@ -1,5 +1,5 @@
use crate::regex;
use crate::util;
use once_cell_regex::regex;
use thiserror::Error;
#[derive(Debug, Error)]

View File

@@ -17,7 +17,7 @@ use crate::{
},
DuctExpressionExt,
};
use once_cell_regex::exports::once_cell::sync::OnceCell;
use once_cell::sync::OnceCell;
use serde::Deserialize;
use std::{
collections::{BTreeMap, HashMap},

View File

@@ -1,4 +1,4 @@
use once_cell_regex::regex;
use crate::regex;
use std::collections::BTreeSet;
use thiserror::Error;

View File

@@ -73,7 +73,7 @@ pub struct App {
template_pack: Pack,
#[serde(skip)]
#[allow(clippy::type_complexity)]
target_dir_resolver: Option<Arc<Box<dyn Fn(&str, Profile) -> PathBuf>>>,
target_dir_resolver: Option<Arc<dyn Fn(&str, Profile) -> PathBuf>>,
}
impl Debug for App {
@@ -164,8 +164,7 @@ impl App {
mut self,
resolver: F,
) -> Self {
self.target_dir_resolver
.replace(Arc::new(Box::new(resolver)));
self.target_dir_resolver.replace(Arc::new(resolver));
self
}

View File

@@ -10,6 +10,7 @@ pub mod doctor;
pub mod dot_cargo;
pub mod env;
pub mod init;
mod once_cell_regex;
pub mod opts;
pub mod os;
mod project;

34
src/once_cell_regex.rs Normal file
View File

@@ -0,0 +1,34 @@
#[macro_export]
macro_rules! regex {
($re:expr) => {{
use ::once_cell::sync::OnceCell;
use ::regex::Regex;
static RE: OnceCell<Regex> = OnceCell::new();
RE.get_or_init(|| Regex::new($re).unwrap())
}};
}
#[macro_export]
macro_rules! regex_multi_line {
($re:expr) => {{
use ::once_cell::sync::OnceCell;
use ::regex::Regex;
static RE: OnceCell<Regex> = OnceCell::new();
RE.get_or_init(|| {
::regex::RegexBuilder::new($re)
.multi_line(true)
.build()
.unwrap()
})
}};
}
#[macro_export]
macro_rules! byte_regex {
($re:expr) => {{
use ::once_cell::sync::OnceCell;
use ::regex::bytes::Regex;
static RE: OnceCell<Regex> = OnceCell::new();
RE.get_or_init(|| Regex::new($re).unwrap())
}};
}

View File

@@ -1,5 +1,5 @@
use crate::os::Info;
use once_cell_regex::regex;
use crate::regex;
use std::path::PathBuf;
use thiserror::Error;

View File

@@ -1,5 +1,6 @@
use crate::byte_regex;
use freedesktop_entry_parser::{parse_entry, Entry as FreeDesktopEntry};
use once_cell_regex::{byte_regex, exports::regex::bytes::Regex};
use regex::bytes::Regex;
use std::{
env,
ffi::{OsStr, OsString},
@@ -154,8 +155,7 @@ fn parse_unquoted_text(
// We parse the arguments
// We only have one file path (not an URL). Any instance of these ones
// needs to be replaced by the file path in this particular case.
let arg_re = byte_regex!(r"%u|%U|%f|%F");
let result = replace_on_pattern(text, argument, arg_re);
let result = replace_on_pattern(text, argument, byte_regex!(r"%u|%U|%f|%F"));
// Then the other flags
let icon_replace = icon.unwrap_or_else(|| "".as_ref());

View File

@@ -1,5 +1,5 @@
use crate::regex;
use crate::{os::Info, util};
use once_cell_regex::regex;
pub fn check() -> Result<Info, util::RunAndSearchError> {
util::run_and_search(

View File

@@ -141,7 +141,7 @@ mod interface {
use std::fmt::Debug;
use crate::{opts, util};
use once_cell_regex::exports::once_cell::sync::Lazy;
use once_cell::sync::Lazy;
use structopt::{
clap::{self, AppSettings},
StructOpt,

View File

@@ -14,21 +14,18 @@ impl<'a> Git<'a> {
Self { root }
}
pub fn root(&'a self) -> &'a Path {
pub fn root(&self) -> &Path {
self.root
}
pub fn command(&self) -> duct::Expression {
duct::cmd(
"git",
["-C", self.root.as_os_str().to_str().unwrap_or_default()],
)
duct::cmd("git", ["-C".as_ref(), self.root.as_os_str()])
}
pub fn command_parse(&self, arg_str: impl AsRef<str>) -> duct::Expression {
let mut args = vec!["-C", self.root.as_os_str().to_str().unwrap_or_default()];
let mut args = vec!["-C".as_ref(), self.root.as_os_str()];
for arg in arg_str.as_ref().split(' ') {
args.push(arg)
args.push(arg.as_ref())
}
duct::cmd("git", args)
}

View File

@@ -1,5 +1,5 @@
use super::{lfs, Git};
use once_cell_regex::regex;
use crate::regex;
use serde::{Deserialize, Serialize};
use std::{
fmt::{self, Display},
@@ -142,20 +142,14 @@ impl Submodule {
cause: Box::new(Cause::IndexCheckFailed(cause)),
})?;
let initialized = if !in_index {
let path_str = self
.path
.to_str()
.ok_or_else(|| Error {
submodule: self.clone(),
cause: Box::new(Cause::PathInvalidUtf8),
})?
.to_owned();
let path = self.path.to_owned();
log::info!("adding submodule: {:#?}", self);
let remote = self.remote.clone();
let name = name.to_owned();
git.command()
.before_spawn(move |cmd| {
cmd.args(["submodule", "add", "--name", &name, &remote, &path_str]);
cmd.args(["submodule", "add", "--name", &name, &remote])
.arg(&path);
Ok(())
})
.run()

View File

@@ -8,13 +8,14 @@ pub mod prompt;
pub use self::{cargo::*, git::*, path::*};
use self::cli::{Report, Reportable};
use crate::regex;
use crate::{
env::ExplicitEnv,
os::{self, command_path},
DuctExpressionExt,
};
use once_cell_regex::{exports::regex::Captures, exports::regex::Regex, regex};
use path_abs::PathOps;
use regex::{Captures, Regex};
use serde::{ser::Serializer, Deserialize, Serialize};
use std::{
error::Error as StdError,
@@ -28,10 +29,10 @@ use std::{
use thiserror::Error;
pub fn list_display(list: &[impl Display]) -> String {
if list.len() == 1 {
list[0].to_string()
} else if list.len() == 2 {
format!("{} and {}", list[0], list[1])
if let [x0] = list {
x0.to_string()
} else if let [x0, x1] = list {
format!("{x0} and {x1}")
} else {
let mut display = String::new();
for (idx, item) in list.iter().enumerate() {

View File

@@ -103,9 +103,7 @@ pub fn prefix_path(root: impl AsRef<Path>, path: impl AsRef<Path>) -> PathBuf {
}
Component::CurDir => {}
Component::ParentDir => {
if buf.last().is_some() {
buf.pop();
}
buf.pop();
}
_ => buf.push(component),
};