Skip to content

Commit baddbb1

Browse files
khueydavidtwco
authored andcommitted
When a single executable is passed, default the output filename to executable.dwp
This matches the binutils dwp behavior.
1 parent 3df019d commit baddbb1

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

thorin-bin/src/main.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ struct Opt {
3838
inputs: Vec<PathBuf>,
3939
/// Specify path to executables to read list of dwarf objects from
4040
#[structopt(short = "e", long = "exec", parse(from_os_str))]
41-
executables: Option<Vec<PathBuf>>,
42-
/// Specify path to write the dwarf package to
43-
#[structopt(short = "o", long = "output", parse(from_os_str), default_value = "-")]
44-
output: PathBuf,
41+
executables: Vec<PathBuf>,
42+
/// Specify path to write the dwarf package to [default: -]
43+
#[structopt(short = "o", long = "output", parse(from_os_str))]
44+
output: Option<PathBuf>,
4545
}
4646

4747
/// Implementation of `thorin::Session` using `typed_arena` and `memmap2`.
@@ -146,29 +146,36 @@ fn main() -> Result<()> {
146146
let mut package = thorin::DwarfPackage::new(&sess);
147147

148148
// Return early if there isn't any input.
149-
if opt.inputs.is_empty() && opt.executables.is_none() {
149+
if opt.inputs.is_empty() && opt.executables.is_empty() {
150150
return Ok(());
151151
}
152152

153-
for input in opt.inputs {
153+
for input in &opt.inputs {
154154
package
155-
.add_input_object(&input)
155+
.add_input_object(input)
156156
.with_context(|| Error::AddInputObject(input.display().to_string()))?;
157157
}
158158

159-
if let Some(executables) = opt.executables {
160-
for executable in executables {
161-
// Failing to read the referenced object might be expected if the path referenced by
162-
// the executable isn't found but the referenced DWARF object is later found as an
163-
// input - calling `finish` will return an error in this case.
164-
package
165-
.add_executable(&executable, thorin::MissingReferencedObjectBehaviour::Skip)
166-
.with_context(|| Error::AddExecutable(executable.display().to_string()))?;
167-
}
159+
for executable in &opt.executables {
160+
// Failing to read the referenced object might be expected if the path referenced by
161+
// the executable isn't found but the referenced DWARF object is later found as an
162+
// input - calling `finish` will return an error in this case.
163+
package
164+
.add_executable(executable, thorin::MissingReferencedObjectBehaviour::Skip)
165+
.with_context(|| Error::AddExecutable(executable.display().to_string()))?;
168166
}
169167

170-
let output_stream = Output::new(opt.output.as_ref())
171-
.with_context(|| Error::CreateOutputFile(opt.output.display().to_string()))?;
168+
let output = opt.output.unwrap_or_else(|| {
169+
if opt.executables.len() == 1 {
170+
let mut path = opt.executables.first().unwrap().clone().into_os_string();
171+
path.push(".dwp");
172+
PathBuf::from(path)
173+
} else {
174+
PathBuf::from("-")
175+
}
176+
});
177+
let output_stream = Output::new(output.as_os_str())
178+
.with_context(|| Error::CreateOutputFile(output.display().to_string()))?;
172179
let mut output_stream = StreamingBuffer::new(BufWriter::new(output_stream));
173180
package
174181
.finish()

0 commit comments

Comments
 (0)