Compare commits
2 Commits
v1.1.0
...
99722302a2
| Author | SHA1 | Date | |
|---|---|---|---|
| 99722302a2 | |||
| a4b7a4d909 |
97
src/app.rs
97
src/app.rs
@@ -95,7 +95,9 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Subcommand::Init => {
|
Subcommand::Init => {
|
||||||
if let Err(e) = create_project(".") {
|
let root = std::env::current_dir().expect("the current working directory");
|
||||||
|
let path = root.file_name().expect("some file name");
|
||||||
|
if let Err(e) = create_project(path.to_string_lossy().to_string()) {
|
||||||
eprintln!("Error initializing project: {e}");
|
eprintln!("Error initializing project: {e}");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
@@ -186,7 +188,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 +278,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)?;
|
||||||
|
|
||||||
@@ -381,45 +383,43 @@ 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")
|
{
|
||||||
.arg("--cflags")
|
let cflags = Command::new("pkg-config")
|
||||||
.args(deps)
|
.arg("--cflags")
|
||||||
.output()
|
.args(deps)
|
||||||
.map_err(|_| {
|
.output()
|
||||||
std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found")
|
.map_err(|_| {
|
||||||
})?;
|
std::io::Error::new(std::io::ErrorKind::NotFound, "pkg-config not found")
|
||||||
if !cflags.status.success() {
|
})?;
|
||||||
return Err(std::io::Error::new(
|
if !cflags.status.success() {
|
||||||
std::io::ErrorKind::Other,
|
return Err(std::io::Error::other(
|
||||||
"pkg-config --cflags failed - is the package installed?",
|
"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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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<PathBuf> = glob("src/*.c")
|
let source_files: Vec<PathBuf> = glob("src/*.c")
|
||||||
@@ -455,10 +455,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 +493,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",
|
||||||
|
|||||||
Reference in New Issue
Block a user