From 3582ed1e76067b7512aa791db146778777235742 Mon Sep 17 00:00:00 2001 From: Peefy Date: Mon, 15 Apr 2024 13:40:46 +0800 Subject: [PATCH] chore: remove pcre2 deps (#1220) Signed-off-by: peefy --- kclvm/Cargo.lock | 34 +--------------------------------- kclvm/config/Cargo.toml | 2 +- kclvm/config/src/path.rs | 16 ++++++---------- 3 files changed, 8 insertions(+), 44 deletions(-) diff --git a/kclvm/Cargo.lock b/kclvm/Cargo.lock index 11767ec08..4fcb93728 100644 --- a/kclvm/Cargo.lock +++ b/kclvm/Cargo.lock @@ -345,10 +345,6 @@ name = "cc" version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" -dependencies = [ - "jobserver", - "libc", -] [[package]] name = "cfg-if" @@ -1672,7 +1668,7 @@ dependencies = [ "kclvm-version", "md-5 0.8.0", "pathdiff", - "pcre2", + "regex", "ron", "serde", "serde_json", @@ -2396,28 +2392,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" -[[package]] -name = "pcre2" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea92ff5eabd27703ab12cefe01b08b2809ec3dc75fdc69d4e6b75fbce0cbd67" -dependencies = [ - "libc", - "log", - "pcre2-sys", -] - -[[package]] -name = "pcre2-sys" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "550f5d18fb1b90c20b87e161852c10cde77858c3900c5059b5ad2a1449f11d8a" -dependencies = [ - "cc", - "libc", - "pkg-config", -] - [[package]] name = "percent-encoding" version = "2.3.1" @@ -2535,12 +2509,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkg-config" -version = "0.3.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" - [[package]] name = "plotters" version = "0.3.5" diff --git a/kclvm/config/Cargo.toml b/kclvm/config/Cargo.toml index 7997307d9..aeb7b394f 100644 --- a/kclvm/config/Cargo.toml +++ b/kclvm/config/Cargo.toml @@ -23,5 +23,5 @@ kclvm-version = {path = "../version"} kclvm-utils = {path = "../utils"} kclvm-ast = {path = "../ast"} dirs = "5.0.0" -pcre2 = "0.2.4" md-5 = "0.8.0" +regex = "1.10.4" diff --git a/kclvm/config/src/path.rs b/kclvm/config/src/path.rs index 652897175..3c54c74d3 100644 --- a/kclvm/config/src/path.rs +++ b/kclvm/config/src/path.rs @@ -11,7 +11,7 @@ //! `${my_pkg:KCL_MOD}/sub/main.k` is a mod relative path. //! The real path of `${my_pkg:KCL_MOD}/xxx/main.k` is `/usr/my_pkg/sub/main.k`. use anyhow::Result; -use pcre2::bytes::Regex; +use regex::Regex; use std::path::PathBuf; #[derive(Clone, Debug, Default)] @@ -72,7 +72,7 @@ impl ModRelativePath { /// ``` pub fn is_relative_path(&self) -> Result { Ok(Regex::new(RELATIVE_PATH_PREFFIX)? - .find(self.path.as_bytes())? + .find(&self.path) .map_or(false, |mat| mat.start() == 0)) } @@ -97,10 +97,9 @@ impl ModRelativePath { } Ok(Regex::new(RELATIVE_PATH_PREFFIX)? - .captures(self.path.as_bytes())? + .captures(&self.path) .and_then(|caps| caps.name(ROOT_PKG_NAME_FLAG)) - .map(|mat| std::str::from_utf8(mat.as_bytes()).map(|s| s.to_string())) - .transpose()?) + .map(|mat| mat.as_str().to_string())) } /// [`canonicalize_by_root_path`] returns the canonicalized path by the root path. @@ -124,17 +123,14 @@ impl ModRelativePath { } Ok(Regex::new(RELATIVE_PATH_PREFFIX)? - .captures(self.path.as_bytes())? + .captures(&self.path) .map_or_else( || self.get_path(), |caps| { // Due to the path format is different between windows and linux, // Can not use the replace method directly // by 'replace(std::str::from_utf8(caps.get(0).unwrap().as_bytes()).unwrap(), root_path)'. - let sub_path = self.get_path().replace( - std::str::from_utf8(caps.get(0).unwrap().as_bytes()).unwrap(), - "", - ); + let sub_path = self.get_path().replace(caps.get(0).unwrap().as_str(), ""); let res = PathBuf::from(root_path) .join(sub_path) .display()