Fix pathing issues.

This commit is contained in:
Olivia Brooks
2026-01-26 21:51:15 -05:00
parent f6a6d54992
commit dafc6ea885

View File

@@ -17,14 +17,6 @@ use nest::{Class, NEST, NestLock};
use anyhow::Context; use anyhow::Context;
use bytesize::ByteSize; use bytesize::ByteSize;
const DIR_TARGET: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("target/"));
const DIR_SRC: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("src/"));
const DIR_MAIN: LazyLock<PathBuf> = LazyLock::new(|| DIR_SRC.join("main/"));
const DIR_TEST: LazyLock<PathBuf> = LazyLock::new(|| DIR_SRC.join("test/"));
const F_NEST_TOML: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("Nest.toml"));
const F_NEST_LOCK: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("Nest.lock"));
pub static PROJECT_ROOT: LazyLock<PathBuf> = LazyLock::new(|| { pub static PROJECT_ROOT: LazyLock<PathBuf> = LazyLock::new(|| {
// Start from CWD // Start from CWD
let cwd = std::env::current_dir().expect("Failed to get current working directory"); let cwd = std::env::current_dir().expect("Failed to get current working directory");
@@ -44,6 +36,14 @@ pub static PROJECT_ROOT: LazyLock<PathBuf> = LazyLock::new(|| {
probe probe
}); });
const DIR_TARGET: LazyLock<PathBuf> = LazyLock::new(|| PROJECT_ROOT.join("target/"));
const DIR_SRC: LazyLock<PathBuf> = LazyLock::new(|| PROJECT_ROOT.join("src/"));
const DIR_MAIN: LazyLock<PathBuf> = LazyLock::new(|| DIR_SRC.join("main/"));
const DIR_TEST: LazyLock<PathBuf> = LazyLock::new(|| DIR_SRC.join("test/"));
const F_NEST_TOML: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("Nest.toml"));
const F_NEST_LOCK: LazyLock<PathBuf> = LazyLock::new(|| PathBuf::from("Nest.lock"));
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
// Ensure that Nest.toml exists, if the requested command depends upon it. // Ensure that Nest.toml exists, if the requested command depends upon it.
if CONFIG.command.depends_on_nest() && NEST.is_err() { if CONFIG.command.depends_on_nest() && NEST.is_err() {
@@ -91,11 +91,7 @@ fn init() -> anyhow::Result<()> {
.context("Unable to convert OsStr to str")? .context("Unable to convert OsStr to str")?
.to_owned(); .to_owned();
// Make src, target, tests // ORDER MATTERS. THIS MUST COME FIRST.
for dir in [DIR_SRC, DIR_MAIN, DIR_TARGET, DIR_TEST] {
std::fs::create_dir_all(dir.clone())?;
}
// Make config file. // Make config file.
if let Result::Ok(mut f) = OpenOptions::new() if let Result::Ok(mut f) = OpenOptions::new()
.write(true) .write(true)
@@ -129,6 +125,11 @@ fn init() -> anyhow::Result<()> {
)?; )?;
} }
// Make src, target, tests
for dir in [DIR_SRC, DIR_MAIN, DIR_TARGET, DIR_TEST] {
std::fs::create_dir_all(dir.clone())?;
}
// Make src/main/Main.java // Make src/main/Main.java
if let Result::Ok(mut f) = OpenOptions::new().write(true).create_new(is_empty).open( if let Result::Ok(mut f) = OpenOptions::new().write(true).create_new(is_empty).open(
DIR_MAIN DIR_MAIN
@@ -254,7 +255,7 @@ fn test(assertions: bool) -> anyhow::Result<(Option<String>, Option<String>)> {
.compile(DIR_TEST.as_path())?; .compile(DIR_TEST.as_path())?;
// Change cwd to avoid Java pathing issues. // Change cwd to avoid Java pathing issues.
crate::env::set_cwd(PROJECT_ROOT.join(DIR_TARGET.as_path()))?; crate::env::set_cwd(DIR_TARGET.as_path())?;
java::JVMBuilder::new() java::JVMBuilder::new()
.assertions(assertions) .assertions(assertions)
@@ -267,5 +268,5 @@ fn test(assertions: bool) -> anyhow::Result<(Option<String>, Option<String>)> {
fn clean() { fn clean() {
let _ = std::fs::remove_file(PROJECT_ROOT.join(F_NEST_LOCK.as_path())); let _ = std::fs::remove_file(PROJECT_ROOT.join(F_NEST_LOCK.as_path()));
let _ = std::fs::remove_dir_all(PROJECT_ROOT.join(DIR_TARGET.as_path())); let _ = std::fs::remove_dir_all(DIR_TARGET.join("/*").as_path());
} }