Skip to content

Commit 8d26316

Browse files
committed
add edit_version
1 parent 423690a commit 8d26316

File tree

6 files changed

+77
-8
lines changed

6 files changed

+77
-8
lines changed

Cargo.lock

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[workspace]
22
resolver = "2"
33
members = [
4-
"crates/*",
4+
"crates/*", "tools/edit_version",
55
]
66

77
[workspace.dependencies]
88
# local
9-
xmake_code_analysis = { path = "crates/xmake_code_analysis", version = "0.1.0" }
10-
xmake_ls = { path = "crates/xmake_ls", version = "0.1.0" }
9+
xmake_code_analysis = { path = "crates/xmake_code_analysis", version = "0.2.0" }
10+
xmake_ls = { path = "crates/xmake_ls", version = "0.2.0" }
1111
xmake_wrapper = { path = "crates/xmake_wrapper", version = "0.1.0" }
1212

1313
# external
@@ -51,4 +51,4 @@ ansi_term = "0.12.1"
5151
num-traits = { version = "0.2", features = ["std"] }
5252
mimalloc = "0.1.47"
5353
googletest = "0.14.2"
54-
unicode-general-category = "1.0.0"
54+
unicode-general-category = "1.0.0"

crates/xmake_code_analysis/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "xmake_code_analysis"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2024"
55
authors = ["CppCXY"]
66
description = "A library for analyzing xmake code."

crates/xmake_ls/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "xmake_ls"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2024"
55
authors = ["CppCXY"]
66
description = "A language server for xmake."

tools/edit_version/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "edit_version"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
toml_edit.workspace = true

tools/edit_version/src/main.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::fs;
2+
use toml_edit::{value, DocumentMut};
3+
4+
const CARGOS: &[&str] = &[
5+
"crates/xmake_code_analysis/Cargo.toml",
6+
"crates/xmake_ls/Cargo.toml",
7+
];
8+
9+
const CRATES: &[&str] = &["xmake_code_analysis", "xmake_ls"];
10+
11+
fn main() {
12+
let mut version = std::env::args().nth(1).expect("Please provide a version");
13+
if version.starts_with("refs/tags/") {
14+
version = version.replace("refs/tags/", "");
15+
}
16+
17+
let current_dir = std::env::current_dir().unwrap();
18+
// 向上查找到有crates的目录
19+
let workspace_dir = current_dir
20+
.ancestors()
21+
.find(|dir| dir.join("crates").exists())
22+
.expect("Unable to find crates directory");
23+
24+
for cargo in CARGOS {
25+
let path = workspace_dir.join(cargo);
26+
let content =
27+
fs::read_to_string(&path).unwrap_or_else(|_| panic!("Unable to read {}", cargo));
28+
29+
let mut doc = content
30+
.parse::<DocumentMut>()
31+
.unwrap_or_else(|_| panic!("Failed to parse {}", cargo));
32+
33+
doc["package"]["version"] = value(version.clone());
34+
35+
fs::write(&path, doc.to_string())
36+
.unwrap_or_else(|_| panic!("Unable to write to {}", cargo));
37+
}
38+
39+
let workspacec_cargo = workspace_dir.join("Cargo.toml");
40+
let content = fs::read_to_string(&workspacec_cargo)
41+
.unwrap_or_else(|_| panic!("Unable to read {:?}", workspacec_cargo));
42+
let mut doc = content
43+
.parse::<DocumentMut>()
44+
.unwrap_or_else(|_| panic!("Failed to parse {:?}", workspacec_cargo));
45+
46+
let dependencies = doc["workspace"]["dependencies"].as_table_mut().unwrap();
47+
for crate_name in CRATES {
48+
if let Some(dep) = dependencies.get_mut(crate_name) {
49+
dep["version"] = value(version.clone());
50+
}
51+
}
52+
53+
fs::write(&workspacec_cargo, doc.to_string())
54+
.unwrap_or_else(|_| panic!("Unable to write to {:?}", workspacec_cargo));
55+
}

0 commit comments

Comments
 (0)