forked from KarlitosVII/trilogy-save-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
33 lines (27 loc) · 1.24 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::fs;
use regex::Regex;
fn main() {
// app/Cargo.toml
const APP_CARGO_PATH: &str = "app/Cargo.toml";
let mut app_cargo = fs::read_to_string(APP_CARGO_PATH).expect(APP_CARGO_PATH);
// version = "*"
let regex = Regex::new(r#"(?m)^\s*version\s*=\s*"([\d.]+)"\s*$"#).unwrap();
let captures = regex.captures(&app_cargo).expect("regex doesn't match");
if &captures[1] != env!("CARGO_PKG_VERSION") {
let range = captures.get(1).unwrap().range();
app_cargo.replace_range(range, env!("CARGO_PKG_VERSION"));
fs::write(APP_CARGO_PATH, app_cargo).unwrap();
}
// InnoSetup.iss
const INNO_SETUP_PATH: &str = "InnoSetup.iss";
let mut inno_setup = fs::read_to_string(INNO_SETUP_PATH).expect(INNO_SETUP_PATH);
// #define AppVersion "*"
let regex = Regex::new(r#"(?m)^\s*#define\s+AppVersion\s+"([\d.]+)"\s*$"#).unwrap();
let captures = regex.captures(&inno_setup).expect("regex doesn't match");
if &captures[1] != env!("CARGO_PKG_VERSION") {
let range = captures.get(1).unwrap().range();
inno_setup.replace_range(range, env!("CARGO_PKG_VERSION"));
fs::write(INNO_SETUP_PATH, inno_setup).unwrap();
}
println!("cargo:rerun-if-env-changed=CARGO_PKG_VERSION");
}