mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-12 14:55:20 +00:00
Move project common code into include
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use crate::gen::gen_cxx_binding;
|
||||
|
||||
#[path = "../include/gen.rs"]
|
||||
mod gen;
|
||||
|
||||
fn main() {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
// We expose constant values as macros so that all constants are literals
|
||||
// An advantage for doing this is that we can use concat!() on these values
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! LOGFILE {
|
||||
() => {
|
||||
"/cache/magisk.log"
|
||||
};
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
// This file hosts shared build script logic
|
||||
|
||||
use std::fmt::Display;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use std::{fs, io, process};
|
||||
|
||||
use cxx_gen::Opt;
|
||||
|
||||
trait ResultExt<T> {
|
||||
fn ok_or_exit(self) -> T;
|
||||
}
|
||||
|
||||
impl<T, E: Display> ResultExt<T> for Result<T, E> {
|
||||
fn ok_or_exit(self) -> T {
|
||||
match self {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
eprintln!("error occurred: {}", e);
|
||||
process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn write_if_diff<P: AsRef<Path>>(path: P, bytes: &[u8]) -> io::Result<()> {
|
||||
let path = path.as_ref();
|
||||
if let Ok(orig) = fs::read(path) {
|
||||
// Do not modify the file if content is the same to make incremental build more optimal
|
||||
if orig.as_slice() == bytes {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let mut f = File::create(path)?;
|
||||
f.write_all(bytes)
|
||||
}
|
||||
|
||||
pub fn gen_cxx_binding(name: &str) {
|
||||
println!("cargo:rerun-if-changed=lib.rs");
|
||||
let opt = Opt::default();
|
||||
let gen = cxx_gen::generate_header_and_cc_with_path("lib.rs", &opt);
|
||||
write_if_diff(format!("{}.cpp", name), gen.implementation.as_slice()).ok_or_exit();
|
||||
write_if_diff(format!("{}.hpp", name), gen.header.as_slice()).ok_or_exit();
|
||||
}
|
||||
@@ -2,13 +2,11 @@
|
||||
|
||||
pub use libc;
|
||||
|
||||
pub use consts::*;
|
||||
pub use files::*;
|
||||
pub use logging::*;
|
||||
pub use misc::*;
|
||||
pub use xwrap::*;
|
||||
|
||||
mod consts;
|
||||
mod files;
|
||||
mod logging;
|
||||
mod misc;
|
||||
|
||||
Reference in New Issue
Block a user