From ecab1c8680f2eece7ff5a46860c768c6738e3467 Mon Sep 17 00:00:00 2001 From: Googler Date: Tue, 10 Jul 2018 08:57:30 -0700 Subject: Prepare CROSSTOOL for dSYM simplification Currently dSYM information is propagated using a zip file emitted by the linking action which contains a dwarf file and plist. A second action then unzips said file, discards the plist and propagates the dwarf file. This CL is part of a change which makes the link action emit the dwarf file directly. This change adds logic to the CROSSTOOL and wrapped_clang to temporarily support both the old and new approaches using the presence of DSYM_HINT_DSYM_BUNDLE_ZIP as a signal as to which to use. After this change the new (and temporary) CROSSTOOL feature no_dsym_create_zip will allow suppressing DSYM_HINT_DSYM_BUNDLE_ZIP from being passed. Once the migration is complete we will remove both the signal variable and feature. PiperOrigin-RevId: 203954795 --- tools/osx/crosstool/CROSSTOOL.tpl | 120 +++++++++++++++++++++++++++++++++++ tools/osx/crosstool/wrapped_clang.cc | 50 ++++++++------- 2 files changed, 148 insertions(+), 22 deletions(-) (limited to 'tools') diff --git a/tools/osx/crosstool/CROSSTOOL.tpl b/tools/osx/crosstool/CROSSTOOL.tpl index e065efbff8..6686ce0e69 100644 --- a/tools/osx/crosstool/CROSSTOOL.tpl +++ b/tools/osx/crosstool/CROSSTOOL.tpl @@ -200,6 +200,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -219,8 +222,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { @@ -1817,6 +1829,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -1836,8 +1851,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { @@ -3450,6 +3474,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -3469,8 +3496,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { @@ -5086,6 +5122,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -5105,8 +5144,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { @@ -6749,6 +6797,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -6768,8 +6819,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { @@ -8382,6 +8442,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -8401,8 +8464,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { @@ -10003,6 +10075,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -10022,8 +10097,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { @@ -11627,6 +11711,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -11646,8 +11733,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { @@ -13278,6 +13374,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -13297,8 +13396,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { @@ -14900,6 +15008,9 @@ toolchain { expand_if_all_available: "legacy_compile_flags" } } + feature { + name: "no_dsym_create_zip" + } feature { name: "generate_dsym_file" flag_set { @@ -14919,8 +15030,17 @@ toolchain { flag_group { flag: "DSYM_HINT_LINKED_BINARY=%{linked_binary}" flag: "DSYM_HINT_DSYM_PATH=%{dsym_path}" + } + } + flag_set { + action: "objc-executable" + action: "objc++-executable" + flag_group { flag: "DSYM_HINT_DSYM_BUNDLE_ZIP=%{dsym_bundle_zip}" } + with_feature { + not_feature: "no_dsym_create_zip" + } } } feature { diff --git a/tools/osx/crosstool/wrapped_clang.cc b/tools/osx/crosstool/wrapped_clang.cc index 91f41d3ce1..232f082dc1 100644 --- a/tools/osx/crosstool/wrapped_clang.cc +++ b/tools/osx/crosstool/wrapped_clang.cc @@ -22,8 +22,10 @@ // are passed in, then they all must be passed in. // "DSYM_HINT_LINKED_BINARY": Workspace-relative path to binary output of the // link action generating the dsym file. -// "DSYM_HINT_DSYM_PATH": Workspace-relative path to dSYM directory. -// "DSYM_HINT_DSYM_BUNDLE_ZIP": Workspace-relative path to dSYM zip. +// "DSYM_HINT_DSYM_PATH": Workspace-relative path to dSYM dwarf file or bundle. +// "DSYM_HINT_DSYM_BUNDLE_ZIP": (optional) Workspace-relative path to dSYM zip. +// - If this is specified, a dSYM bundle is created, otherwise just a regular +// DWARF file is created. // // Likewise, this wrapper also contains a workaround for a bug in ld that causes // flaky builds when using Bitcode symbol maps. ld allows the @@ -199,17 +201,15 @@ int main(int argc, char *argv[]) { // Check to see if we should postprocess with dsymutil. bool postprocess = false; + bool dsyms_use_zip_file = false; if ((!linked_binary.empty()) || (!dsym_path.empty()) || (!dsym_bundle_zip.empty())) { - if ((linked_binary.empty()) || (dsym_path.empty()) || - (dsym_bundle_zip.empty())) { + if ((linked_binary.empty()) || (dsym_path.empty())) { const char *missing_dsym_flag; if (linked_binary.empty()) { missing_dsym_flag = "DSYM_HINT_LINKED_BINARY"; - } else if (dsym_path.empty()) { - missing_dsym_flag = "DSYM_HINT_DSYM_PATH"; } else { - missing_dsym_flag = "DSYM_HINT_DSYM_BUNDLE_ZIP"; + missing_dsym_flag = "DSYM_HINT_DSYM_PATH"; } std::cerr << "Error in clang wrapper: If any dsym " "hint is defined, then " @@ -217,6 +217,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } else { postprocess = true; + dsyms_use_zip_file = !(dsym_bundle_zip.empty()); } } @@ -227,27 +228,32 @@ int main(int argc, char *argv[]) { if (postprocess) { std::vector dsymutil_args = {"/usr/bin/xcrun", "dsymutil", linked_binary, "-o", dsym_path}; + if (!dsyms_use_zip_file) { + dsymutil_args.push_back("--flat"); + } if (RunSubProcess(dsymutil_args) != 0) { return EXIT_FAILURE; } - std::unique_ptr cwd{getcwd(nullptr, 0), - std::free}; - if (cwd == nullptr) { - std::cerr << "Error determining current working directory\n"; - return EXIT_FAILURE; - } - std::vector zip_args = { - "/usr/bin/zip", "-q", "-r", - std::string(cwd.get()) + "/" + dsym_bundle_zip, "."}; - if (chdir(dsym_path.c_str()) < 0) { - std::cerr << "Error changing directory to '" << dsym_path << "'\n"; - return EXIT_FAILURE; - } + if (dsyms_use_zip_file) { + std::unique_ptr cwd{getcwd(nullptr, 0), + std::free}; + if (cwd == nullptr) { + std::cerr << "Error determining current working directory\n"; + return EXIT_FAILURE; + } + std::vector zip_args = { + "/usr/bin/zip", "-q", "-r", + std::string(cwd.get()) + "/" + dsym_bundle_zip, "."}; + if (chdir(dsym_path.c_str()) < 0) { + std::cerr << "Error changing directory to '" << dsym_path << "'\n"; + return EXIT_FAILURE; + } - if (RunSubProcess(zip_args) != 0) { - return EXIT_FAILURE; + if (RunSubProcess(zip_args) != 0) { + return EXIT_FAILURE; + } } } -- cgit v1.2.3