Skip to content

Commit

Permalink
* playdate-build refactoring
Browse files Browse the repository at this point in the history
* make serde optional

* add manifest extra fields

* override `name` & `id` fields for dev examples
  • Loading branch information
boozook committed May 19, 2024
1 parent 006a9cd commit 8b8c75f
Show file tree
Hide file tree
Showing 23 changed files with 1,133 additions and 1,023 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ jobs:
- name: Test
run: |
cargo test -p=playdate-build-utils --all-features
cargo test -p=playdate-build --no-default-features -- --nocapture
cargo test -p=playdate-build --all-features -- --nocapture
cargo test -p=playdate-device
cargo test -p=playdate-tool --all-features
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

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.3", path = "api/sys", package = "playdate-sys", default-features = false }

tool = { version = "0.1", path = "support/tool", package = "playdate-tool" }
build = { version = "0.2", path = "support/build", package = "playdate-build", default-features = false }
build = { version = "0.3", 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
2 changes: 1 addition & 1 deletion cargo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-playdate"
version = "0.4.13"
version = "0.4.14"
readme = "README.md"
description = "Build tool for neat yellow console."
keywords = ["playdate", "build", "cargo", "plugin", "cargo-subcommand"]
Expand Down
2 changes: 1 addition & 1 deletion cargo/src/assets/pdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::process::Command;
use anyhow::bail;
use cargo::CargoResult;
use cargo::core::Package;
use playdate::io::soft_link_checked;
use playdate::fs::soft_link_checked;
use playdate::layout::Layout;

use crate::config::Config;
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 @@ -18,7 +18,7 @@ use cargo::core::compiler::CrateType;
use cargo::util::command_prelude::CompileMode;
use playdate::compile::dylib_suffix_for_host_opt;
use playdate::compile::static_lib_suffix;
use playdate::io::soft_link_checked;
use playdate::fs::soft_link_checked;
use playdate::toolchain::gcc::ArmToolchain;
use playdate::toolchain::sdk::Sdk;
use anstyle::AnsiColor as Color;
Expand Down
54 changes: 39 additions & 15 deletions cargo/src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use cargo::core::profiles::DebugInfo;
use cargo::core::profiles::Profiles;
use cargo_util_schemas::manifest::TomlDebugInfo;
use clap_lex::OsStrExt;
use playdate::io::soft_link_checked;
use playdate::fs::soft_link_checked;
use playdate::layout::Layout;
use playdate::layout::Name;
use playdate::manifest::ManifestDataSource;
Expand Down Expand Up @@ -112,7 +112,9 @@ fn package_single_target<'p>(config: &Config,
}

// manifest:
build_manifest(config, &product.layout, product.package, assets)?;
let ext_id = product.example.then(|| format!("dev.{}", product.name).into());
let ext_name = product.example.then_some(product.name.as_str().into());
build_manifest(config, &product.layout, product.package, assets, ext_id, ext_name)?;

// finally call pdc and pack:
let mut artifact = execute_pdc(config, &product.layout)?;
Expand Down Expand Up @@ -217,15 +219,15 @@ fn package_multi_target<'p>(config: &Config,
}
crate::layout::Layout::prepare(&mut layout.as_mut())?;

let mut has_dev = Default::default();
let mut dev = Default::default();
for product in &products {
log::debug!("Preparing binaries for packaging {}", product.presentable_name());
assert_eq!(package, product.package, "package must be same");
let dst = layout.build().join(product.path.file_name().expect("file_name"));
soft_link_checked(&product.path, &dst, true, layout.as_inner().target())?;

if product.example {
has_dev = true;
dev = Some(product);
}
}

Expand All @@ -237,15 +239,17 @@ fn package_multi_target<'p>(config: &Config,
prepare_assets(
config,
assets,
has_dev,
dev.is_some(),
layout.build(),
true,
layout.as_inner().target(),
)?;
}

// manifest:
build_manifest(config, &layout, package, assets)?;
let ext_id = dev.and_then(|p| p.example.then(|| format!("dev.{}", p.name).into()));
let ext_name = dev.and_then(|p| p.example.then_some(p.name.as_str().into()));
build_manifest(config, &layout, package, assets, ext_id, ext_name)?;

