@@ -38,10 +38,10 @@ struct Opt {
38
38
inputs : Vec < PathBuf > ,
39
39
/// Specify path to executables to read list of dwarf objects from
40
40
#[ 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 > ,
45
45
}
46
46
47
47
/// Implementation of `thorin::Session` using `typed_arena` and `memmap2`.
@@ -146,29 +146,36 @@ fn main() -> Result<()> {
146
146
let mut package = thorin:: DwarfPackage :: new ( & sess) ;
147
147
148
148
// 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 ( ) {
150
150
return Ok ( ( ) ) ;
151
151
}
152
152
153
- for input in opt. inputs {
153
+ for input in & opt. inputs {
154
154
package
155
- . add_input_object ( & input)
155
+ . add_input_object ( input)
156
156
. with_context ( || Error :: AddInputObject ( input. display ( ) . to_string ( ) ) ) ?;
157
157
}
158
158
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 ( ) ) ) ?;
168
166
}
169
167
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 ( ) ) ) ?;
172
179
let mut output_stream = StreamingBuffer :: new ( BufWriter :: new ( output_stream) ) ;
173
180
package
174
181
. finish ( )
0 commit comments