Skip to content

Commit

Permalink
Add sources: unit-graph and full metadata by host cargo,
Browse files Browse the repository at this point in the history
* use new manifest builder from `playdate-build` pre-0.4

* little `cargo-playdate` refactoring 🥵
  • Loading branch information
boozook committed May 28, 2024
1 parent 34606e2 commit e8c02cc
Show file tree
Hide file tree
Showing 20 changed files with 812 additions and 408 deletions.
2 changes: 1 addition & 1 deletion 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.4.14"
version = "0.5.0-pre1"
readme = "README.md"
description = "Build tool for neat yellow console."
keywords = ["playdate", "build", "cargo", "plugin", "cargo-subcommand"]
Expand Down Expand Up @@ -59,7 +59,7 @@ async-std = { version = "1.12", features = ["tokio1"] }
[dependencies.build]
workspace = true
default-features = false
features = ["assets-report", "toml"]
features = ["assets-report", "toml", "json"]

[dependencies.device]
workspace = true
Expand Down
23 changes: 12 additions & 11 deletions cargo/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use std::path::{PathBuf, Path};
use anstyle::AnsiColor as Color;
use anyhow::bail;
use cargo::CargoResult;
use cargo::core::{Package, Verbosity};
use cargo::core::{Package, PackageId, Verbosity};
use playdate::manifest::ManifestSourceOpt as _;
use playdate::metadata::source::MetadataSource as _;
use playdate::metadata::METADATA_FIELD;
use playdate::layout::Layout;

