forked from Cutieguwu/raven
Bump subprocess and toml. Also remove the demo project I accidentally
pushed.
This commit is contained in:
@@ -16,5 +16,5 @@ publish.workspace = true
|
||||
bytesize.workspace = true
|
||||
derive_more.workspace = true
|
||||
fs.workspace = true
|
||||
io.workspace = true
|
||||
semver.workspace = true
|
||||
subprocess.workspace = true
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use subprocess::Exec;
|
||||
use subprocess::Redirection;
|
||||
|
||||
use crate::JAVA_BIN_COMPILER;
|
||||
use crate::Result;
|
||||
|
||||
@@ -45,6 +48,7 @@ pub struct Compiler {
|
||||
}
|
||||
|
||||
impl Compiler {
|
||||
/*
|
||||
pub fn compile<P: AsRef<Path>>(self, path: P) -> Result<(Option<String>, Option<String>)> {
|
||||
let mut cmd: Vec<String> = vec![JAVA_BIN_COMPILER.to_string()];
|
||||
|
||||
@@ -62,6 +66,23 @@ impl Compiler {
|
||||
|
||||
Ok(io::run_process(cmd.as_slice())?)
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn compile<P: AsRef<Path>>(self, path: P) -> Result<bool> {
|
||||
Ok(Exec::cmd(JAVA_BIN_COMPILER)
|
||||
.args(
|
||||
self.flags
|
||||
.clone()
|
||||
.into_iter()
|
||||
.flat_map(|f| Into::<Vec<String>>::into(f)),
|
||||
)
|
||||
.arg(path.as_ref())
|
||||
.stdout(Redirection::Pipe)
|
||||
.detached()
|
||||
.start()?
|
||||
.wait()?
|
||||
.success())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@@ -7,13 +7,10 @@ pub enum Error {
|
||||
EmptyStdout,
|
||||
|
||||
#[from]
|
||||
Io(io::Error),
|
||||
Io(std::io::Error),
|
||||
|
||||
NthOutOfBounds,
|
||||
|
||||
#[from]
|
||||
Semver(semver::Error),
|
||||
|
||||
#[from]
|
||||
StdIo(std::io::Error),
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use std::str::FromStr;
|
||||
|
||||
pub use error::{Error, Result};
|
||||
use runtime::VMFlag;
|
||||
use subprocess::Exec;
|
||||
|
||||
pub const JAVA_BIN_VM: &str = "java";
|
||||
pub const JAVA_BIN_COMPILER: &str = "javac";
|
||||
@@ -41,9 +42,8 @@ pub fn get_javac_ver() -> Result<semver::Version> {
|
||||
|
||||
/// Calls the java binary, returning the complete stdout version information.
|
||||
fn get_java_version_info() -> Result<String> {
|
||||
Ok(
|
||||
io::run_process(&[JAVA_BIN_VM, VMFlag::Version.to_string().as_str()])?
|
||||
.0
|
||||
.ok_or(Error::EmptyStdout)?,
|
||||
)
|
||||
Ok(Exec::cmd(JAVA_BIN_VM)
|
||||
.arg(VMFlag::Version.to_string().as_str())
|
||||
.capture()?
|
||||
.stdout_str())
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::JAVA_BIN_VM;
|
||||
use crate::Result;
|
||||
|
||||
use bytesize::ByteSize;
|
||||
use subprocess::Exec;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct JVMBuilder {
|
||||
@@ -74,36 +75,32 @@ pub struct JVM {
|
||||
}
|
||||
|
||||
impl JVM {
|
||||
pub fn run<P: AsRef<Path>>(self, entry_point: P) -> Result<(Option<String>, Option<String>)> {
|
||||
let mut cmd = vec![JAVA_BIN_VM.to_string()];
|
||||
pub fn run<P: AsRef<Path>>(self, entry_point: P) -> Result<()> {
|
||||
let capture = Exec::cmd(JAVA_BIN_VM)
|
||||
.args(
|
||||
self.flags
|
||||
.clone()
|
||||
.into_iter()
|
||||
.flat_map(|f| Into::<Vec<String>>::into(f)),
|
||||
)
|
||||
.arg(entry_point.as_ref())
|
||||
.capture()?;
|
||||
|
||||
cmd.extend(
|
||||
self.flags
|
||||
.clone()
|
||||
.into_iter()
|
||||
.flat_map(|f| Into::<Vec<String>>::into(f)),
|
||||
);
|
||||
|
||||
cmd.push(entry_point.as_ref().to_path_buf().display().to_string());
|
||||
|
||||
let result = io::run_process(cmd.as_slice())?;
|
||||
|
||||
if self.monitor {
|
||||
let (stdout, stderr) = &result;
|
||||
|
||||
if let Option::Some(stdout) = stdout
|
||||
&& stdout.len() > 0
|
||||
{
|
||||
print!("{stdout}");
|
||||
}
|
||||
if let Option::Some(stderr) = stderr
|
||||
&& stderr.len() > 0
|
||||
{
|
||||
eprintln!("{stderr}");
|
||||
}
|
||||
if !self.monitor {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
let stdout = capture.stdout_str();
|
||||
if stdout.len() > 0 {
|
||||
println!("{stdout}");
|
||||
}
|
||||
|
||||
let stderr = capture.stderr_str();
|
||||
if stderr.len() > 0 {
|
||||
eprintln!("{stderr}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user