diff --git a/src/app.rs b/src/app.rs index 8d251f4..e996456 100644 --- a/src/app.rs +++ b/src/app.rs @@ -186,7 +186,7 @@ impl App { fn add_package(package: &str) -> std::io::Result<()> { let status = Command::new("pkg-config") .arg("--exists") - .arg(&package) + .arg(package) .status() .map_err(|_| { std::io::Error::new( @@ -276,7 +276,7 @@ fn gen_compile_commands(mode: &Option) -> std::io::Result<()> { .collect(); let json = serde_json::to_string_pretty(&entries) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, format!("{e}")))?; + .map_err(|e| std::io::Error::other(format!("{e}")))?; std::fs::write("compile_commands.json", json)?; @@ -330,7 +330,19 @@ fn create_project>(directory: P) -> std::io::Result<()> { std::fs::write("src/main.c", MAIN_C)?; std::fs::write(".gitignore", GITIGNORE)?; - let config = crate::config::Config::new(&pathdir.to_string_lossy()); + let lossy = pathdir.to_string_lossy(); + + let app_name = if lossy == "." { + let root = std::env::current_dir()?; + root.file_name() + .expect("a valid file name") + .to_string_lossy() + .to_string() + } else { + lossy.to_string() + }; + + let config = crate::config::Config::new(&app_name); let serial = toml::to_string_pretty(&config).expect("a valid TOML structure"); @@ -381,45 +393,43 @@ fn build(mode: &Option, force_recompile: bool) -> std::io::Result<()> { let mut extra_compile_flags: Vec = Vec::new(); let mut extra_link_flags: Vec = Vec::new(); - if let Some(deps) = &conf.dependencies { - if !deps.is_empty() { - let cflags = Command::new("pkg-config") - .arg("--cflags") - .args(deps) - .output() - .map_err(|_| { - std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found") - })?; - if !cflags.status.success() { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - "pkg-config --cflags failed - is the package installed?", - )); - } - - let libs = Command::new("pkg-config") - .arg("--libs") - .args(deps) - .output() - .map_err(|_| { - std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found") - })?; - if !libs.status.success() { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - "pkg-config --libs failed - is the pacakge installed?", - )); - } - - extra_compile_flags = String::from_utf8_lossy(&cflags.stdout) - .split_whitespace() - .map(str::to_owned) - .collect(); - extra_link_flags = String::from_utf8_lossy(&libs.stdout) - .split_whitespace() - .map(str::to_owned) - .collect(); + if let Some(deps) = &conf.dependencies + && !deps.is_empty() + { + let cflags = Command::new("pkg-config") + .arg("--cflags") + .args(deps) + .output() + .map_err(|_| { + std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found") + })?; + if !cflags.status.success() { + return Err(std::io::Error::other( + "pkg-config --cflags failed - is the package installed?", + )); } + + let libs = Command::new("pkg-config") + .arg("--libs") + .args(deps) + .output() + .map_err(|_| { + std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found") + })?; + if !libs.status.success() { + return Err(std::io::Error::other( + "pkg-config --libs failed - is the pacakge installed?", + )); + } + + extra_compile_flags = String::from_utf8_lossy(&cflags.stdout) + .split_whitespace() + .map(str::to_owned) + .collect(); + extra_link_flags = String::from_utf8_lossy(&libs.stdout) + .split_whitespace() + .map(str::to_owned) + .collect(); } let source_files: Vec = glob("src/*.c") @@ -455,10 +465,10 @@ fn build(mode: &Option, force_recompile: bool) -> std::io::Result<()> { .status()?; if !status.success() { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - format!("failed to compile {}", src.display()), - )); + return Err(std::io::Error::other(format!( + "failed to compile {}", + src.display() + ))); } std::fs::write(&hash_path, &hash)?; @@ -493,15 +503,12 @@ fn build(mode: &Option, force_recompile: bool) -> std::io::Result<()> { .status()?; if !status.success() { - return Err(std::io::Error::new( - std::io::ErrorKind::Other, - "linking failed", - )); + return Err(std::io::Error::other("linking failed")); } let stop = start.elapsed(); - gen_compile_commands(&mode)?; + gen_compile_commands(mode)?; println!( " {} '{}' profile for project '{}' in {:.2}s",