Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for platform specific dependencies #153

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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