Compare commits
3 Commits
master
...
67381eb071
| Author | SHA1 | Date | |
|---|---|---|---|
| 67381eb071 | |||
| 7aea79c4fa | |||
| 27f784e1f0 |
@@ -50,11 +50,13 @@ Options:
|
|||||||
|
|
||||||
## Future plans
|
## Future plans
|
||||||
|
|
||||||
- [ ] Make `raven run` fall back to an entry point specified in Nest.toml, when
|
- [ ] Fix `raven test`. Totally borked.
|
||||||
|
- [ ] 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 `raven add`. This
|
- [ ] Possibly add support for pulling remote packages via `nest 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.
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
public class MainTest {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
testAdd();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void testAdd() {
|
|
||||||
assert Main.add(2, 2) == 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
44
src/java.rs
44
src/java.rs
@@ -17,15 +17,11 @@ 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<P: AsRef<Path>>(class_path: P) -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self::default()
|
||||||
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 {
|
||||||
@@ -50,9 +46,7 @@ impl JVMBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(&self) -> JVM {
|
pub fn build(&self) -> JVM {
|
||||||
let mut flags = vec![VMFlag::Classpath {
|
let mut flags = vec![];
|
||||||
path: self.class_path.to_owned(),
|
|
||||||
}];
|
|
||||||
|
|
||||||
if self.assertions {
|
if self.assertions {
|
||||||
flags.push(VMFlag::EnableAssert);
|
flags.push(VMFlag::EnableAssert);
|
||||||
@@ -85,6 +79,12 @@ impl JVM {
|
|||||||
) -> anyhow::Result<(Option<String>, Option<String>)> {
|
) -> anyhow::Result<(Option<String>, Option<String>)> {
|
||||||
let mut cmd = vec![JAVA_VM.to_string()];
|
let mut cmd = vec![JAVA_VM.to_string()];
|
||||||
|
|
||||||
|
println!("Fence 4");
|
||||||
|
|
||||||
|
// proper format
|
||||||
|
// java -Xms128m -Xmx512m -cp PROJECT_ROOT/src/text \test.Test
|
||||||
|
// current format
|
||||||
|
// java Xms128.0 MiB Xmx512.0 MiB /home/viffx/Coding/Rust/raven/src/Test1/src/test/
|
||||||
cmd.extend(
|
cmd.extend(
|
||||||
self.flags
|
self.flags
|
||||||
.clone()
|
.clone()
|
||||||
@@ -92,8 +92,21 @@ impl JVM {
|
|||||||
.flat_map(|f| Into::<Vec<String>>::into(f)),
|
.flat_map(|f| Into::<Vec<String>>::into(f)),
|
||||||
);
|
);
|
||||||
|
|
||||||
cmd.push(entry_point.as_ref().to_path_buf().display().to_string());
|
println!("Fence 5");
|
||||||
|
for part in &cmd {
|
||||||
|
println!("{}", part);
|
||||||
|
}
|
||||||
|
cmd.push("-cp".to_string());
|
||||||
|
cmd.push(entry_point.as_ref().display().to_string());
|
||||||
|
|
||||||
|
// Jave needs a class path and a file name to run.
|
||||||
|
cmd.push("Test".to_string());
|
||||||
|
|
||||||
|
println!("Fence 6");
|
||||||
|
println!("{:?}", cmd.as_slice());
|
||||||
|
|
||||||
|
|
||||||
|
println!("Fence 7");
|
||||||
let result = crate::io::run_process(cmd.as_slice());
|
let result = crate::io::run_process(cmd.as_slice());
|
||||||
|
|
||||||
if self.monitor
|
if self.monitor
|
||||||
@@ -117,7 +130,6 @@ 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 },
|
||||||
@@ -126,10 +138,7 @@ 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> {
|
||||||
self.to_string()
|
vec![self.to_string()]
|
||||||
.split_ascii_whitespace()
|
|
||||||
.map(|s| s.to_string())
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +150,6 @@ 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.as_u64()),
|
Self::HeapMax { size } => format!("Xmx{}", size.as_u64()),
|
||||||
Self::HeapMin { size } => format!("Xms{}", size.as_u64()),
|
Self::HeapMin { size } => format!("Xms{}", size.as_u64()),
|
||||||
@@ -220,14 +228,14 @@ impl Compiler {
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum CompilerFlag {
|
pub enum CompilerFlag {
|
||||||
Classpath { path: PathBuf },
|
|
||||||
Destination { path: PathBuf },
|
Destination { path: PathBuf },
|
||||||
|
Classpath { 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!["-classpath".to_string(), path.display().to_string()],
|
Self::Classpath { path } => vec!["-cp".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()],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/main.rs
15
src/main.rs
@@ -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/MainTest.java
|
// Make src/test/Test.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("MainTest")
|
.join("Test")
|
||||||
.with_extension(JAVA_EXT_SOURCE),
|
.with_extension(JAVA_EXT_SOURCE),
|
||||||
) {
|
) {
|
||||||
f.write_all(include_bytes!("../assets/src/test/MainTest.java"))?;
|
f.write_all(include_bytes!("../assets/src/test/Test.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 [
|
||||||
format!("{}/", DIR_TARGET.file_name().unwrap().display()),
|
DIR_TARGET.as_path().display().to_string(),
|
||||||
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(DIR_TARGET.as_path())
|
java::JVMBuilder::new()
|
||||||
.assertions(assertions)
|
.assertions(assertions)
|
||||||
.monitor(true)
|
.monitor(true)
|
||||||
.build()
|
.build()
|
||||||
@@ -248,16 +248,19 @@ fn run<P: AsRef<Path>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test(assertions: bool) -> anyhow::Result<(Option<String>, Option<String>)> {
|
fn test(assertions: bool) -> anyhow::Result<(Option<String>, Option<String>)> {
|
||||||
|
println!("Fence 1");
|
||||||
java::CompilerBuilder::new()
|
java::CompilerBuilder::new()
|
||||||
.class_path(DIR_TARGET.as_path())
|
.class_path(DIR_TARGET.as_path())
|
||||||
.destination(DIR_TARGET.as_path())
|
.destination(DIR_TARGET.as_path())
|
||||||
.build()
|
.build()
|
||||||
.compile(DIR_TEST.as_path())?;
|
.compile(DIR_TEST.as_path())?;
|
||||||
|
|
||||||
|
println!("Fence 2");
|
||||||
// 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(DIR_TARGET.as_path())
|
println!("Fence 3");
|
||||||
|
java::JVMBuilder::new()
|
||||||
.assertions(assertions)
|
.assertions(assertions)
|
||||||
.ram_min(ByteSize::mib(128))
|
.ram_min(ByteSize::mib(128))
|
||||||
.ram_max(ByteSize::mib(512))
|
.ram_max(ByteSize::mib(512))
|
||||||
|
|||||||
Reference in New Issue
Block a user