Initial Commit.

This commit is contained in:
Olivia Brooks
2026-01-25 21:20:03 -05:00
commit ef07526d57
15 changed files with 1561 additions and 0 deletions

44
src/env.rs Normal file
View File

@@ -0,0 +1,44 @@
use std::io;
use std::path::Path;
use std::str::FromStr;
use std::sync::LazyLock;
use crate::java::{JAVA_VM, VMFlag};
use anyhow::Context;
static JAVA_VERSION: LazyLock<String> = LazyLock::new(|| {
crate::io::run_process(&[JAVA_VM, VMFlag::Version.to_string().as_str()])
.expect("Failed to call java")
.0
.expect("Failed to read java version from stdout")
});
pub fn get_javac_ver() -> anyhow::Result<semver::Version> {
/*
* $ java --version
* openjdk 21.0.9 2025-10-21
* OpenJDK Runtime Environment (build 21.0.9+10)
* OpenJDK 64-Bit Server VM (build 21.0.9+10, mixed mode, sharing)
*/
semver::Version::from_str(
JAVA_VERSION
.lines()
.nth(0)
.context("stdout from Java is all f-cked up")?
.split_ascii_whitespace()
.nth(1)
.context("Java version position is all f-cked up")?,
)
.context("Failed to produce a version struct from string")
}
pub fn set_cwd<P: AsRef<Path>>(path: P) -> io::Result<()> {
let mut cwd = crate::PROJECT_ROOT
.lock()
.expect("Failed to lock Mutex")
.to_owned();
cwd.push(path.as_ref());
std::env::set_current_dir(cwd)
}