Compare commits

...

10 Commits

5 changed files with 48 additions and 31 deletions

View File

@@ -32,15 +32,29 @@ cd demo
raven run main.Main 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 ## Future plans
- [ ] Fix `raven test`. Totally borked. - [ ] Make `raven run` fall back to an entry point specified in Nest.toml, when
- [ ] Make `nest run` fall back to an entry point specified in Nest.toml, when
none provided. none provided.
- [ ] Fix project structure, eliminate inter-dependencies. - [ ] Fix project structure, eliminate inter-dependencies.
- [ ] Separate out `java.rs` into a dedicated wrapper library. - [ ] 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. will be implemented should there arise a need.
- [ ] Wrap errors properly, instead of hap-hazardly using `anyhow` - [ ] Wrap errors properly, instead of hap-hazardly using `anyhow`
- [ ] Maybe proper logging? - [ ] Maybe proper logging?
- [ ] Fix using hashes to avoid unnesscesary recompilation.

View File

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

View File

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

View File

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

View File

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