| 301 | } |
| 302 | |
| 303 | fn bump_version(krate: &Crate, crates: &[Crate], patch: bool) { |
| 304 | println!("bumping `{}`...", krate.name); |
| 305 | let contents = fs::read_to_string(&krate.manifest).unwrap(); |
| 306 | let next_version = |krate: &Crate| -> String { |
| 307 | if krate.publish { |
| 308 | bump(&krate.version, patch) |
| 309 | } else { |
| 310 | krate.version.clone() |
| 311 | } |
| 312 | }; |
| 313 | |
| 314 | let mut new_manifest = String::new(); |
| 315 | let mut is_deps = false; |
| 316 | for line in contents.lines() { |
| 317 | let mut rewritten = false; |
| 318 | if !is_deps && line.starts_with("version =") { |
| 319 | if krate.publish { |
| 320 | println!(" {} => {}", krate.version, next_version(krate)); |
| 321 | new_manifest.push_str(&line.replace(&krate.version, &next_version(krate))); |
| 322 | rewritten = true; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | is_deps = if line.starts_with("[") { |
| 327 | line.contains("dependencies") |
| 328 | } else { |
| 329 | is_deps |
| 330 | }; |
| 331 | |
| 332 | for other in crates { |
| 333 | // If `other` isn't a published crate then it's not going to get a |
| 334 | // bumped version so we don't need to update anything in the |
| 335 | // manifest. |
| 336 | if !other.publish { |
| 337 | continue; |
| 338 | } |
| 339 | if !is_deps |
| 340 | || (!line.starts_with(&format!("{} ", other.name)) |
| 341 | && !(line.contains(&format!("package = '{}'", other.name)) |
| 342 | || line.contains(&format!("package = \"{}\"", other.name)))) |
| 343 | { |
| 344 | continue; |
| 345 | } |
| 346 | if !line.contains(&other.version) { |
| 347 | if !line.contains("version =") || !krate.publish { |
| 348 | continue; |
| 349 | } |
| 350 | panic!( |
| 351 | "{:?} has a dep on {} but doesn't list version {}", |
| 352 | krate.manifest, other.name, other.version |
| 353 | ); |
| 354 | } |
| 355 | if krate.publish { |
| 356 | if PUBLIC_CRATES.contains(&other.name.as_str()) { |
| 357 | assert!( |
| 358 | !line.contains("\"="), |
| 359 | "{} should not have an exact version requirement on {}", |
| 360 | krate.name, |