Skip to content

Commit

Permalink
Add support for platform specific dependencies (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
sullivan-sean authored Sep 23, 2022
1 parent 4e2dedd commit 556e906
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/skeleton/version_masking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,43 @@ 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());
}
}
}
}
}
}
}

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<toml::Value> {
let mut local_package_names = vec![];
for manifest in manifests.iter() {
Expand Down

0 comments on commit 556e906

Please sign in to comment.