Skip to content

Commit

Permalink
Add project path check (#380)
Browse files Browse the repository at this point in the history
Co-authored-by: Boppy <no-reply@boppygames.gg>
  • Loading branch information
Centril and Boppy authored Oct 8, 2023
1 parent a45c30c commit 2019bd2
Showing 1 changed file with 43 additions and 33 deletions.
76 changes: 43 additions & 33 deletions crates/cli/src/tasks/csharp.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
use duct::cmd;
use std::path::{Path, PathBuf};

pub(crate) fn build_csharp(project_path: &Path, _build_debug: bool) -> anyhow::Result<PathBuf> {
// NOTE: wasi.sdk does not currently optimize release

let output_path = project_path.join("bin/Release/net7.0/StdbModule.wasm");

// delete existing wasm file if exists
if output_path.exists() {
std::fs::remove_file(&output_path)?;
}

// run dotnet publish using cmd macro
let result = cmd!("dotnet", "publish", "-c", "Release").dir(project_path).run();
match result {
Ok(_) => {}
Err(error) => {
if error.kind() == std::io::ErrorKind::NotFound {
anyhow::bail!("Failed to build project. dotnet not found in path. Please install the .NET Core SDK.");
} else {
anyhow::bail!("Failed to build project. {}", error);
}
}
}

// check if file exists
if !output_path.exists() {
anyhow::bail!("Failed to build project");
}

Ok(output_path)
}
use anyhow::Context;
use duct::cmd;
use std::fs;
use std::path::{Path, PathBuf};

pub(crate) fn build_csharp(project_path: &Path, _build_debug: bool) -> anyhow::Result<PathBuf> {
// NOTE: wasi.sdk does not currently optimize release

let output_path = project_path.join("bin/Release/net7.0/StdbModule.wasm");

// delete existing wasm file if exists
if output_path.exists() {
std::fs::remove_file(&output_path)?;
}

// Ensure the project path exists.
fs::metadata(project_path).with_context(|| {
format!(
"The provided project path '{}' does not exist.",
project_path.to_str().unwrap()
)
})?;

// run dotnet publish using cmd macro
let result = cmd!("dotnet", "publish", "-c", "Release").dir(project_path).run();
match result {
Ok(_) => {}
Err(error) => {
if error.kind() == std::io::ErrorKind::NotFound {
anyhow::bail!("Failed to build project. dotnet not found in path. Please install the .NET Core SDK.");
} else {
anyhow::bail!("Failed to build project. {}", error);
}
}
}

// check if file exists
if !output_path.exists() {
anyhow::bail!("Failed to build project");
}

Ok(output_path)
}

0 comments on commit 2019bd2

Please sign in to comment.