diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-08-15 19:06:51 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2025-08-25 19:44:50 +0200 |
| commit | 0d8f9614a1af5a45b695e6f63b0337fc3bccba76 (patch) | |
| tree | 25bf962ac83685d5059e9a028ced9fa0cd0d1369 /release/src | |
| parent | 3a6ea3a31c90179fb3cbd30c18e3a310e2ee647c (diff) | |
Autodetect repo root.
Diffstat (limited to 'release/src')
| -rw-r--r-- | release/src/main.rs | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/release/src/main.rs b/release/src/main.rs index 5605ca332..f1949dd37 100644 --- a/release/src/main.rs +++ b/release/src/main.rs | |||
| @@ -41,10 +41,6 @@ mod types; | |||
| 41 | #[derive(Parser, Debug)] | 41 | #[derive(Parser, Debug)] |
| 42 | #[command(author, version, about)] | 42 | #[command(author, version, about)] |
| 43 | struct Args { | 43 | struct Args { |
| 44 | /// Path to embassy repository | ||
| 45 | #[arg(short, long)] | ||
| 46 | repo: PathBuf, | ||
| 47 | |||
| 48 | /// Command to perform on each crate | 44 | /// Command to perform on each crate |
| 49 | #[command(subcommand)] | 45 | #[command(subcommand)] |
| 50 | command: Command, | 46 | command: Command, |
| @@ -247,8 +243,29 @@ struct Context { | |||
| 247 | indices: HashMap<String, NodeIndex>, | 243 | indices: HashMap<String, NodeIndex>, |
| 248 | } | 244 | } |
| 249 | 245 | ||
| 250 | fn load_context(args: &Args) -> Result<Context> { | 246 | fn find_repo_root() -> Result<PathBuf> { |
| 251 | let root = args.repo.canonicalize()?; | 247 | let mut path = std::env::current_dir()?.canonicalize()?; |
| 248 | |||
| 249 | loop { | ||
| 250 | // Check if this directory contains a .git directory | ||
| 251 | if path.join(".git").exists() { | ||
| 252 | return Ok(path); | ||
| 253 | } | ||
| 254 | |||
| 255 | // Move to parent directory | ||
| 256 | match path.parent() { | ||
| 257 | Some(parent) => path = parent.to_path_buf(), | ||
| 258 | None => break, | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | Err(anyhow!( | ||
| 263 | "Could not find repository root. Make sure you're running this tool from within the embassy repository." | ||
| 264 | )) | ||
| 265 | } | ||
| 266 | |||
| 267 | fn load_context() -> Result<Context> { | ||
| 268 | let root = find_repo_root()?; | ||
| 252 | let crates = list_crates(&root)?; | 269 | let crates = list_crates(&root)?; |
| 253 | let (graph, indices) = build_graph(&crates); | 270 | let (graph, indices) = build_graph(&crates); |
| 254 | 271 | ||
| @@ -268,7 +285,7 @@ fn load_context(args: &Args) -> Result<Context> { | |||
| 268 | fn main() -> Result<()> { | 285 | fn main() -> Result<()> { |
| 269 | SimpleLogger::new().init().unwrap(); | 286 | SimpleLogger::new().init().unwrap(); |
| 270 | let args = Args::parse(); | 287 | let args = Args::parse(); |
| 271 | let mut ctx = load_context(&args)?; | 288 | let mut ctx = load_context()?; |
| 272 | 289 | ||
| 273 | match args.command { | 290 | match args.command { |
| 274 | Command::List => { | 291 | Command::List => { |
