Compare commits
2 Commits
f6a6d54992
...
aa851f7616
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa851f7616 | ||
|
|
dafc6ea885 |
16
Cargo.toml
16
Cargo.toml
@@ -2,23 +2,27 @@
|
|||||||
name = "raven"
|
name = "raven"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
authors = ["Olivia Brooks", "Adrian Long"]
|
||||||
|
repository = "https://gitea.cutieguwu.ca/Cutieguwu/raven"
|
||||||
|
license = "MIT"
|
||||||
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
bytesize = "2.3"
|
bytesize = "2.3"
|
||||||
ron = "0.12"
|
ron = "0.12"
|
||||||
sha256 = "1.6.0"
|
sha256 = "1.6"
|
||||||
subprocess = "0.2"
|
subprocess = "0.2"
|
||||||
toml = "0.9"
|
toml = "0.9"
|
||||||
|
|
||||||
[dependencies.serde]
|
|
||||||
version = "1.0"
|
|
||||||
features =["derive"]
|
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
version = "4.5"
|
version = "4.5"
|
||||||
features = ["derive"]
|
features = ["cargo", "derive"]
|
||||||
|
|
||||||
[dependencies.semver]
|
[dependencies.semver]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
features = ["serde"]
|
features = ["serde"]
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
version = "1.0"
|
||||||
|
features =["derive"]
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ use clap::{ArgAction, Parser, Subcommand};
|
|||||||
pub static CONFIG: LazyLock<Args> = LazyLock::new(|| Args::parse());
|
pub static CONFIG: LazyLock<Args> = LazyLock::new(|| Args::parse());
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
|
#[clap(author, version)]
|
||||||
|
#[command(help_template = "{author-section}\n{usage-heading} {usage}\n\n{all-args}")]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
pub command: Command,
|
pub command: Command,
|
||||||
|
|||||||
31
src/main.rs
31
src/main.rs
@@ -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());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user