i dont know

This commit is contained in:
Guilleag01
2025-08-07 20:51:30 +02:00
parent e9b9cefff1
commit 73ac38b414
2 changed files with 38 additions and 55 deletions

View File

@@ -67,13 +67,7 @@ impl Compiler {
let mkdir_command = format!("mkdir -p {}", c_path_full.to_str().unwrap()); let mkdir_command = format!("mkdir -p {}", c_path_full.to_str().unwrap());
Command::new("sh") self.run_command(mkdir_command, verbose);
.arg("-c")
.arg(mkdir_command)
.output()
.unwrap();
// TODO: PRINT WHEN VERBOSE
let command = format!( let command = format!(
"{} {} -c {} {} -o {}", "{} {} -c {} {} -o {}",
@@ -84,23 +78,9 @@ impl Compiler {
o_path_strip o_path_strip
); );
if verbose {
println!("{command}");
}
o_s.push(o_path_strip.to_string()); o_s.push(o_path_strip.to_string());
let out = Command::new("sh").arg("-c").arg(command).output().unwrap(); self.run_command(command, verbose);
let stdout = std::str::from_utf8(&out.stdout).unwrap();
let stderr = std::str::from_utf8(&out.stderr).unwrap();
if !stdout.is_empty() {
println!("{stdout}");
}
if !stderr.is_empty() {
println!("{stderr}");
}
} }
let mut link_command = format!( let mut link_command = format!(
@@ -122,27 +102,9 @@ impl Compiler {
target_path.to_str().unwrap() target_path.to_str().unwrap()
); );
println!("Building {}", target_path.to_str().unwrap()); println!(" Building {}", target_path.to_str().unwrap());
if verbose { self.run_command(link_command, verbose);
println!("{link_command}");
}
let out = Command::new("sh")
.arg("-c")
.arg(link_command)
.output()
.unwrap();
let stdout = std::str::from_utf8(&out.stdout).unwrap();
let stderr = std::str::from_utf8(&out.stderr).unwrap();
if !stdout.is_empty() {
println!("{stdout}");
}
if !stderr.is_empty() {
println!("{stderr}");
}
} }
pub fn get_needed_files(&self) -> (Vec<String>, Vec<String>) { pub fn get_needed_files(&self) -> (Vec<String>, Vec<String>) {
@@ -178,7 +140,7 @@ impl Compiler {
.unwrap_or_else(|_| panic!("Couldn't read {}", file_path.to_str().unwrap())); .unwrap_or_else(|_| panic!("Couldn't read {}", file_path.to_str().unwrap()));
lazy_static! { lazy_static! {
static ref RE: Regex = Regex::new(r#"#include (<\w+.h>|\"\w+\.h\")"#).unwrap(); static ref RE: Regex = Regex::new(r#"#include (<(\w/?)+.h>|\"(\w/?)+\.h\")"#).unwrap();
} }
let mut header_paths: HashSet<String> = HashSet::new(); let mut header_paths: HashSet<String> = HashSet::new();
@@ -218,11 +180,15 @@ impl Compiler {
// let mut scanned_files = Vec::new(); // let mut scanned_files = Vec::new();
for find in finds.clone() { for find in finds.clone() {
// println!("{find:?}");
// let find_name = fin[10..find.len() - 1].to_string(); // let find_name = fin[10..find.len() - 1].to_string();
if headers_names.contains(&find) { if headers_names.contains(&find.split("/").last().unwrap().to_string()) {
let h_path = path::Path::new( let h_path = path::Path::new(
self.header_files[headers_names.iter().position(|e| *e == find).unwrap()] self.header_files[headers_names
.iter()
.position(|e| *e == find.split("/").last().unwrap())
.unwrap()]
.as_str(), .as_str(),
); );
@@ -281,20 +247,19 @@ impl Compiler {
pub fn clean(&self) { pub fn clean(&self) {
let build_dir = path::Path::new(&self.path).join(self.config.build.build_dir.clone()); let build_dir = path::Path::new(&self.path).join(self.config.build.build_dir.clone());
let target_path = path::Path::new(&self.path).join(self.config.general.target.clone()); let target_path = path::Path::new(&self.path).join(self.config.general.target.clone());
println!("Removing dir {}", build_dir.to_str().unwrap()); println!(" Removing dir {}", build_dir.to_str().unwrap());
fs::remove_dir_all(build_dir).unwrap(); fs::remove_dir_all(build_dir).unwrap();
println!("Removing file {}", target_path.to_str().unwrap()); println!("Removing file {}", target_path.to_str().unwrap());
fs::remove_file(target_path).unwrap(); fs::remove_file(target_path).unwrap();
} }
pub fn run(&self) { pub fn run(&self, verbose: bool) {
let target_path = path::Path::new(&self.path).join(self.config.general.target.clone()); let target_path = path::Path::new(&self.path).join(self.config.general.target.clone());
println!("Running {}", target_path.to_str().unwrap()); println!(" Running {}", target_path.to_str().unwrap());
Command::new("sh")
.arg("-c") let command = format!("./{}", target_path.to_str().unwrap());
.arg(format!("./{}", target_path.to_str().unwrap()).as_str())
.output() self.run_command(command, verbose);
.unwrap();
} }
fn get_inc_string(&self) -> String { fn get_inc_string(&self) -> String {
@@ -306,4 +271,22 @@ impl Compiler {
inc_string inc_string
} }
fn run_command(&self, command: String, verbose: bool) {
if verbose {
println!("{command}");
}
let out = Command::new("sh").arg("-c").arg(command).output().unwrap();
let stdout = std::str::from_utf8(&out.stdout).unwrap();
let stderr = std::str::from_utf8(&out.stderr).unwrap();
if !stdout.is_empty() {
println!("{stdout}");
}
if !stderr.is_empty() {
println!("{stderr}");
}
}
} }

View File

@@ -75,7 +75,7 @@ fn main() {
Modes::Run => { Modes::Run => {
compiler.prepare(); compiler.prepare();
compiler.compile(args.verbose); compiler.compile(args.verbose);
compiler.run(); compiler.run(args.verbose);
} }
Modes::Init => { Modes::Init => {
init::init(args.path); init::init(args.path);