generated from shadow3aaa/magisk-module-template-rs
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.rs
67 lines (57 loc) · 2.12 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Copyright 2023 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */
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(())
}