media/webrtc/trunk/build/mac/make_more_helpers.sh

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/trunk/build/mac/make_more_helpers.sh	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +#!/bin/bash
     1.5 +
     1.6 +# Copyright (c) 2012 The Chromium Authors. All rights reserved.
     1.7 +# Use of this source code is governed by a BSD-style license that can be
     1.8 +# found in the LICENSE file.
     1.9 +
    1.10 +# Usage: make_more_helpers.sh <directory_within_contents> <app_name>
    1.11 +#
    1.12 +# This script creates additional helper .app bundles for Chromium, based on
    1.13 +# the existing helper .app bundle, changing their Mach-O header's flags to
    1.14 +# enable and disable various features. Based on Chromium Helper.app, it will
    1.15 +# create Chromium Helper EH.app, which has the MH_NO_HEAP_EXECUTION bit
    1.16 +# cleared to support Chromium child processes that require an executable heap,
    1.17 +# and Chromium Helper NP.app, which has the MH_PIE bit cleared to support
    1.18 +# Chromium child processes that cannot tolerate ASLR.
    1.19 +#
    1.20 +# This script expects to be called from the chrome_exe target as a postbuild,
    1.21 +# and operates directly within the built-up browser app's versioned directory.
    1.22 +#
    1.23 +# Each helper is adjusted by giving it the proper bundle name, renaming the
    1.24 +# executable, adjusting several Info.plist keys, and changing the executable's
    1.25 +# Mach-O flags.
    1.26 +
    1.27 +set -eu
    1.28 +
    1.29 +make_helper() {
    1.30 +  local containing_dir="${1}"
    1.31 +  local app_name="${2}"
    1.32 +  local feature="${3}"
    1.33 +  local flags="${4}"
    1.34 +
    1.35 +  local helper_name="${app_name} Helper"
    1.36 +  local helper_stem="${containing_dir}/${helper_name}"
    1.37 +  local original_helper="${helper_stem}.app"
    1.38 +  if [[ ! -d "${original_helper}" ]]; then
    1.39 +    echo "${0}: error: ${original_helper} is a required directory" >& 2
    1.40 +    exit 1
    1.41 +  fi
    1.42 +  local original_helper_exe="${original_helper}/Contents/MacOS/${helper_name}"
    1.43 +  if [[ ! -f "${original_helper_exe}" ]]; then
    1.44 +    echo "${0}: error: ${original_helper_exe} is a required file" >& 2
    1.45 +    exit 1
    1.46 +  fi
    1.47 +
    1.48 +  local feature_helper="${helper_stem} ${feature}.app"
    1.49 +
    1.50 +  rsync -acC --delete --include '*.so' "${original_helper}/" "${feature_helper}"
    1.51 +
    1.52 +  local helper_feature="${helper_name} ${feature}"
    1.53 +  local helper_feature_exe="${feature_helper}/Contents/MacOS/${helper_feature}"
    1.54 +  mv "${feature_helper}/Contents/MacOS/${helper_name}" "${helper_feature_exe}"
    1.55 +
    1.56 +  local change_flags="$(dirname "${0}")/change_mach_o_flags.py"
    1.57 +  "${change_flags}" ${flags} "${helper_feature_exe}"
    1.58 +
    1.59 +  local feature_info="${feature_helper}/Contents/Info"
    1.60 +  local feature_info_plist="${feature_info}.plist"
    1.61 +
    1.62 +  defaults write "${feature_info}" "CFBundleDisplayName" "${helper_feature}"
    1.63 +  defaults write "${feature_info}" "CFBundleExecutable" "${helper_feature}"
    1.64 +
    1.65 +  cfbundleid="$(defaults read "${feature_info}" "CFBundleIdentifier")"
    1.66 +  feature_cfbundleid="${cfbundleid}.${feature}"
    1.67 +  defaults write "${feature_info}" "CFBundleIdentifier" "${feature_cfbundleid}"
    1.68 +
    1.69 +  cfbundlename="$(defaults read "${feature_info}" "CFBundleName")"
    1.70 +  feature_cfbundlename="${cfbundlename} ${feature}"
    1.71 +  defaults write "${feature_info}" "CFBundleName" "${feature_cfbundlename}"
    1.72 +
    1.73 +  # As usual, defaults might have put the plist into whatever format excites
    1.74 +  # it, but Info.plists get converted back to the expected XML format.
    1.75 +  plutil -convert xml1 "${feature_info_plist}"
    1.76 +
    1.77 +  # `defaults` also changes the file permissions, so make the file
    1.78 +  # world-readable again.
    1.79 +  chmod a+r "${feature_info_plist}"
    1.80 +}
    1.81 +
    1.82 +if [[ ${#} -ne 2 ]]; then
    1.83 +  echo "usage: ${0} <directory_within_contents> <app_name>" >& 2
    1.84 +  exit 1
    1.85 +fi
    1.86 +
    1.87 +DIRECTORY_WITHIN_CONTENTS="${1}"
    1.88 +APP_NAME="${2}"
    1.89 +
    1.90 +CONTENTS_DIR="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}"
    1.91 +CONTAINING_DIR="${CONTENTS_DIR}/${DIRECTORY_WITHIN_CONTENTS}"
    1.92 +
    1.93 +make_helper "${CONTAINING_DIR}" "${APP_NAME}" "EH" "--executable-heap"
    1.94 +make_helper "${CONTAINING_DIR}" "${APP_NAME}" "NP" "--no-pie"

mercurial