-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
54 lines (44 loc) · 1.54 KB
/
build.rs
File metadata and controls
54 lines (44 loc) · 1.54 KB
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
44
45
46
47
48
49
50
51
52
53
54
use std::{error::Error, fs, io::Write};
use serde_derive::Deserialize;
#[derive(Deserialize, Debug)]
struct Package {
pub authors: Vec<String>,
pub name: String,
pub version: String,
pub description: String,
}
#[derive(Deserialize)]
struct TomlData {
pub package: Package,
}
fn main() -> Result<(), Box<dyn Error>> {
println!("cargo:rerun-if-changed=README.md");
println!("cargo:rerun-if-changed=Cargo.lock");
println!("cargo:rerun-if-changed=Cargo.toml");
println!("cargo:rerun-if-changed=LICENSE");
let toml = fs::read_to_string("Cargo.toml")?;
let data: TomlData = toml::from_str(&toml)?;
let package = data.package;
let id = package.name.replace('-', "_"); // 符合magisk module id要求
let version_code: usize = package.version.replace('.', "").trim().parse()?; // 转为纯数字版本
let authors = package.authors;
let mut author = String::new();
for a in authors {
author = format!("{author}{a} ");
}
let author = author.trim();
let mut file = fs::OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open("module/module.prop")?;
writeln!(file, "id={id}")?;
writeln!(file, "name={}", package.name)?;
writeln!(file, "version=v{}", package.version)?;
writeln!(file, "versionCode={version_code}")?;
writeln!(file, "author={author}")?;
writeln!(file, "description={}", package.description)?;
let _ = fs::remove_file("module/README.md");
fs::copy("README.md", "module/README.md")?;
Ok(())
}