Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata & manifest-builder refactoring #366

Merged
merged 25 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dd8fb0e
metadata refactoring, add cargo-targets tables that overrides main ma…
boozook May 27, 2024
c5048c0
tests, improvements, minimal validation
boozook May 28, 2024
34606e2
Fix possible recursion in env resolver, remove panic on missed var
boozook May 28, 2024
e8c02cc
Add sources: unit-graph and full metadata by host cargo,
boozook May 28, 2024
c9ac85f
env-resolver: remove panic on missed var (missed part)
boozook May 28, 2024
9c72320
Apply clippy suggestions
boozook May 28, 2024
3b415c2
add targets, improve validation for crate-level source
boozook May 30, 2024
eb710e5
update deps and rust toolchain
boozook May 30, 2024
a2227e3
simplification, get rid of `Package` dep in layout
boozook May 30, 2024
5da646a
Apply clippy suggestions
boozook May 30, 2024
59d54b1
Merge branch 'main' into dev/meta-assets
boozook May 30, 2024
65bab4f
fix totally ignored assets
boozook May 30, 2024
149506a
improve deserialisation of legacy and error for `AssetsRules`
boozook May 30, 2024
f3f1cc2
fix missed feature-gate
boozook May 30, 2024
9ffb277
fix `AssetsRules` again
boozook May 30, 2024
14c9e4e
improve deserialisation and errors
boozook May 31, 2024
650c62e
upd deps
boozook May 31, 2024
5f9405b
parametrize strings in metadata format
boozook May 31, 2024
7f496b5
reduce usage of `Package` where only `PackageId` needed
boozook May 31, 2024
7d16e3c
set correct version
boozook May 31, 2024
570684c
allow use other strings
boozook Jun 1, 2024
6008903
deps: downgraded clang-sys v1.8.2 -> v1.8.1
boozook Jun 2, 2024
e96cbd4
improve `CrateInfoSource`
boozook Jun 4, 2024
575ee8c
add draft for meta-tree (unit-graph + metadata)
boozook Jun 4, 2024
9f1ce14
apply clippy suggestions
boozook Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
385 changes: 202 additions & 183 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ system = { version = "0.3", path = "api/system", package = "playdate-system", de
sys = { version = "0.4", path = "api/sys", package = "playdate-sys", default-features = false }

tool = { version = "0.1", path = "support/tool", package = "playdate-tool" }
build = { version = "0.3", path = "support/build", package = "playdate-build", default-features = false }
build = { version = "=0.4.0-pre1", path = "support/build", package = "playdate-build", default-features = false }
utils = { version = "0.3", path = "support/utils", package = "playdate-build-utils", default-features = false }
device = { version = "0.2", path = "support/device", package = "playdate-device" }
simulator = { version = "0.1", path = "support/sim-ctrl", package = "playdate-simulator-utils", default-features = false }
Expand Down
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
25 changes: 13 additions & 12 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 All @@ -41,7 +43,7 @@ pub fn build<'cfg>(config: &'cfg Config) -> CargoResult<AssetsArtifacts<'cfg>> {
for (package, targets, ..) in config.possible_targets()? {
let env = plan::LazyEnvBuilder::new(config, package);
let mut plans: HashMap<&Package, _> = Default::default();
let global_layout = CrossTargetLayout::new(config, package, None)?;
let global_layout = CrossTargetLayout::new(config, package.package_id(), None)?;
let mut layout = global_layout.assets_layout(config);
let mut options = HashMap::new();

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())
}
25 changes: 12 additions & 13 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;
boozook marked this conversation as resolved.
Show resolved Hide resolved

if is_empty {
return Ok(PackageAssetsPlan { main: None,
Expand All @@ -88,11 +86,11 @@ 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);
let path = layout.as_inner().assets_plan_for(config, &package.package_id());
let mut cached = CachedPlan::new(path, plan)?;
if config.compile_options.build_config.force_rebuild {
cached.difference = Difference::Missing;
Expand All @@ -105,11 +103,12 @@ 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);
let path = layout.as_inner()
.assets_plan_for_dev(config, &package.package_id());
let mut dev_cached = CachedPlan::new(path, dev_plan)?;

// Inheritance, if main is stale or missing - this one is too:
Expand Down
1 change: 0 additions & 1 deletion cargo/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use crate::utils::path::AsRelativeTo;
use crate::utils::workspace::PossibleTargets;


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
Loading