From 8d887548d589b7ced546ae7b52ae0f6d1c53a1c9 Mon Sep 17 00:00:00 2001 From: Alexander Koz Date: Sun, 5 May 2024 14:33:15 +0400 Subject: [PATCH] Add todos, docs, remove garbage --- Cargo.lock | 2 +- support/build/Cargo.toml | 2 +- support/build/src/assets/mod.rs | 2 -- support/build/src/assets/plan.rs | 24 +++++++++++++++--------- support/build/src/assets/resolver.rs | 7 ++++--- support/build/src/assets/tests.rs | 10 +++++----- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a105c7c6..4bd9514d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4093,7 +4093,7 @@ dependencies = [ [[package]] name = "playdate-build" -version = "0.2.6" +version = "0.2.7" dependencies = [ "crate-metadata", "dirs", diff --git a/support/build/Cargo.toml b/support/build/Cargo.toml index df1ca06b..e46f49c9 100644 --- a/support/build/Cargo.toml +++ b/support/build/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "playdate-build" -version = "0.2.6" +version = "0.2.7" readme = "README.md" description = "Utils that help to build package for Playdate" keywords = ["playdate", "package", "encoding", "manifest", "assets"] diff --git a/support/build/src/assets/mod.rs b/support/build/src/assets/mod.rs index 7d8b4733..0cf98a55 100644 --- a/support/build/src/assets/mod.rs +++ b/support/build/src/assets/mod.rs @@ -123,9 +123,7 @@ pub fn apply_build_plan<'l, 'r, P: AsRef>(plan: BuildPlan<'l, 'r>, }; let (mut plan, crate_root) = plan.into_parts(); - // let mut results = HashMap::with_capacity(plan.as_inner().len()); let mut results = HashMap::with_capacity(plan.len()); - // for entry in plan.into_inner().drain(..) { for entry in plan.drain(..) { let current: Vec<_> = match &entry { Mapping::AsIs(inc, ..) => { diff --git a/support/build/src/assets/plan.rs b/support/build/src/assets/plan.rs index 02d1f6ef..86522c9b 100644 --- a/support/build/src/assets/plan.rs +++ b/support/build/src/assets/plan.rs @@ -200,15 +200,16 @@ pub fn build_plan<'l, 'r, 'c: 'l, V>(env: &'c Env, } +// TODO: tests for `abs_or_rel_crate_existing` /// Make path relative to `crate_root` if it isn't absolute, checking existence. /// Returns `None` if path doesn't exist. -pub fn abs_or_rel_crate_existing<'t, P1, P2>(p: P1, root: P2) -> std::io::Result>> +pub fn abs_or_rel_crate_existing<'t, P1, P2>(path: P1, root: P2) -> std::io::Result>> where P1: 't + AsRef + Into>, P2: AsRef { - let p = if p.as_ref().is_absolute() && p.as_ref().try_exists()? { - Some(p.into()) + let p = if path.as_ref().is_absolute() && path.as_ref().try_exists()? { + Some(path.into()) } else { - let abs = root.as_ref().join(p); + let abs = root.as_ref().join(path); if abs.try_exists()? { Some(Cow::Owned(abs)) } else { @@ -218,14 +219,14 @@ pub fn abs_or_rel_crate_existing<'t, P1, P2>(p: P1, root: P2) -> std::io::Result Ok(p) } -/// Same as [`abs_or_rel_crate_existing`], but returns given `p` as fallback. +/// Same as [`abs_or_rel_crate_existing`], but returns given `path` as fallback. #[inline] -pub fn abs_or_rel_crate_any<'t, P1, P2>(p: P1, root: P2) -> Cow<'t, Path> +pub fn abs_or_rel_crate_any<'t, P1, P2>(path: P1, root: P2) -> Cow<'t, Path> where P1: 't + AsRef + Into> + Clone, P2: AsRef { - abs_or_rel_crate_existing(p.clone(), root).ok() - .flatten() - .unwrap_or(p.into()) + abs_or_rel_crate_existing(path.clone(), root).ok() + .flatten() + .unwrap_or(path.into()) } @@ -245,6 +246,7 @@ fn possibly_matching_any, I: IntoIterator>(path: &Pat } +// TODO: tests for `possibly_matching` /// Check that filter (possibly) pattern `expr` matches the `path`. fn possibly_matching>(path: &Path, expr: P) -> bool { // TODO: remove {crate_root} part if it is from filter (or both?). @@ -262,9 +264,12 @@ fn possibly_matching>(path: &Path, expr: P) -> bool { } +/// Assets Build Plan for a crate. #[derive(Debug, PartialEq, Eq, Hash, serde::Serialize)] pub struct BuildPlan<'left, 'right> { + /// Instructions - what file where to put plan: Vec>, + /// Root directory of associated crate crate_root: &'left Path, } @@ -386,6 +391,7 @@ pub enum Mapping<'left, 'right> } impl Mapping<'_, '_> { + // TODO: tests for `Mapping::eq_ignore_expr` pub fn eq_ignore_expr(&self, other: &Self) -> bool { match (self, other) { (Mapping::AsIs(a, _), Mapping::AsIs(b, _)) | (Mapping::Into(a, _), Mapping::Into(b, _)) => a.eq(b), diff --git a/support/build/src/assets/resolver.rs b/support/build/src/assets/resolver.rs index 82a10d0b..e9c8014c 100644 --- a/support/build/src/assets/resolver.rs +++ b/support/build/src/assets/resolver.rs @@ -18,12 +18,12 @@ pub fn resolve_includes, Excl: AsRef>(expr: S, links: LinkBehavior) -> Result, Error> { let expr = unixish_path_pattern(expr.as_ref()); - let crate_root = crate_root.to_string_lossy(); + // let crate_root = crate_root.to_string_lossy(); // #[cfg(windows)] // let crate_root = unixish_path_pattern(crate_root.as_ref()); + // let crate_root = Path::new(crate_root.as_ref()); - let crate_root = Path::new(crate_root.as_ref()); let glob = Glob::new(expr.as_ref()).map_err(|err| { // According wax's issue https://github.com/olson-sean-k/wax/issues/34 // we doesn't support Windows absolute paths and hope to partially relative paths. @@ -233,7 +233,7 @@ impl Match { } } - // TODO: test it + // TODO: tests for `Match::set_target` fn set_target>(&mut self, path: P) { trace!("old target: {}", self.target().display()); match self { @@ -339,6 +339,7 @@ impl Expr<'_> { } impl<'e> Expr<'e> { + // TODO: tests for `Expr::set` fn set<'s, S: Into>>(&mut self, actual: S) where 's: 'e { let original = match self { diff --git a/support/build/src/assets/tests.rs b/support/build/src/assets/tests.rs index ada9da1e..9e43b6e9 100644 --- a/support/build/src/assets/tests.rs +++ b/support/build/src/assets/tests.rs @@ -174,7 +174,7 @@ mod plan { #[test] #[cfg_attr(windows, should_panic)] - fn resolve_external() { + fn resolve_exact_external_abs() { let (temp, sub, _files, env) = prepared_tmp("as_is-resolve_external"); let opts = AssetsOptions::default(); @@ -224,7 +224,7 @@ mod plan { #[test] #[cfg_attr(windows, should_panic)] - fn resolve_external_many() { + fn resolve_glob_external_many() { let (_, _, files, env) = prepared_tmp("as_is-resolve_external_many"); let opts = AssetsOptions::default(); @@ -357,7 +357,7 @@ mod plan { #[test] - fn local_exact() { + fn local_exact_target() { let env = Env::default().unwrap(); let opts = AssetsOptions::default(); @@ -365,7 +365,7 @@ mod plan { let root = Some(root.as_path()); // left hand of rule: - let targets = ["trg/", "trg//", "/trg/", "//trg/"]; // XXX: " too + let targets = ["trg/", "trg//", "/trg/", "//trg/"]; let targets_rel = ["trg/", "trg//"]; // non-abs targets // right hand of rule: let tests: HashSet<_> = vec!["Cargo.toml", "src/lib.rs"].into_iter().collect(); @@ -402,7 +402,7 @@ mod plan { #[test] #[cfg_attr(windows, should_panic)] - fn resolve_local_target() { + fn glob_local_target() { let env = Env::default().unwrap(); let opts = AssetsOptions::default();