Skip to content

Commit

Permalink
override name & id fields for dev-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
boozook committed May 19, 2024
1 parent 6d7606f commit 4eba406
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions cargo/src/package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,28 +278,40 @@ fn build_manifest<Layout: playdate::layout::Layout>(config: &Config,
layout: &Layout,
package: &Package,
assets: Option<&AssetsArtifact<'_>>,
dev_id_suffix: Option<Cow<'_, str>>,
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);
});

if dev_id_suffix.is_some() || name_override.is_some() {
// TODO: modify ManifestSource
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 bot-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();
}
}

let 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))?;
std::fs::write(layout.manifest(), manifest.to_manifest_string())?;
Ok(())
}
Expand Down

0 comments on commit 4eba406

Please sign in to comment.