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
use xassembler::{compile, Target}; pub trait Compile: Target { const BUILD_DIR_NAME: &'static str; const PRELUDE: &'static str; const TERMINATE: &'static str; fn compile_subcommand(compiled: &str, dependeny_paths: Vec<&str>, output_path: &str) -> Result<(), String>; fn run_subcommand(compiled: &str, dependeny_paths: Vec<&str>) -> Result<(), String>; fn build(compiled: &str, dependeny_paths: Vec<&str>) -> Result<(), String>; fn assemble(script: &str) -> Result<String, String> where Self: Sized, { Ok(format!( "{} {} {}", Self::PRELUDE, compile::<Self>(script)?, Self::TERMINATE )) } fn home_dir() -> Result<String, String> { let home = dirs::home_dir().ok_or_else(|| String::from("No home directory in this environment"))?; Ok(home .to_str() .ok_or_else(|| String::from("No home directory in this environment"))? .to_string()) } fn build_dir() -> Result<String, String> { Ok(Self::home_dir()? + "/" + Self::BUILD_DIR_NAME) } }