aboutsummaryrefslogtreecommitdiff
path: root/dev_tools/src/bin/update-version.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-10 16:54:57 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-10 16:54:57 +0800
commit5d258482fb84d58c966a7ccc1b467708278d28ad (patch)
tree1a0c9d2e245d43ff7bc11d9088cf88a5264d293f /dev_tools/src/bin/update-version.rs
parenta8c8d50b6c59b103da7fd4bbb5e7ca3ff7b2f49a (diff)
refactor(devtools): rename dev_tools to .run and replace run-tools
scripts Replace the old run-tools.ps1/run-tools.sh scripts with a new unified run.ps1/run.sh launcher that supports multiple languages (PowerShell, Rust, Python, Go, C#, Nim, Perl, Ruby, Zig, and arbitrary binaries) from the `.run/src/bin` directory. Move all development tools from `dev_tools/` to `.run/`, update Cargo workspace config and relevant documentation references.
Diffstat (limited to 'dev_tools/src/bin/update-version.rs')
-rw-r--r--dev_tools/src/bin/update-version.rs98
1 files changed, 0 insertions, 98 deletions
diff --git a/dev_tools/src/bin/update-version.rs b/dev_tools/src/bin/update-version.rs
deleted file mode 100644
index 475e54b..0000000
--- a/dev_tools/src/bin/update-version.rs
+++ /dev/null
@@ -1,98 +0,0 @@
-use std::io::Write as _;
-use std::path::Path;
-
-use serde::Deserialize;
-use tools::println_cargo_style;
-
-#[derive(Deserialize)]
-struct VersionFile {
- file: String,
- pattern: String,
-}
-
-#[derive(Deserialize)]
-struct Config {
- #[serde(rename = "file")]
- files: Vec<VersionFile>,
-}
-
-fn main() {
- let args: Vec<String> = std::env::args().collect();
-
- // Get new version
- let new_ver = if args.len() > 1 {
- args[1].clone()
- } else {
- print!("Update version to: ");
- std::io::stdout().flush().unwrap();
- let mut input = String::new();
- std::io::stdin().read_line(&mut input).unwrap();
- input.trim().to_string()
- };
-
- if new_ver.is_empty() {
- eprintln!("Error: Version cannot be empty.");
- std::process::exit(1);
- }
-
- // Read current version from root Cargo.toml's workspace.package.version
- let root_cargo_path = "Cargo.toml";
- let root_cargo_content =
- std::fs::read_to_string(root_cargo_path).expect("Failed to read Cargo.toml");
- let cargo_value: toml::Value = root_cargo_content.parse().expect("Failed to parse Cargo.toml");
-
- let current_ver = cargo_value["workspace"]["package"]["version"]
- .as_str()
- .expect("workspace.package.version not found in Cargo.toml")
- .to_string();
-
- if new_ver == current_ver {
- println!("Version is already {}. Nothing to do.", current_ver);
- return;
- }
-
- println_cargo_style!("Version: {} -> {}", current_ver, new_ver);
-
- // Read version-files.toml
- let config_path = Path::new("dev_tools").join("version-files.toml");
- let config_str =
- std::fs::read_to_string(&config_path).expect("Failed to read dev_tools/version-files.toml");
- let config: Config = toml::from_str(&config_str)
- .expect("Failed to parse dev_tools/version-files.toml");
-
- let mut updated_count = 0;
- let mut skipped_count = 0;
-
- for vf in &config.files {
- let file_path = &vf.file;
- let old_pattern = vf.pattern.replace("{VER}", &current_ver);
- let new_pattern = vf.pattern.replace("{VER}", &new_ver);
-
- let content = match std::fs::read_to_string(file_path) {
- Ok(c) => c,
- Err(e) => {
- eprintln!("Warning: Could not read {}: {}", file_path, e);
- skipped_count += 1;
- continue;
- }
- };
-
- let new_content = content.replace(&old_pattern, &new_pattern);
-
- if new_content == content {
- eprintln!(
- "Warning: Pattern '{}' not found in {}",
- old_pattern, file_path
- );
- skipped_count += 1;
- continue;
- }
-
- std::fs::write(file_path, &new_content)
- .unwrap_or_else(|e| panic!("Failed to write {}: {}", file_path, e));
- println_cargo_style!("Updated: {}", file_path);
- updated_count += 1;
- }
-
- println_cargo_style!("Done: {} file(s) updated, {} file(s) skipped", updated_count, skipped_count);
-}