Home | History | Annotate | Download | only in mac
      1 #!/bin/bash
      2 
      3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
      4 # Use of this source code is governed by a BSD-style license that can be
      5 # found in the LICENSE file.
      6 
      7 # This script expects the following environment variables to be set.  Xcode
      8 # normally sets them:
      9 #
     10 # CONFIGURATION - Release or Debug; this script only operates when Release.
     11 # SRCROOT - /path/to/chrome/src/chrome
     12 # BUILT_PRODUTS_DIR - /path/to/chrome/src/xcodebuild/Release
     13 #
     14 # The script also takes a single argument defining the branding type.
     15 #
     16 # To test this script without running an entire build:
     17 #
     18 # cd /path/to/chrome/src/chrome
     19 # CONFIGURATION=Release \
     20 #     SRCROOT=$(pwd) \
     21 #     BUILT_PRODUCTS_DIR=$(pwd)/../xcodebuild/Release \
     22 #     tools/build/mac/dump_app_syms Chromium
     23 
     24 # Make sure we got the header to write into passed to us
     25 if [ $# -ne 1 ]; then
     26   echo "error: missing branding as an argument" >&2
     27   exit 1
     28 fi
     29 
     30 set -ex
     31 
     32 # Skip out if we're aren't in Release mode, no need for dump_syms on debug runs.
     33 if [ "${CONFIGURATION}" != "Release" ] ; then
     34   exit 0
     35 fi
     36 
     37 TOP="${SRCROOT}/.."
     38 BUILD_BRANDING=$1
     39 
     40 BRAND_SCRIPT="${TOP}/build/branding_value.sh"
     41 SRC_APP_NAME=$("${BRAND_SCRIPT}" "${BUILD_BRANDING}" PRODUCT_FULLNAME)
     42 . "${TOP}/chrome/VERSION"
     43 
     44 BREAKPAD_DUMP_SYMS="${BUILT_PRODUCTS_DIR}/dump_syms"
     45 FULL_VERSION="${MAJOR}.${MINOR}.${BUILD}.${PATCH}"
     46 
     47 DSYM_TAR_PATH="${BUILT_PRODUCTS_DIR}/${SRC_APP_NAME}.dSYM.tar.bz2"
     48 
     49 # Starting with an already-dumped symbol file at ${original_sym_path},
     50 # transforms the MODULE line (which must be the first line) from referring to
     51 # ${original_stem} to refer to ${variant_stem}. The transformed symbol file
     52 # is written to a symbol file at the same location that a symbol file would
     53 # be written to if ${variant_name} were in the SRC_NAMES array below.
     54 #
     55 # If the transformed symbol file already appears more recent than
     56 # ${original_sym_path}, it is left alone.
     57 redump_syms_variant() {
     58   local original_sym_path="${1}"
     59   local original_stem="${2}"
     60   local variant_stem="${3}"
     61   local variant_name="${4}"
     62   local arch="${5}"
     63 
     64   local variant_sym_name="${variant_name}-${FULL_VERSION}-${arch}.breakpad"
     65   local variant_sym_path="${BUILT_PRODUCTS_DIR}/${variant_sym_name}"
     66 
     67   if [[ "${original_sym_path}" -nt "${variant_sym_path}" ]]; then
     68     local pattern="\
     69 1s/^(MODULE [^ ]+ [^ ]+ [0-9a-fA-F]{33}) ${original_stem}\$/\1 ${variant_stem}/"
     70     sed -E -e "${pattern}" < "${original_sym_path}" > "${variant_sym_path}"
     71   fi
     72 }
     73 
     74 declare -a DSYMS
     75 
     76 # Everything in SRC_NAMES is required. It's an error for any of these files
     77 # to be missing.
     78 SRC_NAMES=(
     79     "${SRC_APP_NAME}.app"
     80     "${SRC_APP_NAME} Framework.framework"
     81     "${SRC_APP_NAME} Helper.app"
     82     "crash_inspector"
     83     "crash_report_sender.app"
     84     "exif.so"
     85     "ffmpegsumo.so"
     86 )
     87 
     88 # PDF.plugin is optional. Only include it if present.
     89 if [[ -e "${BUILT_PRODUCTS_DIR}/PDF.plugin" ]]; then
     90   SRC_NAMES[${#SRC_NAMES[@]}]="PDF.plugin"
     91 fi
     92 
     93 # libpeerconnection.so is optional. Only include it if present.
     94 if [[ -e "${BUILT_PRODUCTS_DIR}/libpeerconnection.so" ]]; then
     95   SRC_NAMES[${#SRC_NAMES[@]}]="libpeerconnection.so"
     96 fi
     97 
     98 for SRC_NAME in "${SRC_NAMES[@]}"; do
     99   # SRC_STEM is the name of the file within the DWARF directory of the .dSYM
    100   # bundle, which comes from the on-disk name of an executable or dylib within
    101   # its enclosing .app, .framework or .plugin bundle.  This is the bundle name
    102   # without .app, .framework or .plugin appended.  For non-bundled types, the
    103   # stem is just the name of the singular file on disk.
    104   SRC_STEM=$(echo "${SRC_NAME}" | sed -Ee 's/\.(app|framework|plugin)$//')
    105   DSYM_NAME="${SRC_NAME}.dSYM"
    106   DSYM_PATH="${BUILT_PRODUCTS_DIR}/${DSYM_NAME}"
    107   DWARF_PATH="${DSYM_PATH}/Contents/Resources/DWARF/${SRC_STEM}"
    108 
    109   # SRC_PATH is the path to the Mach-O file to which the DSYM_PATH corresponds.
    110   # If this is a directory, it is a bundle, and the path to the actual image
    111   # needs to be computed for dump_syms.
    112   SRC_PREFIX="${BUILT_PRODUCTS_DIR}/${SRC_NAME}"
    113   SRC_PATH=""
    114   if [[ -d "${SRC_PREFIX}" ]]; then
    115     BUNDLED_OPTIONS=(
    116         # Executables and plugins:
    117         "${SRC_PREFIX}/Contents/MacOS/${SRC_STEM}"
    118         # Frameworks:
    119         "${SRC_PREFIX}/Versions/Current/${SRC_STEM}"
    120     )
    121     for BUNDLED_OPTION in "${BUNDLED_OPTIONS[@]}"; do
    122       if [[ -fx "${BUNDLED_OPTION}" ]]; then
    123         SRC_PATH="${BUNDLED_OPTION}"
    124         break
    125       fi
    126     done
    127 
    128     if [[ -z "${SRC_PATH}" ]]; then
    129       echo "${0}: Could not find bundled Mach-O file for ${SRC_NAME}"
    130       exit 1
    131     fi
    132   else
    133     # The Mach-O file is not a bundle.
    134     SRC_PATH="${SRC_PREFIX}"
    135   fi
    136 
    137   ARCHS=$(file "${DWARF_PATH}" | sed -Ene 's/^.*(i386|x86_64)$/\1/p')
    138   if [[ -z "${ARCHS}" ]]; then
    139     echo "${0}: expected something dumpable in ${DWARF_PATH}" >& 2
    140     exit 1
    141   fi
    142 
    143   for ARCH in ${ARCHS}; do
    144     BPAD_SYM_NAME="${SRC_NAME}-${FULL_VERSION}-${ARCH}.breakpad"
    145     BPAD_SYM_PATH="${BUILT_PRODUCTS_DIR}/${BPAD_SYM_NAME}"
    146 
    147     # Only run dump_syms if the file has changed since the last dump. Use -g
    148     # to dump data from the dSYM and CFI data from the Mach-O library or
    149     # executable.
    150     if [ "${DWARF_PATH}" -nt "${BPAD_SYM_PATH}" -o \
    151          "${SRC_PATH}" -nt "${BPAD_SYM_PATH}" ] ; then
    152       "${BREAKPAD_DUMP_SYMS}" -a "${ARCH}" -g "${DWARF_PATH}" "${SRC_PATH}" > \
    153           "${BPAD_SYM_PATH}"
    154     fi
    155 
    156     # Some executables will show up with variant names. The Breakpad symbol
    157     # server looks up modules based on a combination of the module name and
    158     # identifier (UUID). Produce symbol files for these variant names so that
    159     # the Breakpad symbol server will have something to return for stacks that
    160     # travel through these modules.
    161     case "${SRC_NAME}" in
    162       "${SRC_APP_NAME}.app")
    163         # Google Chrome Canary is produced during packaging.
    164         redump_syms_variant "${BPAD_SYM_PATH}" "${SRC_STEM}" \
    165                             "${SRC_STEM} Canary" "${SRC_STEM} Canary.app" \
    166                             "${ARCH}"
    167         ;;
    168 
    169       "${SRC_APP_NAME} Helper.app")
    170         # Google Chrome Helper EH and Google Chrome Helper NP are produced by
    171         # build/mac/make_more_helpers.sh.
    172         redump_syms_variant "${BPAD_SYM_PATH}" "${SRC_STEM}" \
    173                             "${SRC_STEM} EH" "${SRC_STEM} EH.app" "${ARCH}"
    174         redump_syms_variant "${BPAD_SYM_PATH}" "${SRC_STEM}" \
    175                             "${SRC_STEM} NP" "${SRC_STEM} NP.app" "${ARCH}"
    176         ;;
    177     esac
    178   done
    179 
    180   # Remove the .dSYM archive if the file has changed since the archive was
    181   # last generated.  This will cause a new .dSYM archive to be created.
    182   if [ "${DWARF_PATH}" -nt "${DSYM_TAR_PATH}" ] ; then
    183     rm -f "${DSYM_TAR_PATH}"
    184   fi
    185 
    186   # Push the .dSYM bundle onto the DSYMS array so that it will be included in
    187   # the .dSYM archive if a new one is needed
    188   DSYMS[${#DSYMS[@]}]="${DSYM_NAME}"
    189 done
    190 
    191 # Create the archive of .dSYM bundles.
    192 if [ ! -e "${DSYM_TAR_PATH}" ] ; then
    193   # Change directory so that absolute paths aren't included in the archive.
    194   (cd "${BUILT_PRODUCTS_DIR}" &&
    195    tar -jcf "${DSYM_TAR_PATH}" "${DSYMS[@]}")
    196 fi
    197