-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
43 lines (35 loc) · 1.14 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
34
35
36
37
38
39
40
41
42
43
use std::fs::OpenOptions;
use std::io::{BufRead, Write};
fn main() {
update_readme();
}
fn update_readme() {
println!("cargo:rerun-if-changed=Cargo.toml");
let version = env!("CARGO_PKG_VERSION");
let mut lines = {
std::io::BufReader::new(
OpenOptions::new()
.read(true)
.open("README.md")
.expect("Failed to open README.md for reading"),
)
.lines()
.map(|l| l.expect("Failed to read a particular line in README.md, aborting"))
.collect::<Vec<String>>()
};
let version_str = format!("# eilang {}", version);
if lines.first().unwrap() == &version_str {
return;
}
*lines.get_mut(0).unwrap() = version_str;
let lines = lines.join("\n");
let readme = OpenOptions::new()
.write(true)
.open("README.md")
.expect("Failed to open README.md for writing");
let mut readme_writer = std::io::LineWriter::new(readme);
readme_writer
.write_all(lines.as_bytes())
.expect("Failed to write all lines to README.md");
readme_writer.flush().expect("Failed to flush README.md");
}