diff options
Diffstat (limited to 'release/src/main.rs')
| -rw-r--r-- | release/src/main.rs | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/release/src/main.rs b/release/src/main.rs index 769611c78..0dbcc5d45 100644 --- a/release/src/main.rs +++ b/release/src/main.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | use simple_logger::SimpleLogger; | ||
| 1 | use std::collections::{BTreeMap, HashMap}; | 2 | use std::collections::{BTreeMap, HashMap}; |
| 2 | use std::fs; | 3 | use std::fs; |
| 3 | use std::path::{Path, PathBuf}; | 4 | use std::path::{Path, PathBuf}; |
| @@ -11,6 +12,8 @@ use petgraph::{Directed, Direction}; | |||
| 11 | use toml_edit::{DocumentMut, Item, Value}; | 12 | use toml_edit::{DocumentMut, Item, Value}; |
| 12 | use types::*; | 13 | use types::*; |
| 13 | 14 | ||
| 15 | mod cargo; | ||
| 16 | mod semver_check; | ||
| 14 | mod types; | 17 | mod types; |
| 15 | 18 | ||
| 16 | /// Tool to traverse and operate on intra-repo Rust crate dependencies | 19 | /// Tool to traverse and operate on intra-repo Rust crate dependencies |
| @@ -70,7 +73,7 @@ fn load_release_config(repo: &Path) -> ReleaseConfig { | |||
| 70 | } | 73 | } |
| 71 | 74 | ||
| 72 | fn update_version(c: &mut Crate, new_version: &str) -> Result<()> { | 75 | fn update_version(c: &mut Crate, new_version: &str) -> Result<()> { |
| 73 | let path = &c.path; | 76 | let path = c.path.join("Cargo.toml"); |
| 74 | c.version = new_version.to_string(); | 77 | c.version = new_version.to_string(); |
| 75 | let content = fs::read_to_string(&path)?; | 78 | let content = fs::read_to_string(&path)?; |
| 76 | let mut doc: DocumentMut = content.parse()?; | 79 | let mut doc: DocumentMut = content.parse()?; |
| @@ -84,7 +87,7 @@ fn update_version(c: &mut Crate, new_version: &str) -> Result<()> { | |||
| 84 | } | 87 | } |
| 85 | 88 | ||
| 86 | fn update_versions(to_update: &Crate, dep: &CrateId, new_version: &str) -> Result<()> { | 89 | fn update_versions(to_update: &Crate, dep: &CrateId, new_version: &str) -> Result<()> { |
| 87 | let path = &to_update.path; | 90 | let path = to_update.path.join("Cargo.toml"); |
| 88 | let content = fs::read_to_string(&path)?; | 91 | let content = fs::read_to_string(&path)?; |
| 89 | let mut doc: DocumentMut = content.parse()?; | 92 | let mut doc: DocumentMut = content.parse()?; |
| 90 | let mut changed = false; | 93 | let mut changed = false; |
| @@ -117,15 +120,16 @@ fn update_versions(to_update: &Crate, dep: &CrateId, new_version: &str) -> Resul | |||
| 117 | Ok(()) | 120 | Ok(()) |
| 118 | } | 121 | } |
| 119 | 122 | ||
| 120 | fn list_crates(path: &PathBuf) -> Result<BTreeMap<CrateId, Crate>> { | 123 | fn list_crates(root: &PathBuf) -> Result<BTreeMap<CrateId, Crate>> { |
| 121 | let d = std::fs::read_dir(path)?; | 124 | let d = std::fs::read_dir(root)?; |
| 122 | let release_config = load_release_config(path); | 125 | let release_config = load_release_config(root); |
| 123 | let mut crates = BTreeMap::new(); | 126 | let mut crates = BTreeMap::new(); |
| 124 | for c in d { | 127 | for c in d { |
| 125 | let entry = c?; | 128 | let entry = c?; |
| 126 | let name = entry.file_name().to_str().unwrap().to_string(); | 129 | let name = entry.file_name().to_str().unwrap().to_string(); |
| 127 | if entry.file_type()?.is_dir() && name.starts_with("embassy-") { | 130 | if entry.file_type()?.is_dir() && name.starts_with("embassy-") { |
| 128 | let entry = entry.path().join("Cargo.toml"); | 131 | let path = root.join(entry.path()); |
| 132 | let entry = path.join("Cargo.toml"); | ||
| 129 | if entry.exists() { | 133 | if entry.exists() { |
| 130 | let content = fs::read_to_string(&entry)?; | 134 | let content = fs::read_to_string(&entry)?; |
| 131 | let parsed: ParsedCrate = toml::from_str(&content)?; | 135 | let parsed: ParsedCrate = toml::from_str(&content)?; |
| @@ -138,7 +142,6 @@ fn list_crates(path: &PathBuf) -> Result<BTreeMap<CrateId, Crate>> { | |||
| 138 | } | 142 | } |
| 139 | } | 143 | } |
| 140 | 144 | ||
| 141 | let path = path.join(entry); | ||
| 142 | if let Some(config) = release_config.get(&id) { | 145 | if let Some(config) = release_config.get(&id) { |
| 143 | crates.insert( | 146 | crates.insert( |
| 144 | id.clone(), | 147 | id.clone(), |
| @@ -191,6 +194,7 @@ fn build_graph(crates: &BTreeMap<CrateId, Crate>) -> (Graph<CrateId, ()>, HashMa | |||
| 191 | } | 194 | } |
| 192 | 195 | ||
| 193 | fn main() -> Result<()> { | 196 | fn main() -> Result<()> { |
| 197 | SimpleLogger::new().init().unwrap(); | ||
| 194 | let args = Args::parse(); | 198 | let args = Args::parse(); |
| 195 | 199 | ||
| 196 | let root = args.repo.canonicalize()?; | 200 | let root = args.repo.canonicalize()?; |
| @@ -306,7 +310,7 @@ fn main() -> Result<()> { | |||
| 306 | let mut args: Vec<String> = vec![ | 310 | let mut args: Vec<String> = vec![ |
| 307 | "publish".to_string(), | 311 | "publish".to_string(), |
| 308 | "--manifest-path".to_string(), | 312 | "--manifest-path".to_string(), |
| 309 | c.path.display().to_string(), | 313 | c.path.join("Cargo.toml").display().to_string(), |
| 310 | ]; | 314 | ]; |
| 311 | 315 | ||
| 312 | if let Some(features) = &c.config.features { | 316 | if let Some(features) = &c.config.features { |
| @@ -337,26 +341,9 @@ fn main() -> Result<()> { | |||
| 337 | } | 341 | } |
| 338 | 342 | ||
| 339 | fn check_semver(c: &Crate) -> Result<()> { | 343 | fn check_semver(c: &Crate) -> Result<()> { |
| 340 | let mut args: Vec<String> = vec![ | 344 | let min_version = semver_check::minimum_update(c)?; |
| 341 | "semver-checks".to_string(), | 345 | println!("Version should be bumped to {:?}", min_version); |
| 342 | "--manifest-path".to_string(), | 346 | Ok(()) |
| 343 | c.path.display().to_string(), | ||
| 344 | "--default-features".to_string(), | ||
| 345 | ]; | ||
| 346 | if let Some(features) = &c.config.features { | ||
| 347 | args.push("--features".into()); | ||
| 348 | args.push(features.join(",")); | ||
| 349 | } | ||
| 350 | |||
| 351 | let status = ProcessCommand::new("cargo").args(&args).output()?; | ||
| 352 | |||
| 353 | println!("{}", core::str::from_utf8(&status.stdout).unwrap()); | ||
| 354 | eprintln!("{}", core::str::from_utf8(&status.stderr).unwrap()); | ||
| 355 | if !status.status.success() { | ||
| 356 | return Err(anyhow!("semver check failed")); | ||
| 357 | } else { | ||
| 358 | Ok(()) | ||
| 359 | } | ||
| 360 | } | 347 | } |
| 361 | 348 | ||
| 362 | fn update_changelog(repo: &Path, c: &Crate) -> Result<()> { | 349 | fn update_changelog(repo: &Path, c: &Crate) -> Result<()> { |
| @@ -366,7 +353,7 @@ fn update_changelog(repo: &Path, c: &Crate) -> Result<()> { | |||
| 366 | "--config".to_string(), | 353 | "--config".to_string(), |
| 367 | repo.join("release").join("release.toml").display().to_string(), | 354 | repo.join("release").join("release.toml").display().to_string(), |
| 368 | "--manifest-path".to_string(), | 355 | "--manifest-path".to_string(), |
| 369 | c.path.display().to_string(), | 356 | c.path.join("Cargo.toml").display().to_string(), |
| 370 | "--execute".to_string(), | 357 | "--execute".to_string(), |
| 371 | "--no-confirm".to_string(), | 358 | "--no-confirm".to_string(), |
| 372 | ]; | 359 | ]; |
| @@ -386,7 +373,7 @@ fn publish_release(_repo: &Path, c: &Crate, push: bool) -> Result<()> { | |||
| 386 | let mut args: Vec<String> = vec![ | 373 | let mut args: Vec<String> = vec![ |
| 387 | "publish".to_string(), | 374 | "publish".to_string(), |
| 388 | "--manifest-path".to_string(), | 375 | "--manifest-path".to_string(), |
| 389 | c.path.display().to_string(), | 376 | c.path.join("Cargo.toml").display().to_string(), |
| 390 | ]; | 377 | ]; |
| 391 | 378 | ||
| 392 | if let Some(features) = &c.config.features { | 379 | if let Some(features) = &c.config.features { |
| @@ -415,3 +402,8 @@ fn publish_release(_repo: &Path, c: &Crate, push: bool) -> Result<()> { | |||
| 415 | Ok(()) | 402 | Ok(()) |
| 416 | } | 403 | } |
| 417 | } | 404 | } |
| 405 | |||
| 406 | /// Make the path "Windows"-safe | ||
| 407 | pub fn windows_safe_path(path: &Path) -> PathBuf { | ||
| 408 | PathBuf::from(path.to_str().unwrap().to_string().replace("\\\\?\\", "")) | ||
| 409 | } | ||
