Skip to content

Commit 04be189

Browse files
authored
Honor symbol mappings in CLI diffs (#378)
1 parent 4d0a273 commit 04be189

2 files changed

Lines changed: 41 additions & 10 deletions

File tree

objdiff-cli/src/cmd/diff.rs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
collections::BTreeMap,
23
io::stdout,
34
mem,
45
sync::{
@@ -79,11 +80,13 @@ pub struct Args {
7980
}
8081

8182
pub fn run(args: Args) -> Result<()> {
82-
let (target_path, base_path, project_config, unit_options) =
83+
let (target_path, base_path, project_config, unit_options, symbol_mappings) =
8384
match (&args.target, &args.base, &args.project, &args.unit) {
8485
(Some(_), Some(_), None, None)
8586
| (Some(_), None, None, None)
86-
| (None, Some(_), None, None) => (args.target.clone(), args.base.clone(), None, None),
87+
| (None, Some(_), None, None) => {
88+
(args.target.clone(), args.base.clone(), None, None, BTreeMap::new())
89+
}
8790
(None, None, p, u) => {
8891
let project = match p {
8992
Some(project) => project.clone(),
@@ -163,15 +166,24 @@ pub fn run(args: Args) -> Result<()> {
163166
let unit_options = units.get(unit_idx).and_then(|u| u.options().cloned());
164167
let target_path = object.target_path.clone();
165168
let base_path = object.base_path.clone();
166-
(target_path, base_path, Some(project_config), unit_options)
169+
let symbol_mappings = object.symbol_mappings.clone();
170+
(target_path, base_path, Some(project_config), unit_options, symbol_mappings)
167171
}
168172
_ => bail!("Either target and base or project and unit must be specified"),
169173
};
170174

171175
if let Some(output) = &args.output {
172-
run_oneshot(&args, output, target_path.as_deref(), base_path.as_deref(), unit_options)
176+
run_oneshot(
177+
&args,
178+
output,
179+
target_path.as_deref(),
180+
base_path.as_deref(),
181+
project_config.as_ref(),
182+
unit_options,
183+
&symbol_mappings,
184+
)
173185
} else {
174-
run_interactive(args, target_path, base_path, project_config, unit_options)
186+
run_interactive(args, target_path, base_path, project_config, unit_options, symbol_mappings)
175187
}
176188
}
177189

@@ -180,10 +192,13 @@ fn run_oneshot(
180192
output: &Utf8PlatformPath,
181193
target_path: Option<&Utf8PlatformPath>,
182194
base_path: Option<&Utf8PlatformPath>,
195+
project_config: Option<&ProjectConfig>,
183196
unit_options: Option<ProjectOptions>,
197+
symbol_mappings: &BTreeMap<String, String>,
184198
) -> Result<()> {
185199
let output_format = OutputFormat::from_option(args.format.as_deref())?;
186-
let (diff_config, mapping_config) = build_config_from_args(args, None, unit_options.as_ref())?;
200+
let (diff_config, mapping_config) =
201+
build_config_from_args(args, project_config, unit_options.as_ref(), symbol_mappings)?;
187202
let target = target_path
188203
.map(|p| {
189204
obj::read::read(p.as_ref(), &diff_config, DiffSide::Target)
@@ -209,6 +224,7 @@ fn build_config_from_args(
209224
args: &Args,
210225
project_config: Option<&ProjectConfig>,
211226
unit_options: Option<&ProjectOptions>,
227+
symbol_mappings: &BTreeMap<String, String>,
212228
) -> Result<(DiffObjConfig, MappingConfig)> {
213229
let mut diff_config = DiffObjConfig::default();
214230
if let Some(options) = project_config.and_then(|config| config.options.as_ref()) {
@@ -218,7 +234,11 @@ fn build_config_from_args(
218234
apply_project_options(&mut diff_config, options)?;
219235
}
220236
apply_config_args(&mut diff_config, &args.config)?;
221-
Ok((diff_config, MappingConfig::default()))
237+
Ok((diff_config, MappingConfig {
238+
mappings: symbol_mappings.clone(),
239+
selecting_left: None,
240+
selecting_right: None,
241+
}))
222242
}
223243

224244
pub struct AppState {
@@ -279,6 +299,7 @@ pub struct ObjectConfig {
279299
pub base_path: Option<Utf8PlatformPathBuf>,
280300
pub metadata: ProjectObjectMetadata,
281301
pub complete: Option<bool>,
302+
pub symbol_mappings: BTreeMap<String, String>,
282303
}
283304

284305
impl ObjectConfig {
@@ -308,6 +329,7 @@ impl ObjectConfig {
308329
base_path,
309330
metadata: object.metadata.clone().unwrap_or_default(),
310331
complete: object.complete(),
332+
symbol_mappings: object.symbol_mappings.clone().unwrap_or_default(),
311333
}
312334
}
313335
}
@@ -358,12 +380,17 @@ fn run_interactive(
358380
base_path: Option<Utf8PlatformPathBuf>,
359381
project_config: Option<ProjectConfig>,
360382
unit_options: Option<ProjectOptions>,
383+
symbol_mappings: BTreeMap<String, String>,
361384
) -> Result<()> {
362385
let Some(symbol_name) = &args.symbol else { bail!("Interactive mode requires a symbol name") };
363386
let time_format = time::format_description::parse_borrowed::<2>("[hour]:[minute]:[second]")
364387
.context("Failed to parse time format")?;
365-
let (diff_obj_config, mapping_config) =
366-
build_config_from_args(&args, project_config.as_ref(), unit_options.as_ref())?;
388+
let (diff_obj_config, mapping_config) = build_config_from_args(
389+
&args,
390+
project_config.as_ref(),
391+
unit_options.as_ref(),
392+
&symbol_mappings,
393+
)?;
367394
let mut state = AppState {
368395
jobs: Default::default(),
369396
waker: Default::default(),

objdiff-cli/src/cmd/report.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ fn report_object(
210210
}
211211
_ => {}
212212
}
213-
let mapping_config = diff::MappingConfig::default();
213+
let mapping_config = diff::MappingConfig {
214+
mappings: object.symbol_mappings.clone(),
215+
selecting_left: None,
216+
selecting_right: None,
217+
};
214218
let target = object
215219
.target_path
216220
.as_ref()

0 commit comments

Comments
 (0)