From 57fc5df858e7526108a8b7df46ed245f09f8ce2f Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Mon, 11 Nov 2024 23:08:32 -0800 Subject: [PATCH] Modify `bump-version` subcommand to also bump dependent packages' dependencies (#2514) --- xtask/src/lib.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 043cdda2e..c807586a4 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -433,6 +433,33 @@ pub fn bump_version(workspace: &Path, package: Package, amount: Version) -> Resu manifest["package"]["version"] = toml_edit::value(version.to_string()); fs::write(manifest_path, manifest.to_string())?; + for pkg in + Package::iter().filter(|p| ![package, Package::Examples, Package::HilTest].contains(p)) + { + let manifest_path = workspace.join(pkg.to_string()).join("Cargo.toml"); + let manifest = fs::read_to_string(&manifest_path) + .with_context(|| format!("Could not read {}", manifest_path.display()))?; + + let mut manifest = manifest.parse::()?; + + if manifest["dependencies"] + .as_table() + .unwrap() + .contains_key(&package.to_string()) + { + log::info!( + " Bumping {package} version for package {pkg}: ({prev_version} -> {version})" + ); + + manifest["dependencies"].as_table_mut().map(|table| { + table[&package.to_string()]["version"] = toml_edit::value(version.to_string()) + }); + + fs::write(&manifest_path, manifest.to_string()) + .with_context(|| format!("Could not write {}", manifest_path.display()))?; + } + } + Ok(()) }