// finally call pdc and pack:
let mut artifact = execute_pdc(config, &layout)?;
Expand Down Expand Up @@ -273,21 +277,41 @@ fn package_multi_target<'p>(config: &Config,
fn build_manifest<Layout: playdate::layout::Layout>(config: &Config,
layout: &Layout,
package: &Package,
assets: Option<&AssetsArtifact<'_>>)
assets: Option<&AssetsArtifact<'_>>,
id_suffix: Option<Cow<'_, str>>,
name_override: Option<Cow<'_, str>>)
-> CargoResult<()> {
config.log().verbose(|mut log| {
let msg = format!("building package manifest for {}", package.package_id());
log.status("Manifest", msg);
});

let manifest = if let Some(metadata) = assets.and_then(|a| a.metadata.as_ref()) {
Manifest::try_from_source(ManifestSource { package,
metadata: metadata.into() })
} else {
let metadata = playdate_metadata(package);
Manifest::try_from_source(ManifestSource { package,
metadata: metadata.as_ref() })
}.map_err(|err| anyhow!(err))?;
let mut manifest = if let Some(metadata) = assets.and_then(|a| a.metadata.as_ref()) {
let source = ManifestSource { package,
metadata: metadata.into() };
Manifest::try_from_source(source)
} else {
let metadata = playdate_metadata(package);
let source = ManifestSource { package,
metadata: metadata.as_ref() };
Manifest::try_from_source(source)
}.map_err(|err| anyhow!(err))?;

// Override fields. This is a hacky not-so-braking hot-fix for issue #354.
// This is a temporary solution only until full metadata inheritance is implemented.
if id_suffix.is_some() || name_override.is_some() {
if let Some(id) = id_suffix {
log::trace!("Overriding bundle_id from {}", manifest.bundle_id);
manifest.bundle_id.push_str(".example.");
manifest.bundle_id.push_str(&id);
log::trace!(" to {}", manifest.bundle_id);
}
if let Some(name) = name_override {
log::trace!("Overriding program name {} -> {name}", manifest.name);
manifest.name = name.into_owned();
}
}

std::fs::write(layout.manifest(), manifest.to_manifest_string())?;
Ok(())
}
Expand Down
11 changes: 6 additions & 5 deletions support/build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playdate-build"
version = "0.2.9"
version = "0.3.0"
readme = "README.md"
description = "Utils that help to build package for Playdate"
keywords = ["playdate", "package", "encoding", "manifest", "assets"]
Expand All @@ -14,8 +14,7 @@ repository.workspace = true

[dependencies]
log.workspace = true
# TODO: make serde optional!
serde = { workspace = true, features = ["derive"] }
serde = { workspace = true, features = ["derive"], optional = true }
serde_json = { workspace = true, optional = true }
toml = { workspace = true, optional = true }
dirs.workspace = true
Expand All @@ -35,8 +34,10 @@ features = ["log"]


[features]
default = ["toml", "serde_json"]
cargo = ["utils/cargo-message", "serde_json"]
default = []
toml = ["serde", "dep:toml"]
serde_json = ["serde", "dep:serde_json"]
crate-metadata = ["serde_json", "dep:crate-metadata"]
assets-report = []


Expand Down
8 changes: 3 additions & 5 deletions support/build/src/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ use std::io::{Error as IoError, ErrorKind as IoErrorKind};
use wax::{LinkBehavior, WalkError};
use fs_extra::error::Error as FsExtraError;

use crate::io::soft_link_checked;
use crate::fs::soft_link_checked;
use crate::metadata::format::AssetsBuildMethod;
use crate::metadata::format::AssetsOptions;


pub mod plan;
pub mod resolver;
mod tests;

use self::plan::*;


pub fn apply_build_plan<'l, 'r, P: AsRef<Path>>(plan: BuildPlan<'l, 'r>,
target_root: P,
assets_options: &AssetsOptions)
-> Result<BuildReport<'l, 'r>, FsExtraError> {
use crate::io::parent_of;
use crate::io::ensure_dir_exists;
use crate::fs::parent_of;
use crate::fs::ensure_dir_exists;

let target_root = target_root.as_ref();
let build_method = assets_options.method;
Expand Down
Loading

0 comments on commit 8b8c75f

Please sign in to comment.