Skip to content

Commit 99e81cd

Browse files
committed
fix: simplify & improve build script code
1 parent 7c396ea commit 99e81cd

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

libsigner/src/libsigner.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,5 @@ lazy_static! {
8989
#[test]
9090
fn test_version_string() {
9191
let version = VERSION_STRING.to_string();
92-
assert_eq!(
93-
version.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str()),
94-
true
95-
);
92+
assert!(version.contains(format!("stacks-signer {}", STACKS_SIGNER_VERSION).as_str()));
9693
}

stacks-common/build.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,30 @@ use std::{env, fs};
44
use toml::Value;
55

66
fn main() {
7-
let toml_content =
8-
fs::read_to_string("../versions.toml").expect("Failed to read versions.toml");
7+
let toml_file = "../versions.toml";
8+
let toml_content = fs::read_to_string(toml_file).expect("Failed to read versions.toml");
99

1010
let config: Value = toml::from_str(&toml_content).expect("Failed to parse TOML");
1111

1212
let mut rust_code = String::from("// Auto-generated code from versions.toml\n\n");
1313

14-
match config {
15-
Value::Table(table) => {
16-
for (key, val) in table {
17-
match val {
18-
Value::String(s) => {
19-
let const_value = format!("\"{}\"", s);
20-
rust_code.push_str(&format!(
21-
"pub const {}: &str = {};\n",
22-
key.to_uppercase(),
23-
const_value
24-
));
25-
}
26-
_ => {
27-
panic!("Invalid value type in versions.toml: {:?}", val);
28-
}
29-
};
30-
}
31-
}
32-
_ => {
33-
panic!("Invalid value type in versions.toml: {:?}", config);
34-
}
14+
let Value::Table(table) = config else {
15+
panic!("Invalid value type in versions.toml: {config:?}");
16+
};
17+
for (key, val) in table {
18+
let Value::String(s) = val else {
19+
panic!("Invalid value type in versions.toml: {val:?}");
20+
};
21+
rust_code.push_str(&format!(
22+
"pub const {}: &str = {s:?};\n",
23+
key.to_uppercase()
24+
));
3525
}
3626

3727
let out_dir = env::var_os("OUT_DIR").unwrap();
3828
let dest_path = Path::new(&out_dir).join("versions.rs");
3929
fs::write(&dest_path, rust_code).expect("Failed to write generated code");
4030

4131
// Tell Cargo to rerun this script if the TOML file changes
42-
println!("cargo:rerun-if-changed=../versions.toml");
32+
println!("cargo:rerun-if-changed={toml_file}");
4333
}

versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Update these values when a new release is created.
22
# `stacks-common/build.rs` will automatically update `versions.rs` with these values.
3-
stacks_node_version = "3.1.0.0.2"
4-
stacks_signer_version = "3.1.0.0.2.0"
3+
stacks_node_version = "3.1.0.0.4"
4+
stacks_signer_version = "3.1.0.0.4.0"

0 commit comments

Comments
 (0)