From 556e90603aff2dae00403ab6567d773b4ff2bb77 Mon Sep 17 00:00:00 2001 From: Sean Sullivan <22581534+sullivan-sean@users.noreply.github.com> Date: Fri, 23 Sep 2022 08:19:54 -0700 Subject: [PATCH] Add support for platform specific dependencies (#153) --- src/skeleton/version_masking.rs | 37 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/skeleton/version_masking.rs b/src/skeleton/version_masking.rs index cfa3c00..869feed 100644 --- a/src/skeleton/version_masking.rs +++ b/src/skeleton/version_masking.rs @@ -57,23 +57,22 @@ fn mask_local_versions_in_manifests( *version = toml::Value::String(CONST_VERSION.to_string()); } } - mask_local_dependency_versions(local_package_names, manifest, "dependencies"); - mask_local_dependency_versions(local_package_names, manifest, "dev-dependencies"); - mask_local_dependency_versions(local_package_names, manifest, "build-dependencies"); + mask_local_dependency_versions(local_package_names, manifest); } } -fn mask_local_dependency_versions( +fn mask_dependencies_in_value( local_package_names: &[toml::Value], - manifest: &mut ParsedManifest, - dependency_key: &str, + toml_value: &mut toml::Value, ) { - if let Some(dependencies) = manifest.contents.get_mut(dependency_key) { - for local_package in local_package_names.iter() { - if let toml::Value::String(local_package) = local_package { - if let Some(local_dependency) = dependencies.get_mut(local_package) { - if let Some(version) = local_dependency.get_mut("version") { - *version = toml::Value::String(CONST_VERSION.to_string()); + for dependency_key in ["dependencies", "dev-dependencies", "build-dependencies"] { + if let Some(dependencies) = toml_value.get_mut(dependency_key) { + for local_package in local_package_names.iter() { + if let toml::Value::String(local_package) = local_package { + if let Some(local_dependency) = dependencies.get_mut(local_package) { + if let Some(version) = local_dependency.get_mut("version") { + *version = toml::Value::String(CONST_VERSION.to_string()); + } } } } @@ -81,6 +80,20 @@ fn mask_local_dependency_versions( } } +fn mask_local_dependency_versions( + local_package_names: &[toml::Value], + manifest: &mut ParsedManifest, +) { + mask_dependencies_in_value(local_package_names, &mut manifest.contents); + if let Some(targets) = manifest.contents.get_mut("target") { + if let Some(target_table) = targets.as_table_mut() { + for (_, mut target_config) in target_table.iter_mut() { + mask_dependencies_in_value(local_package_names, &mut target_config) + } + } + } +} + fn parse_local_crate_names(manifests: &[ParsedManifest]) -> Vec { let mut local_package_names = vec![]; for manifest in manifests.iter() {