forked 6ad82c3339 and refactored to combine prey.toml with nest.toml. The WorkspaceHandler.discover_packages() function is very broken

This commit is contained in:
2026-02-22 23:19:26 -05:00
parent 6ad82c3339
commit 3654d76340
32 changed files with 335 additions and 333 deletions

View File

@@ -11,7 +11,6 @@ use subprocess::Exec;
use crate::nest::{F_NEST_LOCK, F_NEST_TOML, Nest, NestLock};
use crate::package::PackageHandler;
use crate::prey::{F_PREY_LOCK, F_PREY_TOML, Prey};
use crate::{Error, package};
#[derive(Debug)]
@@ -23,8 +22,8 @@ pub struct WorkspaceHandler {
}
impl WorkspaceHandler {
const DIR_SRC: &str = "src/";
const DIR_TARGET: &str = "target/";
const DIR_SRC: &'static str = "src/";
const DIR_TARGET: &'static str = "target/";
pub fn new<P: AsRef<Path>>(project_root: P) -> crate::Result<Self> {
let project_root = project_root.as_ref().canonicalize()?;
@@ -43,7 +42,9 @@ impl WorkspaceHandler {
}
pub fn load<P: AsRef<Path>>(project_root: P) -> crate::Result<Self> {
let project_root = project_root.as_ref().canonicalize()?;
println!("{}", project_root.display());
let mut workspace_manager = Self {
nest: Nest::try_from(project_root.join(F_NEST_TOML))?,
@@ -121,8 +122,8 @@ impl WorkspaceHandler {
.destination(Self::DIR_TARGET)
.build();
// No unintentional deep copying anywhere, right?
// Probably not. We'll see.
// cyclic dependencies across packages are not supported.
// construct a hashmap of parent child relationships between all files across all packages.
for handler in self.packages.values_mut() {
let package_src_root = self
.project_root
@@ -135,7 +136,7 @@ impl WorkspaceHandler {
dbg!(&target);
if let Ok(true) = compiler
.clone()
.compile(package_src_root.join(target.path.as_path()))
.compile(vec![package_src_root.join(target.path.as_path())])
{
target.update(package_src_root.as_path())?;
handler
@@ -157,33 +158,42 @@ impl WorkspaceHandler {
entry_point: Option<P>,
assertions: bool,
) -> crate::Result<&mut Self> {
let mut entry_point = if entry_point.is_none() {
self.nest.default_package()
} else {
entry_point.unwrap().as_ref().to_path_buf()
};
if !entry_point.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.
let mut entry_point = entry_point.expect("No entry point found").as_ref().to_path_buf();
while entry_point.is_file() {
entry_point = self
.packages
.get(&entry_point)
.ok_or(Error::UnknownPackage)?
.entry_point();
.entry_point()
.expect("No entry point found");
}
// let mut entry_point = if entry_point.is_none() {
// self.nest.entry_point()
// } else {
// //entry_point.unwrap().as_ref().to_path_buf()
// };
//
// if !entry_point.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.
// entry_point = self
// .packages
// .get(&entry_point)
// .ok_or(Error::UnknownPackage)?
// .entry_point();
// }
//
if entry_point.file_name().is_none() {
return Err(Error::UndefinedEntryPoint);
return Err(Error::UndefinedEntryPoint);
}
//
java::runtime::JVMBuilder::new(Self::DIR_TARGET)
.assertions(assertions)
.monitor(true)
.build()
.run(entry_point)?;
Ok(self)
}
@@ -201,7 +211,7 @@ impl WorkspaceHandler {
self.project_root
.join(Self::DIR_SRC)
.join(handler.name())
.join(F_PREY_LOCK),
.join(F_NEST_LOCK),
) {
if err.kind() != std::io::ErrorKind::NotFound {
return Err(Error::from(err));
@@ -216,6 +226,9 @@ impl WorkspaceHandler {
}
/// Add any newly created packages.
/// Prey.toml files designate packages.
/// discover_packages() iterates the filesystem recursively to discover all such packages.
/// discovered packages are stored as a hashmap<PathBuf, PackageHandler> in the WorkspaceHandler.
fn discover_packages(&mut self) -> crate::Result<()> {
// Scan the src/ directory for entries,
// filter out the files,
@@ -227,7 +240,7 @@ impl WorkspaceHandler {
// whole subtree.
//
// Yes, I know this looks like shit.
// That's because it is.
// That's because it is. CON-FUCKING-FIRMED THIS SHIT IS NOT DEBUGGABLE
for file in read_dir(self.project_root.join(Self::DIR_SRC))?
// Get directories
@@ -240,14 +253,14 @@ impl WorkspaceHandler {
})
// Get Prey.toml files
.filter_map(|dir| {
Some(if dir.join(F_PREY_TOML).exists() {
vec![dir.join(F_PREY_TOML)]
Some(if dir.join(F_NEST_TOML).exists() {
vec![dir.join(F_NEST_TOML)]
} else {
expand_files(dir)
.ok()?
.iter()
.filter_map(|file| {
if file.ends_with(PathBuf::from(F_PREY_TOML)) {
if file.ends_with(PathBuf::from(F_NEST_TOML)) {
Some(file.to_owned())
} else {
None
@@ -319,10 +332,10 @@ impl WorkspaceHandler {
if let Result::Ok(mut f) = OpenOptions::new()
.write(true)
.create_new(true)
.open(main.join(F_PREY_TOML))
.open(main.join(F_NEST_TOML))
{
f.write_all(
toml::to_string_pretty(&Prey::new("main").with_entry_point("Main"))?.as_bytes(),
toml::to_string_pretty(&Nest::new("main").with_entry_point("Main"))?.as_bytes(),
)?;
}
@@ -339,10 +352,10 @@ impl WorkspaceHandler {
if let Result::Ok(mut f) = OpenOptions::new()
.write(true)
.create_new(true)
.open(test.join(F_PREY_TOML))
.open(test.join(F_NEST_TOML))
{
f.write_all(
toml::to_string_pretty(&Prey::new("test").with_entry_point("MainTest"))?.as_bytes(),
toml::to_string_pretty(&Nest::new("test").with_entry_point("MainTest"))?.as_bytes(),
)?;
}