forked from Cutieguwu/raven
Fix pathing issues.
This commit is contained in:
31
src/main.rs
31
src/main.rs
@@ -17,14 +17,6 @@ use nest::{Class, NEST, NestLock};
|
||||
use anyhow::Context;
|
||||
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(|| {
|
||||
// Start from CWD
|
||||
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
|
||||
});
|
||||
|
||||
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<()> {
|
||||
// Ensure that Nest.toml exists, if the requested command depends upon it.
|
||||
if CONFIG.command.depends_on_nest() && NEST.is_err() {
|
||||
@@ -91,11 +91,7 @@ fn init() -> anyhow::Result<()> {
|
||||
.context("Unable to convert OsStr to str")?
|
||||
.to_owned();
|
||||
|
||||
// Make src, target, tests
|
||||
for dir in [DIR_SRC, DIR_MAIN, DIR_TARGET, DIR_TEST] {
|
||||
std::fs::create_dir_all(dir.clone())?;
|
||||
}
|
||||
|
||||
// ORDER MATTERS. THIS MUST COME FIRST.
|
||||
// Make config file.
|
||||
if let Result::Ok(mut f) = OpenOptions::new()
|
||||
.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
|
||||
if let Result::Ok(mut f) = OpenOptions::new().write(true).create_new(is_empty).open(
|
||||
DIR_MAIN
|
||||
@@ -254,7 +255,7 @@ fn test(assertions: bool) -> anyhow::Result<(Option<String>, Option<String>)> {
|
||||
.compile(DIR_TEST.as_path())?;
|
||||
|
||||
// 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()
|
||||
.assertions(assertions)
|
||||
@@ -267,5 +268,5 @@ fn test(assertions: bool) -> anyhow::Result<(Option<String>, Option<String>)> {
|
||||
|
||||
fn clean() {
|
||||
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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user