@@ -261,14 +261,15 @@ void ProcessArgument(const std::string arg, const std::string developer_dir,
261
261
const std::string sdk_root, const std::string cwd,
262
262
const std::string nosandbox_root, bool relative_ast_path,
263
263
std::string &linked_binary, std::string &dsym_path,
264
- std::string toolchain_path,
264
+ bool &strip_debug_symbols, std::string toolchain_path,
265
265
std::function<void (const std::string &)> consumer);
266
266
267
267
bool ProcessResponseFile (const std::string arg, const std::string developer_dir,
268
268
const std::string sdk_root, const std::string cwd,
269
269
const std::string nosandbox_root,
270
270
bool relative_ast_path, std::string &linked_binary,
271
- std::string &dsym_path, std::string toolchain_path,
271
+ std::string &dsym_path, bool &strip_debug_symbols,
272
+ std::string toolchain_path,
272
273
std::function<void (const std::string &)> consumer) {
273
274
auto path = arg.substr (1 );
274
275
std::ifstream original_file (path);
@@ -283,7 +284,7 @@ bool ProcessResponseFile(const std::string arg, const std::string developer_dir,
283
284
// unescape them ourselves.
284
285
ProcessArgument (Unescape (arg_from_file), developer_dir, sdk_root, cwd,
285
286
nosandbox_root, relative_ast_path, linked_binary, dsym_path,
286
- toolchain_path, consumer);
287
+ strip_debug_symbols, toolchain_path, consumer);
287
288
}
288
289
289
290
return true ;
@@ -341,13 +342,13 @@ void ProcessArgument(const std::string arg, const std::string developer_dir,
341
342
const std::string sdk_root, const std::string cwd,
342
343
const std::string nosandbox_root, bool relative_ast_path,
343
344
std::string &linked_binary, std::string &dsym_path,
344
- std::string toolchain_path,
345
+ bool &strip_debug_symbols, std::string toolchain_path,
345
346
std::function<void (const std::string &)> consumer) {
346
347
auto new_arg = arg;
347
348
if (arg[0 ] == ' @' ) {
348
349
if (ProcessResponseFile (arg, developer_dir, sdk_root, cwd, nosandbox_root,
349
350
relative_ast_path, linked_binary, dsym_path,
350
- toolchain_path, consumer)) {
351
+ strip_debug_symbols, toolchain_path, consumer)) {
351
352
return ;
352
353
}
353
354
}
@@ -358,6 +359,10 @@ void ProcessArgument(const std::string arg, const std::string developer_dir,
358
359
if (SetArgIfFlagPresent (arg, " DSYM_HINT_DSYM_PATH" , &dsym_path)) {
359
360
return ;
360
361
}
362
+ if (arg == " STRIP_DEBUG_SYMBOLS" ) {
363
+ strip_debug_symbols = true ;
364
+ return ;
365
+ }
361
366
362
367
FindAndReplace (" __BAZEL_EXECUTION_ROOT__" , cwd, &new_arg);
363
368
FindAndReplace (" __BAZEL_EXECUTION_ROOT_NO_SANDBOX__" , nosandbox_root,
@@ -427,6 +432,7 @@ int main(int argc, char *argv[]) {
427
432
std::string developer_dir = GetMandatoryEnvVar (" DEVELOPER_DIR" );
428
433
std::string sdk_root = GetMandatoryEnvVar (" SDKROOT" );
429
434
std::string linked_binary, dsym_path;
435
+ bool strip_debug_symbols = false ;
430
436
431
437
const std::string cwd = GetCurrentDirectory ();
432
438
std::vector<std::string> invocation_args = {" /usr/bin/xcrun" , tool_name};
@@ -453,8 +459,8 @@ int main(int argc, char *argv[]) {
453
459
std::string arg (argv[i]);
454
460
455
461
ProcessArgument (arg, developer_dir, sdk_root, cwd, nosandbox_root,
456
- relative_ast_path, linked_binary, dsym_path, toolchain_path,
457
- consumer);
462
+ relative_ast_path, linked_binary, dsym_path,
463
+ strip_debug_symbols, toolchain_path, consumer);
458
464
}
459
465
460
466
char *modulemap = getenv (" APPLE_SUPPORT_MODULEMAP" );
@@ -509,16 +515,32 @@ int main(int argc, char *argv[]) {
509
515
return 0 ;
510
516
}
511
517
512
- std::vector<std::string> dsymutil_args = {" /usr/bin/xcrun" ,
513
- " dsymutil" ,
514
- linked_binary,
515
- " -o" ,
516
- dsym_path,
517
- " --flat" ,
518
- " --no-swiftmodule-timestamp" };
518
+ const std::string bundle_suffix = " .dSYM" ;
519
+ bool is_bundle = dsym_path.rfind (bundle_suffix) ==
520
+ dsym_path.length () - bundle_suffix.length ();
521
+
522
+ std::vector<std::string> dsymutil_args = {
523
+ " /usr/bin/xcrun" , " dsymutil" ,
524
+ linked_binary, " -o" ,
525
+ dsym_path, " --no-swiftmodule-timestamp" };
526
+ if (!is_bundle) {
527
+ // We should generate a .dSYM bundle only when a path is passed to a .dSYM
528
+ // directory for backwards compatibility
529
+ dsymutil_args.push_back (" --flat" );
530
+ }
519
531
if (!RunSubProcess (dsymutil_args)) {
520
532
return 1 ;
521
533
}
522
534
535
+ // When stripping is requested, we should still strip the binary
536
+ // before returning
537
+ if (strip_debug_symbols) {
538
+ std::vector<std::string> strip_args = {" /usr/bin/xcrun" , " strip" , " -S" ,
539
+ linked_binary};
540
+ if (!RunSubProcess (strip_args)) {
541
+ return 2 ;
542
+ }
543
+ }
544
+
523
545
return 0 ;
524
546
}
0 commit comments