Skip to content

Commit

Permalink
Package new assets-builder' artefacts using meta tree (#381)
Browse files Browse the repository at this point in the history
* fix assets-plan index - wrong for dev

* package new assets-artifacts

* fix "Assets artifacts not found" for crates without assets 🤦🏻‍♂️

* clean up
  • Loading branch information
boozook authored Jun 13, 2024
1 parent 7eb4e5a commit a69b41a
Show file tree
Hide file tree
Showing 16 changed files with 990 additions and 1,846 deletions.
124 changes: 31 additions & 93 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cargo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-playdate"
version = "0.5.0-beta.4"
version = "0.5.0-beta.5"
readme = "README.md"
description = "Build tool for neat yellow console."
keywords = ["playdate", "build", "cargo", "plugin", "cargo-subcommand"]
Expand Down Expand Up @@ -43,7 +43,7 @@ toml.workspace = true
toml_edit = { version = "0.22", features = ["serde"] }
regex.workspace = true
byteorder = "1.5"
zip = { version = "1.1", features = ["time"] }
zip = { version = "2.1", features = ["time"] }
walkdir = "2.5"

anyhow = "1.0"
Expand Down
60 changes: 60 additions & 0 deletions cargo/src/assets/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::collections::BTreeMap;
use std::path::PathBuf;

use cargo::CargoResult;
use playdate::assets::plan::BuildPlan;

pub struct PlanCache {
pub difference: Difference,
pub serialized: Option<String>,
pub path: PathBuf,
}


#[derive(Debug, Clone, Copy, serde::Serialize)]
pub enum Difference {
Same,
Different,
/// There is not cache file.
Missing,
}

impl Difference {
pub fn is_same(&self) -> bool { matches!(self, Self::Same) }
}


#[must_use = "Cached plan must be used"]
pub fn plan_cache(path: PathBuf, plan: &BuildPlan<'_, '_>) -> CargoResult<PlanCache> {
let mut serializable = plan.iter_flatten_meta().collect::<Vec<_>>();
serializable.sort();

#[derive(serde::Serialize)]
struct SerializablePlan<'t> {
items: &'t [(playdate::assets::plan::MappingKind, PathBuf, (PathBuf, Option<std::time::SystemTime>))],
env: &'t BTreeMap<String, String>,
}

let serializable = SerializablePlan { items: &serializable,
env: plan.used_env_vars() };
let json = serde_json::to_string(&serializable)?;

let difference = if path.try_exists()? {
if std::fs::read_to_string(&path)? == json {
log::debug!("Cached plan is the same");
Difference::Same
} else {
log::debug!("Cache mismatch, need diff & rebuild");
Difference::Different
}
} else {
log::debug!("Cache mismatch, full rebuilding");
Difference::Missing
};

let serialized = (!difference.is_same()).then_some(json);

Ok(PlanCache { path,
difference,
serialized })
}
Loading

0 comments on commit a69b41a

Please sign in to comment.