Skip to content

Commit

Permalink
Fix dSYMs
Browse files Browse the repository at this point in the history
  • Loading branch information
keith committed Nov 4, 2020
1 parent 042aa81 commit a11812e
Showing 1 changed file with 35 additions and 26 deletions.
61 changes: 35 additions & 26 deletions tools/osx/crosstool/wrapped_clang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,23 @@ static std::unique_ptr<TempFile> 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<void(const std::string &)> 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<void(const std::string &)> consumer) {
auto path = arg.substr(1);
std::ifstream original_file(path);
Expand All @@ -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;
Expand All @@ -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<void(const std::string &)> 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);

Expand Down Expand Up @@ -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<std::string> invocation_args = {"/usr/bin/xcrun", tool_name};
Expand All @@ -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.
Expand Down

0 comments on commit a11812e

Please sign in to comment.