diff --git a/tools/osx/crosstool/wrapped_clang.cc b/tools/osx/crosstool/wrapped_clang.cc index 6b632a95c33c06..9dec7b04668abd 100644 --- a/tools/osx/crosstool/wrapped_clang.cc +++ b/tools/osx/crosstool/wrapped_clang.cc @@ -272,19 +272,23 @@ static std::unique_ptr WriteResponseFile( } void ProcessArgument( - const std::string &arg, + const std::string arg, const std::string developer_dir, const std::string sdk_root, const std::string cwd, bool relative_ast_path, + std::string &linked_binary, + std::string &dsym_path, std::function consumer); bool ProcessResponseFile( - const std::string &arg, + const std::string arg, const std::string developer_dir, const std::string sdk_root, const std::string cwd, bool relative_ast_path, + std::string &linked_binary, + std::string &dsym_path, std::function consumer) { auto path = arg.substr(1); std::ifstream original_file(path); @@ -299,7 +303,7 @@ bool ProcessResponseFile( // unescape them ourselves. ProcessArgument( Unescape(arg_from_file), developer_dir, sdk_root, cwd, - relative_ast_path, consumer); + relative_ast_path, linked_binary, dsym_path, consumer); } return true; @@ -314,20 +318,43 @@ std::string GetCurrentDirectory() { } void ProcessArgument( - const std::string &arg, + const std::string arg, const std::string developer_dir, const std::string sdk_root, const std::string cwd, bool relative_ast_path, + std::string &linked_binary, + std::string &dsym_path, std::function consumer) { auto new_arg = arg; if (arg[0] == '@') { if (ProcessResponseFile(arg, developer_dir, sdk_root, cwd, - relative_ast_path, consumer)) { + relative_ast_path, linked_binary, dsym_path, consumer)) { return; } } + if (SetArgIfFlagPresent(arg, "DSYM_HINT_LINKED_BINARY", &linked_binary)) { + return; + } + if (SetArgIfFlagPresent(arg, "DSYM_HINT_DSYM_PATH", &dsym_path)) { + return; + } + + std::string dest_dir, bitcode_symbol_map; + if (SetArgIfFlagPresent(arg, "DEBUG_PREFIX_MAP_PWD", &dest_dir)) { + new_arg = "-fdebug-prefix-map=" + cwd + "=" + dest_dir; + } + if (arg.compare("OSO_PREFIX_MAP_PWD") == 0) { + new_arg = "-Wl,-oso_prefix," + cwd + "/"; + } + if (SetArgIfFlagPresent(arg, "BITCODE_TOUCH_SYMBOL_MAP", + &bitcode_symbol_map)) { + // Touch bitcode_symbol_map. + std::ofstream bitcode_symbol_map_file(bitcode_symbol_map); + new_arg = bitcode_symbol_map; + } + FindAndReplace("__BAZEL_XCODE_DEVELOPER_DIR__", developer_dir, &new_arg); FindAndReplace("__BAZEL_XCODE_SDKROOT__", sdk_root, &new_arg); @@ -366,9 +393,7 @@ int main(int argc, char *argv[]) { std::string developer_dir = GetMandatoryEnvVar("DEVELOPER_DIR"); std::string sdk_root = GetMandatoryEnvVar("SDKROOT"); - - std::string linked_binary, dsym_path, bitcode_symbol_map; - std::string dest_dir; + std::string linked_binary, dsym_path; const std::string cwd = GetCurrentDirectory(); std::vector invocation_args = {"/usr/bin/xcrun", tool_name}; @@ -379,25 +404,9 @@ int main(int argc, char *argv[]) { for (int i = 1; i < argc; i++) { std::string arg(argv[i]); - // These args are not read from response files to simplify assignment - if (SetArgIfFlagPresent(arg, "DSYM_HINT_LINKED_BINARY", &linked_binary)) { - continue; - } - if (SetArgIfFlagPresent(arg, "DSYM_HINT_DSYM_PATH", &dsym_path)) { - continue; - } - if (SetArgIfFlagPresent(arg, "BITCODE_TOUCH_SYMBOL_MAP", - &bitcode_symbol_map)) { - // Touch bitcode_symbol_map. - std::ofstream bitcode_symbol_map_file(bitcode_symbol_map); - arg = bitcode_symbol_map; - } - if (SetArgIfFlagPresent(arg, "DEBUG_PREFIX_MAP_PWD", &dest_dir)) { - arg = "-fdebug-prefix-map=" + std::string(cwd) + "=" + dest_dir; - } - ProcessArgument( - arg, developer_dir, sdk_root, cwd, relative_ast_path, consumer); + arg, developer_dir, sdk_root, cwd, relative_ast_path, linked_binary, + dsym_path, consumer); } // Special mode that only prints the command. Used for testing.