Skip to content

Commit

Permalink
Add new debug_prefix_map_pwd_is_dot CROSSTOOL feature
Browse files Browse the repository at this point in the history
This feature sets `-fdebug_prefix_map=$PWD=.` as an argument to Clang
in order to standardize the paths to debug symbols (by making them
relative to the exec root).

Note that this needs to be implemented inside wrapped_clang instead
of as an argument to the action itself for caching purposes, as PWD
can change based on the action's executor.

PiperOrigin-RevId: 206019016
  • Loading branch information
Googler authored and Copybara-Service committed Jul 25, 2018
1 parent 24d3a01 commit 3f46dd0
Show file tree
Hide file tree
Showing 2 changed files with 192 additions and 6 deletions.
180 changes: 180 additions & 0 deletions tools/osx/crosstool/CROSSTOOL.tpl
Expand Up @@ -200,6 +200,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."
}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down Expand Up @@ -1829,6 +1847,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."
}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down Expand Up @@ -3474,6 +3510,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."
}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down Expand Up @@ -5122,6 +5176,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."
}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down Expand Up @@ -6797,6 +6869,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."
}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down Expand Up @@ -8442,6 +8532,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."
}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down Expand Up @@ -10075,6 +10183,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."
}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down Expand Up @@ -11711,6 +11837,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."
}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down Expand Up @@ -13374,6 +13518,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."
}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down Expand Up @@ -15008,6 +15170,24 @@ toolchain {
expand_if_all_available: "legacy_compile_flags"
}
}
feature {
name: "debug_prefix_map_pwd_is_dot"
flag_set {
action: "assemble"
action: "preprocess-assemble"
action: "c-compile"
action: "c++-compile"
action: "c++-header-parsing"
action: "c++-module-compile"
action: "c++-module-codegen"
action: "linkstamp-compile"
action: "objc-compile"
action: "objc++-compile"
flag_group {
flag: "DEBUG_PREFIX_MAP_PWD=."

This comment has been minimized.

Copy link
@steeve

steeve Nov 29, 2018

Contributor

Why was thing done as a flag_group rather than env_group?
I'm asking because the same problem exists when using the Android NDK on macOS machines, and at the moment Bazel is directly invoking the compiler.
I feel that having an env variable would simplify using this method while avoiding possible breaks in the arguments.

}
}
}
feature {
name: "no_dsym_create_zip"
}
Expand Down
18 changes: 12 additions & 6 deletions tools/osx/crosstool/wrapped_clang.cc
Expand Up @@ -177,6 +177,15 @@ int main(int argc, char *argv[]) {
std::vector<std::string> processed_args = {"/usr/bin/xcrun", tool_name};

std::string linked_binary, dsym_path, dsym_bundle_zip, bitcode_symbol_map;
std::string dest_dir;

std::unique_ptr<char, decltype(std::free) *> cwd{getcwd(nullptr, 0),
std::free};
if (cwd == nullptr) {
std::cerr << "Error determining current working directory\n";
abort();
}

for (int i = 1; i < argc; i++) {
std::string arg(argv[i]);

Expand All @@ -196,6 +205,9 @@ int main(int argc, char *argv[]) {
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.get()) + "=" + dest_dir;
}
FindAndReplace("__BAZEL_XCODE_DEVELOPER_DIR__", developer_dir, &arg);
FindAndReplace("__BAZEL_XCODE_SDKROOT__", sdk_root, &arg);
processed_args.push_back(arg);
Expand Down Expand Up @@ -240,12 +252,6 @@ int main(int argc, char *argv[]) {
RunSubProcess(dsymutil_args);

if (dsyms_use_zip_file) {
std::unique_ptr<char, decltype(std::free) *> cwd{getcwd(nullptr, 0),
std::free};
if (cwd == nullptr) {
std::cerr << "Error determining current working directory\n";
abort();
}
std::vector<std::string> zip_args = {
"/usr/bin/zip", "-q", "-r",
std::string(cwd.get()) + "/" + dsym_bundle_zip, "."};
Expand Down

0 comments on commit 3f46dd0

Please sign in to comment.