Fix Pallet Init #23

Merged
sfrembling merged 4 commits from working/#22 into main 2026-03-23 15:30:47 -06:00

View File

@@ -186,7 +186,7 @@ impl App {
fn add_package(package: &str) -> std::io::Result<()> { fn add_package(package: &str) -> std::io::Result<()> {
let status = Command::new("pkg-config") let status = Command::new("pkg-config")
.arg("--exists") .arg("--exists")
.arg(&package) .arg(package)
.status() .status()
.map_err(|_| { .map_err(|_| {
std::io::Error::new( std::io::Error::new(
@@ -276,7 +276,7 @@ fn gen_compile_commands(mode: &Option<String>) -> std::io::Result<()> {
.collect(); .collect();
let json = serde_json::to_string_pretty(&entries) 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)?; std::fs::write("compile_commands.json", json)?;
@@ -330,7 +330,19 @@ fn create_project<P: AsRef<Path>>(directory: P) -> std::io::Result<()> {
std::fs::write("src/main.c", MAIN_C)?; std::fs::write("src/main.c", MAIN_C)?;
std::fs::write(".gitignore", GITIGNORE)?; 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"); let serial = toml::to_string_pretty(&config).expect("a valid TOML structure");
@@ -381,8 +393,9 @@ fn build(mode: &Option<String>, force_recompile: bool) -> std::io::Result<()> {
let mut extra_compile_flags: Vec<String> = Vec::new(); let mut extra_compile_flags: Vec<String> = Vec::new();
let mut extra_link_flags: Vec<String> = Vec::new(); let mut extra_link_flags: Vec<String> = Vec::new();
if let Some(deps) = &conf.dependencies { if let Some(deps) = &conf.dependencies
if !deps.is_empty() { && !deps.is_empty()
{
let cflags = Command::new("pkg-config") let cflags = Command::new("pkg-config")
.arg("--cflags") .arg("--cflags")
.args(deps) .args(deps)
@@ -391,8 +404,7 @@ fn build(mode: &Option<String>, force_recompile: bool) -> std::io::Result<()> {
std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found") std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found")
})?; })?;
if !cflags.status.success() { if !cflags.status.success() {
return Err(std::io::Error::new( return Err(std::io::Error::other(
std::io::ErrorKind::Other,
"pkg-config --cflags failed - is the package installed?", "pkg-config --cflags failed - is the package installed?",
)); ));
} }
@@ -405,8 +417,7 @@ fn build(mode: &Option<String>, force_recompile: bool) -> std::io::Result<()> {
std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found") std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found")
})?; })?;
if !libs.status.success() { if !libs.status.success() {
return Err(std::io::Error::new( return Err(std::io::Error::other(
std::io::ErrorKind::Other,
"pkg-config --libs failed - is the pacakge installed?", "pkg-config --libs failed - is the pacakge installed?",
)); ));
} }
@@ -420,7 +431,6 @@ fn build(mode: &Option<String>, force_recompile: bool) -> std::io::Result<()> {
.map(str::to_owned) .map(str::to_owned)
.collect(); .collect();
} }
}
let source_files: Vec<PathBuf> = glob("src/*.c") let source_files: Vec<PathBuf> = glob("src/*.c")
.map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, format!("{e}")))? .map_err(|e| std::io::Error::new(std::io::ErrorKind::NotFound, format!("{e}")))?
@@ -455,10 +465,10 @@ fn build(mode: &Option<String>, force_recompile: bool) -> std::io::Result<()> {
.status()?; .status()?;
if !status.success() { if !status.success() {
return Err(std::io::Error::new( return Err(std::io::Error::other(format!(
std::io::ErrorKind::Other, "failed to compile {}",
format!("failed to compile {}", src.display()), src.display()
)); )));
} }
std::fs::write(&hash_path, &hash)?; std::fs::write(&hash_path, &hash)?;
@@ -493,15 +503,12 @@ fn build(mode: &Option<String>, force_recompile: bool) -> std::io::Result<()> {
.status()?; .status()?;
if !status.success() { if !status.success() {
return Err(std::io::Error::new( return Err(std::io::Error::other("linking failed"));
std::io::ErrorKind::Other,
"linking failed",
));
} }
let stop = start.elapsed(); let stop = start.elapsed();
gen_compile_commands(&mode)?; gen_compile_commands(mode)?;
println!( println!(
" {} '{}' profile for project '{}' in {:.2}s", " {} '{}' profile for project '{}' in {:.2}s",