(args: Args)
| 79 | } |
| 80 | |
| 81 | pub fn run(args: Args) -> Result<()> { |
| 82 | let (target_path, base_path, project_config, unit_options) = |
| 83 | match (&args.target, &args.base, &args.project, &args.unit) { |
| 84 | (Some(_), Some(_), None, None) |
| 85 | | (Some(_), None, None, None) |
| 86 | | (None, Some(_), None, None) => (args.target.clone(), args.base.clone(), None, None), |
| 87 | (None, None, p, u) => { |
| 88 | let project = match p { |
| 89 | Some(project) => project.clone(), |
| 90 | _ => check_path_buf( |
| 91 | std::env::current_dir().context("Failed to get the current directory")?, |
| 92 | ) |
| 93 | .context("Current directory is not valid UTF-8")?, |
| 94 | }; |
| 95 | let Some((project_config, project_config_info)) = |
| 96 | objdiff_core::config::try_project_config(project.as_ref()) |
| 97 | else { |
| 98 | bail!("Project config not found in {}", &project) |
| 99 | }; |
| 100 | let project_config = project_config.with_context(|| { |
| 101 | format!("Reading project config {}", project_config_info.path.display()) |
| 102 | })?; |
| 103 | let target_obj_dir = project_config |
| 104 | .target_dir |
| 105 | .as_ref() |
| 106 | .map(|p| project.join(p.with_platform_encoding())); |
| 107 | let base_obj_dir = project_config |
| 108 | .base_dir |
| 109 | .as_ref() |
| 110 | .map(|p| project.join(p.with_platform_encoding())); |
| 111 | let units = project_config.units.as_deref().unwrap_or_default(); |
| 112 | let objects = units |
| 113 | .iter() |
| 114 | .enumerate() |
| 115 | .map(|(idx, o)| { |
| 116 | ( |
| 117 | ObjectConfig::new( |
| 118 | o, |
| 119 | &project, |
| 120 | target_obj_dir.as_deref(), |
| 121 | base_obj_dir.as_deref(), |
| 122 | ), |
| 123 | idx, |
| 124 | ) |
| 125 | }) |
| 126 | .collect::<Vec<_>>(); |
| 127 | let (object, unit_idx) = if let Some(u) = u { |
| 128 | objects |
| 129 | .iter() |
| 130 | .find(|(obj, _)| obj.name == *u) |
| 131 | .map(|(obj, idx)| (obj, *idx)) |
| 132 | .ok_or_else(|| anyhow!("Unit not found: {}", u))? |
| 133 | } else if let Some(symbol_name) = &args.symbol { |
| 134 | let mut idx = None; |
| 135 | let mut count = 0usize; |
| 136 | for (i, (obj, unit_idx)) in objects.iter().enumerate() { |
| 137 | if obj |
| 138 | .target_path |
no test coverage detected