several bugs with new include system fixed
This commit is contained in:
		
							parent
							
								
									4ce746e845
								
							
						
					
					
						commit
						70b7b7912b
					
				
					 3 changed files with 32 additions and 16 deletions
				
			
		
							
								
								
									
										7
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										7
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -122,9 +122,16 @@ name = "mgen"
 | 
			
		|||
version = "0.1.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "clap",
 | 
			
		||||
 "path-clean",
 | 
			
		||||
 "regex",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "path-clean"
 | 
			
		||||
version = "1.0.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "proc-macro2"
 | 
			
		||||
version = "1.0.70"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,4 +7,5 @@ edition = "2021"
 | 
			
		|||
 | 
			
		||||
[dependencies]
 | 
			
		||||
clap = { version = "4.4.10", features = ["derive"] }
 | 
			
		||||
path-clean = "1.0.1"
 | 
			
		||||
regex = "1.10.2"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										40
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								src/main.rs
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -4,6 +4,7 @@ use std::fs::{self, DirEntry};
 | 
			
		|||
 | 
			
		||||
use regex::Regex;
 | 
			
		||||
use clap::Parser;
 | 
			
		||||
use path_clean::PathClean;
 | 
			
		||||
 | 
			
		||||
const START_KEY: &str = "#=mgen_start=#\n";
 | 
			
		||||
const END_KEY: &str = "#=mgen_end=#";
 | 
			
		||||
| 
						 | 
				
			
			@ -61,31 +62,32 @@ impl BuildRule {
 | 
			
		|||
 | 
			
		||||
        let includes_regex = Regex::new(r#"#include\s+"(.*?)""#).unwrap();
 | 
			
		||||
        let caps = includes_regex.captures_iter(&file_contents);
 | 
			
		||||
        for (_, [include_file]) in caps.map(|c| c.extract()) {
 | 
			
		||||
            match file_dir.join(PathBuf::from(include_file)).canonicalize() {
 | 
			
		||||
                Ok(path) => {
 | 
			
		||||
        'fileloop: for (_, [include_file]) in caps.map(|c| c.extract()) {
 | 
			
		||||
            let path = file_dir.join(PathBuf::from(include_file)).clean();
 | 
			
		||||
            match path.exists() {
 | 
			
		||||
                true => {
 | 
			
		||||
                    headers.push(String::from(path.to_str().unwrap()));
 | 
			
		||||
                    println!("e {:?}", path);
 | 
			
		||||
                    continue;
 | 
			
		||||
                },
 | 
			
		||||
                Err(_) => (),
 | 
			
		||||
                false => println!("n {:?}", path),
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            let mut done = false;
 | 
			
		||||
            for dir in makefile.include_dirs.iter() {
 | 
			
		||||
                let dir = PathBuf::from(&dir);
 | 
			
		||||
                match dir.join(PathBuf::from(include_file)).canonicalize() {
 | 
			
		||||
                    Ok(path) => {
 | 
			
		||||
                let path = dir.join(PathBuf::from(include_file)).clean();
 | 
			
		||||
                match path.exists() {
 | 
			
		||||
                    true => {
 | 
			
		||||
                        headers.push(String::from(path.to_str().unwrap()));
 | 
			
		||||
                        done = true;
 | 
			
		||||
                        break;
 | 
			
		||||
                        println!("e {:?}", path);
 | 
			
		||||
                        continue 'fileloop;
 | 
			
		||||
                    },
 | 
			
		||||
                    Err(_) => (),
 | 
			
		||||
                    false => println!("n {:?}", path),
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if done {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            let path = file_dir.join(PathBuf::from(include_file));
 | 
			
		||||
            println!("t {:?}", path);
 | 
			
		||||
            headers.push(String::from(path.to_str().unwrap()));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -178,19 +180,25 @@ impl Makefile {
 | 
			
		|||
    fn get_include_dirs(search: &String) -> Vec<String> {
 | 
			
		||||
        let mut include_dirs: Vec<String> = Vec::new();
 | 
			
		||||
 | 
			
		||||
        let makefile_regex = Regex::new(r"^INCS\s*=\s*(.*?)$").unwrap();
 | 
			
		||||
        let makefile_regex = Regex::new(r"INCS\s*=\s*(.*)").unwrap();
 | 
			
		||||
        let caps = makefile_regex.captures_iter(search);
 | 
			
		||||
        let dirlist = match caps.map(|c| c.extract()).last() {
 | 
			
		||||
            Some((_, [v])) => v,
 | 
			
		||||
            None => return include_dirs,
 | 
			
		||||
            None => {
 | 
			
		||||
                return include_dirs
 | 
			
		||||
            }
 | 
			
		||||
            ,
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        let incdir_regex = Regex::new(r"-s*-I\s*(.*?)\s*").unwrap();
 | 
			
		||||
 | 
			
		||||
        let incdir_regex = Regex::new(r"\s*-I\s*(.*?)(?:[\s]|$)").unwrap();
 | 
			
		||||
        let caps = incdir_regex.captures_iter(&dirlist);
 | 
			
		||||
        for (_, [dir]) in caps.map(|c| c.extract()) {
 | 
			
		||||
            include_dirs.push(String::from(dir));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        println!("{:?}", include_dirs);
 | 
			
		||||
 | 
			
		||||
        include_dirs
 | 
			
		||||
    }
 | 
			
		||||
        
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue