MCPcopy Create free account
hub / github.com/SeaQL/FireDBG.for.Rust / cache_workspace

Function cache_workspace

command/src/main.rs:491–563  ·  view source on GitHub ↗
(workspace: &Workspace)

Source from the content-addressed store, hash-verified

489}
490
491async fn cache_workspace(workspace: &Workspace) -> Result<()> {
492 let workspace_root_dir = &workspace.root_dir;
493 let firedbg_dir = &workspace.get_firedbg_dir();
494
495 let mut cache_skip = 0;
496 let mut cache_refresh = 0;
497 for package in workspace.packages.iter() {
498 let regex = &format!("{}/**/*.rs", package.root_dir).replace("//", "/");
499 let context = || format!("Invalid glob regex: `{regex}`");
500 for src_file in glob(regex).with_context(context)?.filter_map(Result::ok) {
501 // abs_file_path = /Applications/MAMP/htdocs/FireDBG.for.Rust.Internal/codelldb/adapter/crates/lldb/src/sb/sbtypeenummember.rs
502 // parent_dir = /Applications/MAMP/htdocs/FireDBG.for.Rust.Internal/codelldb/adapter/crates/lldb/src/sb
503 // workspace_root_dir = /Applications/MAMP/htdocs/FireDBG.for.Rust.Internal
504 // rel_path = codelldb/adapter/crates/lldb/src/sb
505 // file_name = sbtypeenummember.rs
506 // map_dir = /Applications/MAMP/htdocs/FireDBG.for.Rust.Internal/firedbg/codelldb/adapter/crates/lldb/src/sb
507 // map_path = /Applications/MAMP/htdocs/FireDBG.for.Rust.Internal/firedbg/codelldb/adapter/crates/lldb/src/sb/sbtypeenummember.rs.firedbg.map
508 let abs_file_path = path_to_str(&src_file);
509 let parent_dir = path_to_str(src_file.parent().expect("Parent directory not found"));
510 let rel_path = &parent_dir[workspace_root_dir.len()..];
511 let file_name = path_file_name(&src_file);
512 let map_dir = &format!("{firedbg_dir}{rel_path}");
513 let map_path = &format!("{map_dir}/{file_name}.firedbg.map");
514
515 // Skip caching if the `src_file` has older modified timestamp than the `map_file`
516 let src_modified = src_file.metadata()?.modified()?;
517 let map_file = Path::new(map_path);
518 if map_file.is_file() {
519 let map_modified = map_file.metadata()?.modified()?;
520 if src_modified <= map_modified {
521 log::debug!("parser_cache_skip `{abs_file_path}`");
522 cache_skip += 1;
523 continue;
524 }
525 }
526 log::debug!("parser_cache_create `{abs_file_path}`");
527 cache_refresh += 1;
528
529 let functions = parse_file(abs_file_path).unwrap_or_else(|e| {
530 console::warn(
531 "Parsing",
532 &format!("fail to parse and cache source file `{abs_file_path}`; {e}"),
533 );
534 Vec::new()
535 });
536
537 let content = File {
538 path: abs_file_path.into(),
539 functions,
540 crate_name: package.get_crate_name(),
541 modified: src_modified,
542 };
543 create_dir_all(map_dir)
544 .await
545 .with_context(|| format!("Fail to create directory: `{map_dir}`"))?;
546 to_bson_file(map_path, &content)
547 .await
548 .with_context(|| format!("Fail to create BSON file: `{map_path}`"))?;

Callers 1

mainFunction · 0.85

Calls 11

path_file_nameFunction · 0.85
parse_fileFunction · 0.85
warnFunction · 0.85
to_bson_fileFunction · 0.85
to_json_fileFunction · 0.85
statusFunction · 0.85
get_firedbg_dirMethod · 0.80
get_crate_nameMethod · 0.80
path_to_strFunction · 0.70
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected