-
-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathupload.rs
More file actions
330 lines (307 loc) · 12.5 KB
/
upload.rs
File metadata and controls
330 lines (307 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
use std::collections::BTreeSet;
use std::str::{self, FromStr as _};
use std::time::Duration;
use anyhow::{bail, format_err, Result};
use clap::{builder::PossibleValuesParser, Arg, ArgAction, ArgMatches, Command};
use console::style;
use itertools::Itertools as _;
use symbolic::common::DebugId;
use symbolic::debuginfo::FileFormat;
use crate::config::Config;
use crate::constants::DEFAULT_MAX_WAIT;
use crate::utils::args::ArgExt as _;
use crate::utils::dif::{DifType, ObjectDifFeatures};
use crate::utils::dif_upload::{DifFormat, DifUpload};
use crate::utils::system::QuietExit;
static DERIVED_DATA_FOLDER: &str = "Library/Developer/Xcode/DerivedData";
pub fn make_command(command: Command) -> Command {
let types = DifType::all_names()
.iter()
.filter(|&name| name != &"proguard")
.chain(&["bcsymbolmap"])
.sorted_by(|a, b| Ord::cmp(&a, &b))
.collect::<Vec<_>>();
command
.about("Upload debugging information files.")
.org_arg()
.project_arg(false)
.arg(
Arg::new("paths")
.value_name("PATH")
.help("A path to search recursively for symbol files.")
.num_args(1..)
.action(ArgAction::Append),
)
.arg(
Arg::new("types")
.long("type")
.short('t')
.value_name("TYPE")
.action(ArgAction::Append)
.value_parser(PossibleValuesParser::new(types))
.help(
"Only consider debug information files of the given \
type. By default, all types are considered.",
),
)
.arg(
Arg::new("no_unwind")
.long("no-unwind")
.alias("no-bin")
.action(ArgAction::SetTrue)
.help(
"Do not scan for stack unwinding information. Specify \
this flag for builds with disabled FPO, or when \
stackwalking occurs on the device. This usually \
excludes executables and dynamic libraries. They might \
still be uploaded, if they contain additional \
processable information (see other flags).",
),
)
.arg(
Arg::new("no_debug")
.long("no-debug")
.action(ArgAction::SetTrue)
.help(
"Do not scan for debugging information. This will \
usually exclude debug companion files. They might \
still be uploaded, if they contain additional \
processable information (see other flags).",
)
.conflicts_with("no_unwind"),
)
.arg(
Arg::new("no_sources")
.long("no-sources")
.action(ArgAction::SetTrue)
.help(
"Do not scan for source information. This will \
usually exclude source bundle files. They might \
still be uploaded, if they contain additional \
processable information (see other flags).",
),
)
.arg(
Arg::new("ids")
.value_name("ID")
.long("id")
.help("Search for specific debug identifiers.")
.value_parser(DebugId::from_str)
.action(ArgAction::Append),
)
.arg(
Arg::new("require_all")
.long("require-all")
.action(ArgAction::SetTrue)
.help("Errors if not all identifiers specified with --id could be found."),
)
.arg(
Arg::new("symbol_maps")
.long("symbol-maps")
.value_name("PATH")
.help(
"Optional path to BCSymbolMap files which are used to \
resolve hidden symbols in dSYM files downloaded from \
iTunes Connect. This requires the dsymutil tool to be \
available. This should not be used when using the App \
Store Connect integration, the .bcsymbolmap files needed \
for the integration are uploaded without this option if \
they are found in the PATH searched for symbol files.",
),
)
.arg(
Arg::new("derived_data")
.long("derived-data")
.action(ArgAction::SetTrue)
.help("Search for debug symbols in Xcode's derived data."),
)
.arg(
Arg::new("no_zips")
.long("no-zips")
.action(ArgAction::SetTrue)
.help("Do not search in ZIP files."),
)
.arg(
Arg::new("info_plist")
.long("info-plist")
.value_name("PATH")
.hide(true)
.help(
"This argument is deprecated. It does nothing and will be removed in a future release.",
),
)
.arg(
Arg::new("no_upload")
.long("no-upload")
.action(ArgAction::SetTrue)
.help(
"Disable the actual upload.{n}This runs all steps for the \
processing but does not trigger the upload. This is useful if you \
just want to verify the setup or skip the upload in tests.",
),
)
.arg(
Arg::new("force_foreground")
.hide(true)
.long("force-foreground")
.action(ArgAction::SetTrue)
.help(
"DEPRECATED: Foreground uploads are now the default behavior.{n}\
This flag has no effect and will be removed in a future version.",
),
)
.arg(
Arg::new("include_sources")
.long("include-sources")
.action(ArgAction::SetTrue)
.help(
"Include sources from the local file system and upload them as source bundles.",
),
)
.arg(
Arg::new("wait")
.long("wait")
.action(ArgAction::SetTrue)
.conflicts_with("wait_for")
.help(
"Wait for the server to fully process uploaded files. Errors \
can only be displayed if --wait or --wait-for is specified, but this will \
significantly slow down the upload process.",
),
)
.arg(
Arg::new("wait_for")
.long("wait-for")
.value_name("SECS")
.value_parser(clap::value_parser!(u64))
.conflicts_with("wait")
.help(
"Wait for the server to fully process uploaded files, \
but at most for the given number of seconds. Errors \
can only be displayed if --wait or --wait-for is specified, but this will \
significantly slow down the upload process.",
),
)
// Legacy flag that has no effect, left hidden for backward compatibility
.arg(
Arg::new("upload_symbol_maps")
.long("upload-symbol-maps")
.action(ArgAction::SetTrue)
.hide(true),
)
.arg(
Arg::new("il2cpp_mapping")
.long("il2cpp-mapping")
.action(ArgAction::SetTrue)
.help("Compute il2cpp line mappings and upload them along with sources."),
)
}
pub fn execute(matches: &ArgMatches) -> Result<()> {
if matches.get_one::<String>("info_plist").is_some() {
log::warn!(
"The --info-plist argument is deprecated. \
It does nothing and will be removed in a future release."
);
}
let config = Config::current();
let (org, project) = config.get_org_and_project(matches)?;
let ids = matches
.get_many::<DebugId>("ids")
.unwrap_or_default()
.copied();
let wait_for_secs = matches.get_one::<u64>("wait_for").copied();
let wait = matches.get_flag("wait") || wait_for_secs.is_some();
let max_wait = wait_for_secs.map_or(DEFAULT_MAX_WAIT, Duration::from_secs);
// Build generic upload parameters
let mut upload = DifUpload::new(&org, &project);
upload
.wait(wait)
.max_wait(max_wait)
.search_paths(matches.get_many::<String>("paths").unwrap_or_default())
.allow_zips(!matches.get_flag("no_zips"))
.filter_ids(ids);
// Restrict symbol types, if specified by the user
for ty in matches
.get_many::<String>("types")
.unwrap_or_default()
.map(String::as_str)
{
match ty {
"dsym" => upload.filter_format(DifFormat::Object(FileFormat::MachO)),
"elf" => upload.filter_format(DifFormat::Object(FileFormat::Elf)),
"breakpad" => upload.filter_format(DifFormat::Object(FileFormat::Breakpad)),
"pdb" => upload.filter_format(DifFormat::Object(FileFormat::Pdb)),
"pe" => upload.filter_format(DifFormat::Object(FileFormat::Pe)),
"sourcebundle" => upload.filter_format(DifFormat::Object(FileFormat::SourceBundle)),
"portablepdb" => upload.filter_format(DifFormat::Object(FileFormat::PortablePdb)),
"jvm" => upload.filter_format(DifFormat::Object(FileFormat::SourceBundle)),
"wasm" => upload.filter_format(DifFormat::Object(FileFormat::Wasm)),
"bcsymbolmap" => {
upload.filter_format(DifFormat::BcSymbolMap);
upload.filter_format(DifFormat::PList)
}
other => bail!("Unsupported type: {}", other),
};
}
upload.filter_features(ObjectDifFeatures {
// Allow stripped debug symbols. These are dSYMs, ELF binaries generated
// with `objcopy --only-keep-debug` or Breakpad symbols. As a fallback,
// we also upload all files with a public symbol table.
debug: !matches.get_flag("no_debug"),
symtab: !matches.get_flag("no_debug"),
// Allow executables and dynamic/shared libraries, but not object files.
// They are guaranteed to contain unwind info, for instance `eh_frame`,
// and may optionally contain debugging information such as DWARF.
unwind: !matches.get_flag("no_unwind"),
sources: !matches.get_flag("no_sources"),
});
upload.include_sources(matches.get_flag("include_sources"));
upload.il2cpp_mapping(matches.get_flag("il2cpp_mapping"));
// Configure BCSymbolMap resolution, if possible
if let Some(symbol_map) = matches.get_one::<String>("symbol_maps") {
upload
.symbol_map(symbol_map)
.map_err(|_| format_err!("--symbol-maps requires Apple dsymutil to be available."))?;
}
// Add a path to XCode's DerivedData, if configured
if matches.get_flag("derived_data") {
let derived_data = dirs::home_dir().map(|x| x.join(DERIVED_DATA_FOLDER));
if let Some(path) = derived_data {
if path.is_dir() {
upload.search_path(path);
}
}
}
if matches.get_flag("no_upload") {
println!("{} skipping upload.", style(">").dim());
return Ok(());
}
// Execute the upload
let (uploaded, has_processing_errors) = upload.upload()?;
// Did we miss explicitly requested symbols?
if matches.get_flag("require_all") {
let required_ids: BTreeSet<DebugId> = matches
.get_many::<DebugId>("ids")
.unwrap_or_default()
.cloned()
.collect();
let found_ids = uploaded.into_iter().map(|dif| dif.id()).collect();
let missing_ids: Vec<_> = required_ids.difference(&found_ids).collect();
if !missing_ids.is_empty() {
eprintln!();
eprintln!("{}", style("Error: Some symbols could not be found!").red());
eprintln!("The following symbols are still missing:");
for id in missing_ids {
println!(" {id}");
}
return Err(QuietExit(1).into());
}
}
// report a non 0 status code if the server encountered issues.
if has_processing_errors {
eprintln!();
eprintln!("{}", style("Error: some symbols did not process correctly"));
return Err(QuietExit(1).into());
}
Ok(())
}