File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ authors = ["Linus Leo Stöckli"]
6
6
description = " Serial Monitor and Plotter written in rust."
7
7
license = " GPL-3.0"
8
8
homepage = " https://github.com/hacknus/serial-monitor-rust"
9
- # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
10
9
11
10
[dependencies ]
12
11
csv = " 1.3"
@@ -25,6 +24,9 @@ serde = { version = "1.0", features = ["derive"] }
25
24
serialport = { version = " 4.6.1" , features = [" serde" ] }
26
25
log = " 0.4.22"
27
26
27
+ [build-dependencies ]
28
+ regex = " 1.11"
29
+
28
30
[package .metadata .bundle ]
29
31
name = " Serial Monitor"
30
32
identifier = " com.hacknus.serial_monitor"
Original file line number Diff line number Diff line change
1
+ use std:: fs;
1
2
fn main ( ) {
2
3
println ! ( "cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.8" ) ;
4
+
5
+ // Get the package version from the environment variable
6
+ let version = env ! ( "CARGO_PKG_VERSION" ) ;
7
+
8
+ // Define the paths to `Cargo.toml`
9
+ let cargo_toml_path = "Cargo.toml" ;
10
+
11
+ // Read `Cargo.toml`
12
+ let content = fs:: read_to_string ( cargo_toml_path) . expect ( "Failed to read Cargo.toml" ) ;
13
+
14
+ // Replace `version = ...` only within `[package.metadata.bundle]` and `[package.metadata.wix]`
15
+ let updated_content = content
16
+ . lines ( )
17
+ . map ( |line| {
18
+ if line. trim_start ( ) . starts_with ( "version =" ) {
19
+ // Check if we're inside the relevant sections
20
+ if content. contains ( "[package.metadata.bundle]" )
21
+ || content. contains ( "[package.metadata.wix]" )
22
+ {
23
+ format ! ( r#"version = "{}""# , version)
24
+ } else {
25
+ line. to_string ( )
26
+ }
27
+ } else {
28
+ line. to_string ( )
29
+ }
30
+ } )
31
+ . collect :: < Vec < _ > > ( )
32
+ . join ( "\n " ) ;
33
+
34
+ // Write the updated content back to `Cargo.toml`
35
+ fs:: write ( cargo_toml_path, updated_content) . expect ( "Failed to write updated Cargo.toml" ) ;
36
+
37
+ println ! ( "cargo:rerun-if-changed={}" , cargo_toml_path) ;
3
38
}
You can’t perform that action at this time.
0 commit comments