| OLD | NEW |
| (Empty) |
| 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 # Usage: make_more_helpers.sh <directory_within_contents> <app_name> | |
| 8 # | |
| 9 # This script creates additional helper .app bundles for Chromium, based on | |
| 10 # the existing helper .app bundle, changing their Mach-O header's flags to | |
| 11 # enable and disable various features. | |
| 12 # | |
| 13 # This script expects to be called from the chrome_exe target as a postbuild, | |
| 14 # and operates directly within the built-up browser app's versioned directory. | |
| 15 # | |
| 16 # Each helper is adjusted by giving it the proper bundle name, renaming the | |
| 17 # executable, adjusting several Info.plist keys, and changing the executable's | |
| 18 # Mach-O flags. | |
| 19 | |
| 20 set -eu | |
| 21 | |
| 22 make_helper() { | |
| 23 local containing_dir="${1}" | |
| 24 local app_name="${2}" | |
| 25 local feature="${3}" | |
| 26 local flags="${4}" | |
| 27 | |
| 28 local helper_name="${app_name} Helper" | |
| 29 local helper_stem="${containing_dir}/${helper_name}" | |
| 30 local original_helper="${helper_stem}.app" | |
| 31 if [[ ! -d "${original_helper}" ]]; then | |
| 32 echo "${0}: error: ${original_helper} is a required directory" >& 2 | |
| 33 exit 1 | |
| 34 fi | |
| 35 local original_helper_exe="${original_helper}/Contents/MacOS/${helper_name}" | |
| 36 if [[ ! -f "${original_helper_exe}" ]]; then | |
| 37 echo "${0}: error: ${original_helper_exe} is a required file" >& 2 | |
| 38 exit 1 | |
| 39 fi | |
| 40 | |
| 41 local feature_helper="${helper_stem} ${feature}.app" | |
| 42 | |
| 43 rsync -acC --delete --include '*.so' "${original_helper}/" "${feature_helper}" | |
| 44 | |
| 45 local helper_feature="${helper_name} ${feature}" | |
| 46 local helper_feature_exe="${feature_helper}/Contents/MacOS/${helper_feature}" | |
| 47 mv "${feature_helper}/Contents/MacOS/${helper_name}" "${helper_feature_exe}" | |
| 48 | |
| 49 local change_flags="$(dirname "${0}")/change_mach_o_flags.py" | |
| 50 "${change_flags}" ${flags} "${helper_feature_exe}" | |
| 51 | |
| 52 local feature_info="${feature_helper}/Contents/Info" | |
| 53 local feature_info_plist="${feature_info}.plist" | |
| 54 | |
| 55 defaults write "${feature_info}" "CFBundleDisplayName" "${helper_feature}" | |
| 56 defaults write "${feature_info}" "CFBundleExecutable" "${helper_feature}" | |
| 57 | |
| 58 cfbundleid="$(defaults read "${feature_info}" "CFBundleIdentifier")" | |
| 59 feature_cfbundleid="${cfbundleid}.${feature}" | |
| 60 defaults write "${feature_info}" "CFBundleIdentifier" "${feature_cfbundleid}" | |
| 61 | |
| 62 cfbundlename="$(defaults read "${feature_info}" "CFBundleName")" | |
| 63 feature_cfbundlename="${cfbundlename} ${feature}" | |
| 64 defaults write "${feature_info}" "CFBundleName" "${feature_cfbundlename}" | |
| 65 | |
| 66 # As usual, defaults might have put the plist into whatever format excites | |
| 67 # it, but Info.plists get converted back to the expected XML format. | |
| 68 plutil -convert xml1 "${feature_info_plist}" | |
| 69 | |
| 70 # `defaults` also changes the file permissions, so make the file | |
| 71 # world-readable again. | |
| 72 chmod a+r "${feature_info_plist}" | |
| 73 } | |
| 74 | |
| 75 if [[ ${#} -ne 2 ]]; then | |
| 76 echo "usage: ${0} <directory_within_contents> <app_name>" >& 2 | |
| 77 exit 1 | |
| 78 fi | |
| 79 | |
| 80 DIRECTORY_WITHIN_CONTENTS="${1}" | |
| 81 APP_NAME="${2}" | |
| 82 | |
| 83 CONTENTS_DIR="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}" | |
| 84 CONTAINING_DIR="${CONTENTS_DIR}/${DIRECTORY_WITHIN_CONTENTS}" | |
| OLD | NEW |