From 33fa4aa60fc7ca9cc392445cdfff192d5320dd06 Mon Sep 17 00:00:00 2001 From: Alexander Koz Date: Wed, 15 May 2024 00:36:52 +0400 Subject: [PATCH] override (fix) manifest fields (id & name) for examples, wip --- cargo/src/package/mod.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/cargo/src/package/mod.rs b/cargo/src/package/mod.rs index b2da09ca..99bc1b00 100644 --- a/cargo/src/package/mod.rs +++ b/cargo/src/package/mod.rs @@ -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)?; @@ -217,7 +219,7 @@ 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"); @@ -225,7 +227,7 @@ fn package_multi_target<'p>(config: &Config, soft_link_checked(&product.path, &dst, true, layout.as_inner().target())?; if product.example { - has_dev = true; + dev = Some(product); } } @@ -237,7 +239,7 @@ fn package_multi_target<'p>(config: &Config, prepare_assets( config, assets, - has_dev, + dev.is_some(), layout.build(), true, layout.as_inner().target(), @@ -245,7 +247,9 @@ fn package_multi_target<'p>(config: &Config, } // 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)?; @@ -273,20 +277,28 @@ fn package_multi_target<'p>(config: &Config, fn build_manifest(config: &Config, layout: &Layout, package: &Package, - assets: Option<&AssetsArtifact<'_>>) + assets: Option<&AssetsArtifact<'_>>, + dev_id_suffix: Option>, + name_override: Option>) -> 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 manifest = if let Some(metadata) = assets.and_then(|a| a.metadata.as_ref()) { - Manifest::try_from_source(ManifestSource { package, - metadata: metadata.into() }) + let source = ManifestSource { package, + metadata: metadata.into() }; + Manifest::try_from_source(source) } else { let metadata = playdate_metadata(package); - Manifest::try_from_source(ManifestSource { package, - metadata: metadata.as_ref() }) + 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(())