1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414//
15- // wrapped_clang.cc: Pass args to 'xcrun clang' and zip dsym files.
15+ // wrapped_clang.cc: Pass args to 'xcrun clang' and optionally produce dSYM
16+ // files.
1617//
17- // wrapped_clang passes its args to clang, but also supports a separate set of
18- // invocations to generate dSYM files. If "DSYM_HINT" flags are passed in, they
19- // are used to construct that separate set of invocations (instead of being
20- // passed to clang).
21- // The following "DSYM_HINT" flags control dsym generation. If any one if these
22- // are passed in, then they all must be passed in.
23- // "DSYM_HINT_LINKED_BINARY": Workspace-relative path to binary output of the
24- // link action generating the dsym file.
25- // "DSYM_HINT_DSYM_PATH": Workspace-relative path to dSYM dwarf file.
2618
2719#include < libgen.h>
2820#include < spawn.h>
@@ -259,16 +251,12 @@ static std::unique_ptr<TempFile> WriteResponseFile(
259251
260252void ProcessArgument (const std::string arg, const std::string developer_dir,
261253 const std::string sdk_root, const std::string cwd,
262- bool relative_ast_path, std::string &linked_binary,
263- std::string &dsym_path, bool &strip_debug_symbols,
264- std::string toolchain_path,
254+ bool relative_ast_path, std::string toolchain_path,
265255 std::function<void (const std::string &)> consumer);
266256
267257bool ProcessResponseFile (const std::string arg, const std::string developer_dir,
268258 const std::string sdk_root, const std::string cwd,
269- bool relative_ast_path, std::string &linked_binary,
270- std::string &dsym_path, bool &strip_debug_symbols,
271- std::string toolchain_path,
259+ bool relative_ast_path, std::string toolchain_path,
272260 std::function<void (const std::string &)> consumer) {
273261 auto path = arg.substr (1 );
274262 std::ifstream original_file (path);
@@ -282,8 +270,7 @@ bool ProcessResponseFile(const std::string arg, const std::string developer_dir,
282270 // Arguments in response files might be quoted/escaped, so we need to
283271 // unescape them ourselves.
284272 ProcessArgument (Unescape (arg_from_file), developer_dir, sdk_root, cwd,
285- relative_ast_path, linked_binary, dsym_path,
286- strip_debug_symbols, toolchain_path, consumer);
273+ relative_ast_path, toolchain_path, consumer);
287274 }
288275
289276 return true ;
@@ -339,30 +326,16 @@ std::string GetToolchainPath(const std::string &toolchain_id) {
339326
340327void ProcessArgument (const std::string arg, const std::string developer_dir,
341328 const std::string sdk_root, const std::string cwd,
342- bool relative_ast_path, std::string &linked_binary,
343- std::string &dsym_path, bool &strip_debug_symbols,
344- std::string toolchain_path,
329+ bool relative_ast_path, std::string toolchain_path,
345330 std::function<void (const std::string &)> consumer) {
346331 auto new_arg = arg;
347332 if (arg[0 ] == ' @' ) {
348333 if (ProcessResponseFile (arg, developer_dir, sdk_root, cwd,
349- relative_ast_path, linked_binary, dsym_path,
350- strip_debug_symbols, toolchain_path, consumer)) {
334+ relative_ast_path, toolchain_path, consumer)) {
351335 return ;
352336 }
353337 }
354338
355- if (SetArgIfFlagPresent (arg, " DSYM_HINT_LINKED_BINARY" , &linked_binary)) {
356- return ;
357- }
358- if (SetArgIfFlagPresent (arg, " DSYM_HINT_DSYM_PATH" , &dsym_path)) {
359- return ;
360- }
361- if (arg == " STRIP_DEBUG_SYMBOLS" ) {
362- strip_debug_symbols = true ;
363- return ;
364- }
365-
366339 FindAndReplace (" __BAZEL_EXECUTION_ROOT__" , cwd, &new_arg);
367340 FindAndReplace (" __BAZEL_XCODE_DEVELOPER_DIR__" , developer_dir, &new_arg);
368341 FindAndReplace (" __BAZEL_XCODE_SDKROOT__" , sdk_root, &new_arg);
@@ -428,8 +401,6 @@ int main(int argc, char *argv[]) {
428401
429402 std::string developer_dir = GetMandatoryEnvVar (" DEVELOPER_DIR" );
430403 std::string sdk_root = GetMandatoryEnvVar (" SDKROOT" );
431- std::string linked_binary, dsym_path;
432- bool strip_debug_symbols = false ;
433404
434405 const std::string cwd = GetCurrentDirectory ();
435406 std::vector<std::string> invocation_args = {" /usr/bin/xcrun" , tool_name};
@@ -443,7 +414,6 @@ int main(int argc, char *argv[]) {
443414 std::string arg (argv[i]);
444415
445416 ProcessArgument (arg, developer_dir, sdk_root, cwd, relative_ast_path,
446- linked_binary, dsym_path, strip_debug_symbols,
447417 toolchain_path, consumer);
448418 }
449419
@@ -468,10 +438,12 @@ int main(int argc, char *argv[]) {
468438
469439 // Check to see if we should postprocess with dsymutil.
470440 bool postprocess = false ;
471- if ((!linked_binary.empty ()) || (!dsym_path.empty ())) {
472- if ((linked_binary.empty ()) || (dsym_path.empty ())) {
441+ const char *linked_binary = getenv (" DSYM_HINT_LINKED_BINARY" );
442+ const char *dsym_path_raw_value = getenv (" DSYM_HINT_DSYM_PATH" );
443+ if (linked_binary != nullptr || dsym_path_raw_value != nullptr ) {
444+ if (linked_binary == nullptr || dsym_path_raw_value == nullptr ) {
473445 const char *missing_dsym_flag;
474- if (linked_binary. empty () ) {
446+ if (linked_binary == nullptr ) {
475447 missing_dsym_flag = " DSYM_HINT_LINKED_BINARY" ;
476448 } else {
477449 missing_dsym_flag = " DSYM_HINT_DSYM_PATH" ;
@@ -499,6 +471,7 @@ int main(int argc, char *argv[]) {
499471 return 0 ;
500472 }
501473
474+ std::string dsym_path = dsym_path_raw_value;
502475 const std::string bundle_suffix = " .dSYM" ;
503476 bool is_bundle = dsym_path.rfind (bundle_suffix) ==
504477 dsym_path.length () - bundle_suffix.length ();
@@ -518,7 +491,8 @@ int main(int argc, char *argv[]) {
518491
519492 // When stripping is requested, we should still strip the binary
520493 // before returning
521- if (strip_debug_symbols) {
494+ const char *strip_debug_symbols = getenv (" STRIP_DEBUG_SYMBOLS" );
495+ if (strip_debug_symbols != nullptr ) {
522496 std::vector<std::string> strip_args = {" /usr/bin/xcrun" , " strip" , " -S" ,
523497 linked_binary};
524498 if (!RunSubProcess (strip_args)) {
0 commit comments