Expand All @@ -15,23 +17,23 @@ use crate::layout::{PlaydateAssets, LayoutLockable, Layout as _, CrossTargetLayo
use crate::logger::LogErr;
use crate::utils::LazyBuildContext;
use crate::utils::path::AsRelativeTo;
use self::plan::TomlMetadata;
use self::plan::Metadata;


mod plan;
mod pdc;


#[derive(Debug)]
pub struct AssetsArtifact<'cfg> {
pub package: &'cfg Package,
pub struct AssetsArtifact {
pub package_id: PackageId,
pub layout: PlaydateAssets<PathBuf>,
/// Cached metadata
pub metadata: Option<TomlMetadata>,
pub metadata: Option<Metadata>,
}

/// One artifact per package.
pub type AssetsArtifacts<'cfg> = HashMap<&'cfg Package, AssetsArtifact<'cfg>>;
pub type AssetsArtifacts<'cfg> = HashMap<&'cfg Package, AssetsArtifact>;


pub fn build<'cfg>(config: &'cfg Config) -> CargoResult<AssetsArtifacts<'cfg>> {
Expand Down Expand Up @@ -348,7 +350,7 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult<AssetsArtifacts<'cfg>> {
let metadata = options.remove(package);
artifacts.insert(
package,
AssetsArtifact { package,
AssetsArtifact { package_id: package.package_id(),
layout,
metadata, },
);
Expand All @@ -369,7 +371,7 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult<AssetsArtifacts<'cfg>> {
fn deps_tree_metadata<'cfg: 'r, 't: 'r, 'r>(package: &'cfg Package,
bcx: &'t LazyBuildContext<'t, 'cfg>,
config: &Config<'_>)
-> CargoResult<HashMap<&'r Package, TomlMetadata>> {
-> CargoResult<HashMap<&'r Package, Metadata>> {
let mut packages = HashMap::new();
if let Some(metadata) = playdate_metadata(package) {
// if explicitly allowed collect deps => scan deps-tree
Expand Down Expand Up @@ -470,11 +472,10 @@ fn deps_tree_metadata<'cfg: 'r, 't: 'r, 'r>(package: &'cfg Package,
}


pub fn playdate_metadata(package: &Package) -> Option<TomlMetadata> {
pub fn playdate_metadata(package: &Package) -> Option<Metadata> {
package.manifest()
.custom_metadata()
.and_then(|m| m.as_table().map(|t| t.get(METADATA_FIELD)))
.flatten()
.and_then(|v| v.to_owned().try_into::<TomlMetadata>().log_err().ok())
.and_then(|mut m| m.merge_opts().map(|_| m).log_err().ok())
.and_then(|v| v.to_owned().try_into::<Metadata>().log_err().ok())
}
20 changes: 9 additions & 11 deletions cargo/src/assets/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ use playdate::assets::BuildReport;
use playdate::assets::apply_build_plan;
use playdate::config::Env;
use playdate::metadata::format::AssetsOptions;
use playdate::metadata::source::MetadataSource as _;
use crate::config::Config;
use crate::utils::path::AsRelativeTo;
use playdate::consts::SDK_ENV_VAR;
use cargo::util::CargoResult;
use playdate::metadata::format::PlayDateMetadata;
pub use playdate::metadata::format::Metadata;
use playdate::assets::plan::BuildPlan as AssetsPlan;
use playdate::assets::plan::build_plan as assets_build_plan;
use try_lazy_init::Lazy;

use crate::layout::{PlaydateAssets, LayoutLock};


pub type TomlMetadata = PlayDateMetadata<toml::Value>;


pub struct LazyEnvBuilder<'a, 'cfg> {
config: &'a Config<'cfg>,
package: &'cfg Package,
Expand Down Expand Up @@ -68,15 +66,15 @@ pub type LockedLayout<'t> = LayoutLock<&'t mut PlaydateAssets<PathBuf>>;
/// Returns `None` if there is no `assets` metadata.
pub fn plan_for<'cfg, 'env, 'l>(config: &'cfg Config,
package: &'cfg Package,
metadata: &TomlMetadata,
metadata: &Metadata,
env: &'cfg LazyEnvBuilder<'env, 'cfg>,
layout: &'l LockedLayout<'l>,
with_dev: bool)
-> CargoResult<PackageAssetsPlan<'env, 'cfg>> {
let opts = metadata.assets_options();

let has_dev_assets = with_dev && metadata.dev_assets.iter().any(|t| !t.is_empty());
let is_empty = metadata.assets.is_empty() && !has_dev_assets;
let has_dev_assets = with_dev && !metadata.dev_assets().is_empty();
let is_empty = !metadata.assets().is_empty() && !has_dev_assets;

if is_empty {
return Ok(PackageAssetsPlan { main: None,
Expand All @@ -88,8 +86,8 @@ pub fn plan_for<'cfg, 'env, 'l>(config: &'cfg Config,
.parent()
.ok_or(anyhow!("No parent of manifest-path"))?;

let main = if !metadata.assets.is_empty() {
let plan = assets_build_plan(env, &metadata.assets, opts.as_ref(), Some(root))?;
let main = if !metadata.assets().is_empty() {
let plan = assets_build_plan(env, metadata.assets(), opts.as_ref(), Some(root))?;

// main-assets plan:
let path = layout.as_inner().assets_plan_for(config, package);
Expand All @@ -105,8 +103,8 @@ pub fn plan_for<'cfg, 'env, 'l>(config: &'cfg Config,


// dev-assets plan:
let dev = if has_dev_assets && metadata.dev_assets.is_some() {
let assets = metadata.dev_assets.as_ref().unwrap();
let dev = if has_dev_assets && !metadata.dev_assets().is_empty() {
let assets = metadata.dev_assets();
let dev_plan = assets_build_plan(env, assets, opts.as_ref(), Some(root))?;

let path = layout.as_inner().assets_plan_for_dev(config, package);
Expand Down
2 changes: 1 addition & 1 deletion cargo/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use crate::utils::cargo::CompileKindExt;
use crate::utils::path::AsRelativeTo;
use crate::utils::workspace::PossibleTargets;

use crate::utils::cargo::build_plan as plan;

pub mod plan;
pub mod rustflags;


Expand Down
145 changes: 0 additions & 145 deletions cargo/src/build/plan/format.rs

This file was deleted.

Loading

0 comments on commit e8c02cc

Please sign in to comment.