aboutsummaryrefslogtreecommitdiff
path: root/release/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'release/src/main.rs')
-rw-r--r--release/src/main.rs31
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)]
43struct Args { 43struct 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
250fn load_context(args: &Args) -> Result<Context> { 246fn 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
267fn 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> {
268fn main() -> Result<()> { 285fn 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 => {