Compare commits

..

12 Commits

Author SHA1 Message Date
Olivia Brooks
54e6350d42 Code cleanup. 2026-01-27 22:01:41 -05:00
Olivia Brooks
f3f79a12df Zed mucked something up with the merge. Fix it. 2026-01-27 21:32:18 -05:00
Olivia Brooks
649507bbcb Fix build; Correct target/ path in generated .gitignore 2026-01-27 21:30:45 -05:00
676b0b606b Merge pull request 'fix: raven test' (#2) from AdrianLong/raven:master into master
Reviewed-on: #2
2026-01-27 16:33:41 -05:00
82b45d9c66 Removed Fence denugging statements 2026-01-27 14:09:30 -05:00
05390a8f0b Fixed raven test. The raven test system needs to be redesigned in order to run multiple different test classes. Cyclic dependencies cannot be resolved the curent build system so a parser needs to be implemented to get the import statements. 2026-01-27 13:47:57 -05:00
6da7586c3e Refactored assets to use propper java syntax. Found error in the raven test command. Impropper formating when passing arguments to the java command. 2026-01-27 13:47:57 -05:00
3deedb2f7f Fixed raven build to build from anywhere inside of a raven project. 2026-01-27 13:47:57 -05:00
Olivia Brooks
3db0f53943 Correct commands. 2026-01-27 06:15:03 -05:00
Olivia Brooks
b5c4f61c8a Use a bug tracker, instead of README. 2026-01-27 06:13:37 -05:00
Olivia Brooks
aa851f7616 Add clap version, authors; Update metadata. 2026-01-26 22:21:10 -05:00
Olivia Brooks
dafc6ea885 Fix pathing issues. 2026-01-26 21:51:15 -05:00
7 changed files with 76 additions and 52 deletions

View File

@@ -2,23 +2,27 @@
name = "raven"
version = "0.1.0"
edition = "2024"
authors = ["Olivia Brooks", "Adrian Long"]
repository = "https://gitea.cutieguwu.ca/Cutieguwu/raven"
license = "MIT"
publish = false
[dependencies]
anyhow = "1.0"
bytesize = "2.3"
ron = "0.12"
sha256 = "1.6.0"
sha256 = "1.6"
subprocess = "0.2"
toml = "0.9"
[dependencies.serde]
version = "1.0"
features =["derive"]
[dependencies.clap]
version = "4.5"
features = ["derive"]
features = ["cargo", "derive"]
[dependencies.semver]
version = "1.0"
features = ["serde"]
[dependencies.serde]
version = "1.0"
features =["derive"]

View File

@@ -32,15 +32,29 @@ cd demo
raven run main.Main
```
## Raven commands
Usage: raven <COMMAND>
Commands:
new Create a new raven project
init Create a new raven project in an existing directory
build Compile the current project
run Run the current project
test !!! BORKED !!! Run the tests
clean Remove the target directory and caching
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
## Future plans
- [ ] Fix `raven test`. Totally borked.
- [ ] Make `nest run` fall back to an entry point specified in Nest.toml, when
- [ ] Make `raven run` fall back to an entry point specified in Nest.toml, when
none provided.
- [ ] Fix project structure, eliminate inter-dependencies.
- [ ] Separate out `java.rs` into a dedicated wrapper library.
- [ ] Possibly add support for pulling remote packages via `nest add`. This
- [ ] Possibly add support for pulling remote packages via `raven add`. This
will be implemented should there arise a need.
- [ ] Wrap errors properly, instead of hap-hazardly using `anyhow`
- [ ] Maybe proper logging?
- [ ] Fix using hashes to avoid unnesscesary recompilation.

View File

@@ -1,5 +1,3 @@
package main;
public class Main {
public static void main(String[] args) {

View File

@@ -1,12 +1,10 @@
package test;
public class Main {
public class MainTest {
public static void main(String[] args) {
testAdd();
}
public static void testAdd() {
assert main.Main.add(2, 2) == 4;
assert Main.add(2, 2) == 4;
}
}

View File

@@ -5,6 +5,8 @@ use clap::{ArgAction, Parser, Subcommand};
pub static CONFIG: LazyLock<Args> = LazyLock::new(|| Args::parse());
#[derive(Debug, Parser)]
#[clap(author, version)]
#[command(help_template = "{author-section}\n{usage-heading} {usage}\n\n{all-args}")]
pub struct Args {
#[command(subcommand)]
pub command: Command,

View File

@@ -17,11 +17,15 @@ pub struct JVMBuilder {
monitor: bool,
ram_min: Option<ByteSize>,
ram_max: Option<ByteSize>,
class_path: PathBuf,
}
impl JVMBuilder {
pub fn new() -> Self {
Self::default()
pub fn new<P: AsRef<Path>>(class_path: P) -> Self {
Self {
class_path: class_path.as_ref().to_path_buf(),
..Default::default()
}
}
pub fn assertions(&mut self, assertions: bool) -> &mut Self {
@@ -46,7 +50,9 @@ impl JVMBuilder {
}
pub fn build(&self) -> JVM {
let mut flags = vec![];
let mut flags = vec![VMFlag::Classpath {
path: self.class_path.to_owned(),
}];
if self.assertions {
flags.push(VMFlag::EnableAssert);
@@ -85,7 +91,8 @@ impl JVM {
.into_iter()
.flat_map(|f| Into::<Vec<String>>::into(f)),
);
cmd.push(entry_point.as_ref().display().to_string());
cmd.push(entry_point.as_ref().to_path_buf().display().to_string());
let result = crate::io::run_process(cmd.as_slice());
@@ -110,6 +117,7 @@ impl JVM {
#[derive(Debug, Clone)]
pub enum VMFlag {
Classpath { path: PathBuf },
EnableAssert,
HeapMax { size: ByteSize },
HeapMin { size: ByteSize },
@@ -118,12 +126,10 @@ pub enum VMFlag {
impl Into<Vec<String>> for VMFlag {
fn into(self) -> Vec<String> {
match self {
Self::EnableAssert => vec![String::from("-ea")],
Self::HeapMax { size } => vec![format!("Xmx{}", size)],
Self::HeapMin { size } => vec![format!("Xms{}", size)],
Self::Version => vec![String::from("--version")],
}
self.to_string()
.split_ascii_whitespace()
.map(|s| s.to_string())
.collect()
}
}
@@ -135,9 +141,10 @@ impl fmt::Display for VMFlag {
f,
"-{}",
match self {
Self::Classpath { path } => format!("classpath {}", path.display()),
Self::EnableAssert => String::from("ea"),
Self::HeapMax { size } => format!("Xmx{}", size),
Self::HeapMin { size } => format!("Xms{}", size),
Self::HeapMax { size } => format!("Xmx{}", size.as_u64()),
Self::HeapMin { size } => format!("Xms{}", size.as_u64()),
Self::Version => String::from("-version"), // --version
}
)
@@ -213,14 +220,14 @@ impl Compiler {
#[derive(Debug, Clone)]
pub enum CompilerFlag {
Destination { path: PathBuf },
Classpath { path: PathBuf },
Destination { path: PathBuf },
}
impl Into<Vec<String>> for CompilerFlag {
fn into(self) -> Vec<String> {
match self {
Self::Classpath { path } => vec!["-cp".to_string(), path.display().to_string()],
Self::Classpath { path } => vec!["-classpath".to_string(), path.display().to_string()],
Self::Destination { path } => vec!["-d".to_string(), path.display().to_string()],
}
}

View File

@@ -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
@@ -139,14 +140,14 @@ fn init() -> anyhow::Result<()> {
f.write_all(include_bytes!("../assets/src/main/Main.java"))?;
}
// Make src/test/Main.java
// Make src/test/MainTest.java
if let Result::Ok(mut f) = OpenOptions::new().write(true).create_new(is_empty).open(
DIR_TEST
.clone()
.join("Main")
.join("MainTest")
.with_extension(JAVA_EXT_SOURCE),
) {
f.write_all(include_bytes!("../assets/src/test/Main.java"))?;
f.write_all(include_bytes!("../assets/src/test/MainTest.java"))?;
}
// git init .
@@ -163,7 +164,7 @@ fn init() -> anyhow::Result<()> {
f.read_to_string(&mut buf)?;
for ignored in [
DIR_TARGET.as_path().display().to_string(),
format!("{}/", DIR_TARGET.file_name().unwrap().display()),
format!("*.{}", JAVA_EXT_CLASS),
] {
if !buf.contains(&ignored) {
@@ -239,7 +240,7 @@ fn run<P: AsRef<Path>>(
// JRE pathing will be messed up without this.
crate::env::set_cwd(DIR_TARGET.as_path())?;
java::JVMBuilder::new()
java::JVMBuilder::new(DIR_TARGET.as_path())
.assertions(assertions)
.monitor(true)
.build()
@@ -254,18 +255,18 @@ 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()
java::JVMBuilder::new(DIR_TARGET.as_path())
.assertions(assertions)
.ram_min(ByteSize::mib(128))
.ram_max(ByteSize::mib(512))
.monitor(true)
.build()
.run(DIR_TEST.as_path())
.run(DIR_TARGET.as_path())
}
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());
}