Resolve some pathing issues; cleanup.

This commit is contained in:
Cutieguwu
2026-02-15 20:15:26 -05:00
parent 16accb8ab8
commit 17f7b9dca9
3 changed files with 20 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "core" name = "core"
version = "0.1.0" version = "0.1.1"
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true

View File

@@ -1,6 +1,6 @@
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::Read; use std::io::Read;
use std::path::PathBuf; use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -28,6 +28,11 @@ impl Prey {
} }
} }
pub fn with_entry_point<P: AsRef<Path>>(&mut self, entry_point: P) -> &mut Self {
self.package.entry_point = entry_point.as_ref().to_path_buf();
self
}
pub fn entry_point(&self) -> PathBuf { pub fn entry_point(&self) -> PathBuf {
self.package.entry_point.clone() self.package.entry_point.clone()
} }

View File

@@ -67,32 +67,10 @@ impl WorkspaceHandler {
Ok(()) Ok(())
} }
/*
/// Future `build` method.
pub fn compile(&self, target: Option<PathBuf>) -> crate::Result<()> {
let mut target = target.unwrap_or(self.nest.default_package());
if !target.is_file() {
// Use is_file to skip messing with pathing for src/
// If target is not a file (explicit entry point), check if it's a known package
// and use that's package's default entry point.
target = target.join(
self.packages
.get(&target)
.ok_or(Error::UnknownPackage)?
.entry_point(),
);
}
//java::Compiler::new();
Ok(())
}
*/
pub fn init(&mut self) -> crate::Result<&mut Self> { pub fn init(&mut self) -> crate::Result<&mut Self> {
// ORDER MATTERS.
let is_empty = read_dir(self.project_root.as_path()).is_ok_and(|tree| tree.count() == 0); let is_empty = read_dir(self.project_root.as_path()).is_ok_and(|tree| tree.count() == 0);
// ORDER MATTERS. THIS MUST COME FIRST.
// Make config file. // Make config file.
self.write_nest()?; self.write_nest()?;
@@ -150,7 +128,7 @@ impl WorkspaceHandler {
for target in targets.iter() { for target in targets.iter() {
// Possibly come up with a source file handler for this? // Possibly come up with a source file handler for this?
if let Ok(_) = compiler.clone().compile(target.path.as_path()) { if let Ok(_) = compiler.clone().compile(target.path.as_path()) {
// No, this does not run O(1) // TODO: Prevent unnecessary recompile
//target.update()?; //target.update()?;
} }
} }
@@ -173,17 +151,13 @@ impl WorkspaceHandler {
// Use is_file to skip messing with pathing for src/ // Use is_file to skip messing with pathing for src/
// If target is not a file (explicit entry point), check if it's a known package // If target is not a file (explicit entry point), check if it's a known package
// and use that's package's default entry point. // and use that's package's default entry point.
entry_point = entry_point.join( entry_point = self
self.packages .packages
.get(&entry_point) .get(&entry_point)
.ok_or(Error::UnknownPackage)? .ok_or(Error::UnknownPackage)?
.entry_point(), .entry_point();
);
} }
// JRE pathing will be messed up without this.
std::env::set_current_dir(Self::DIR_TARGET)?;
java::runtime::JVMBuilder::new(Self::DIR_TARGET) java::runtime::JVMBuilder::new(Self::DIR_TARGET)
.assertions(assertions) .assertions(assertions)
.monitor(true) .monitor(true)
@@ -305,7 +279,9 @@ impl WorkspaceHandler {
.create_new(true) .create_new(true)
.open(main.join(F_PREY_TOML)) .open(main.join(F_PREY_TOML))
{ {
f.write_all(toml::to_string_pretty(&Prey::new("main"))?.as_bytes())?; f.write_all(
toml::to_string_pretty(&Prey::new("main").with_entry_point("Main"))?.as_bytes(),
)?;
} }
// Make src/main/Main.java // Make src/main/Main.java
@@ -323,7 +299,9 @@ impl WorkspaceHandler {
.create_new(true) .create_new(true)
.open(test.join(F_PREY_TOML)) .open(test.join(F_PREY_TOML))
{ {
f.write_all(toml::to_string_pretty(&Prey::new("test"))?.as_bytes())?; f.write_all(
toml::to_string_pretty(&Prey::new("test").with_entry_point("MainTest"))?.as_bytes(),
)?;
} }
// Make src/test/MainTest.java // Make src/test/MainTest.java