浏览文件
toolexec-for-codesign.sh
57 行 · 1.7 KB历史下载| 1 | |
| 2 | |
| 3 | # SPDX-FileCopyrightText: Copyright The Lima Authors |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | |
| 6 | # This script is used to wrap the compiler and linker commands in the build |
| 7 | # process. It captures the output of the command and logs it to a file. |
| 8 | # The script's primary purpose is codesigning the output of the linker command |
| 9 | # with the entitlements file if it exists. |
| 10 | # If the OS is macOS, the result of the command is 0, the entitlements file |
| 11 | # exists, and codesign is available, sign the output of the linker command with |
| 12 | # the entitlements file. |
| 13 | # |
| 14 | # Usage: |
| 15 | # go build -toolexec hack/toolexec-to-codesign.sh |
| 16 | |
| 17 | repository_root="$(dirname "$(dirname "$0")")" |
| 18 | logfile="${repository_root}/.toolexec-to-codesign.log" |
| 19 | |
| 20 | echo $$: cmd: "$@" >>"${logfile}" |
| 21 | |
| 22 | output="$("$@")" |
| 23 | result=$? |
| 24 | |
| 25 | echo $$: output: "${output}" >>"${logfile}" |
| 26 | |
| 27 | entitlements="${repository_root}/vz.entitlements" |
| 28 | |
| 29 | # If the OS is macOS, the result of the command is 0, the entitlements file |
| 30 | # exists, and codesign is available, sign the output of the linker command. |
| 31 | if OS=$(uname -s) && [ "${OS}" = "Darwin" ] && [ "${result}" -eq 0 ] && [ -f "${entitlements}" ] && command -v codesign >/dev/null 2>&1; then |
| 32 | # Check if the command is a linker command. |
| 33 | case "$1" in |
| 34 | *link) |
| 35 | shift |
| 36 | # Find a parameter that is a output file. |
| 37 | while [ $# -gt 1 ]; do |
| 38 | case "$1" in |
| 39 | -o) |
| 40 | # If the output file is a executable, sign it with the entitlements file. |
| 41 | if [ -x "$2" ]; then |
| 42 | codesign_output="$(codesign -v --entitlements "${entitlements}" -s - "$2" 2>&1)" |
| 43 | echo "$$: ${codesign_output}" >>"${logfile}" |
| 44 | fi |
| 45 | break |
| 46 | ;; |
| 47 | *) shift ;; |
| 48 | esac |
| 49 | done |
| 50 | ;; |
| 51 | *) ;; |
| 52 | esac |
| 53 | fi |
| 54 | |
| 55 | # Print the output of the command and exit with the result of the command. |
| 56 | echo "${output}" |
| 57 | exit "${result}" |

