| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | usagescip-shell shell shell-project 0.0.0 usage().() { |
| 4 | >&2 printfscip-shell system . . printf. "%s FILENAME [DEFAULT_ARCH]\n" "$0" |
| 5 | } |
| 6 | |
| 7 | fname="$1" |
| 8 | default="$2" |
| 9 | if [scip-shell system . . `[`. -z "$fname" ] || [scip-shell system . . `[`. "$fname" = "-h" ] || [scip-shell system . . `[`. "$fname" = "--help" ]; then |
| 10 | usagescip-shell shell shell-project 0.0.0 usage(). |
| 11 | fi |
| 12 | if [scip-shell system . . `[`. -z "$fname" ]; then |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | if [scip-shell system . . `[`. ! -z "${SHELL}" ]; then |
| 17 | runscip-shell shell shell-project 0.0.0 run().() { |
| 18 | "${SHELL}" -c "$*" || truescip-shell system . . true. |
| 19 | } |
| 20 | else |
| 21 | runscip-shell shell shell-project 0.0.0 run().() { |
| 22 | /bin/shscip-shell filesystem . . `/bin/sh`. -c "$*" || truescip-shell system . . true. |
| 23 | } |
| 24 | fi |
| 25 | |
| 26 | if [scip-shell system . . `[`. ! -z "$CI" ]; then |
| 27 | groupscip-shell shell shell-project 0.0.0 group().() { |
| 28 | echoscip-shell system . . echo. "::group::$*" |
| 29 | runscip-shell shell shell-project 0.0.0 run(). "$@" |
| 30 | echoscip-shell system . . echo. "::endgroup::" |
| 31 | } |
| 32 | else |
| 33 | groupscip-shell shell shell-project 0.0.0 group().() { runscip-shell shell shell-project 0.0.0 run(). "$@"; } |
| 34 | fi |
| 35 | |
| 36 | default_archscip-shell shell shell-project 0.0.0 default_arch().() { |
| 37 | if [scip-shell system . . `[`. -z "$default" ]; then |
| 38 | printfscip-shell system . . printf. "%s\n" "$1" | awkscip-shell system . . awk. '{print $NF}' |
| 39 | else |
| 40 | printfscip-shell system . . printf. "%s\n" "$default" |
| 41 | fi |
| 42 | >&2 echoscip-shell system . . echo. "::warning::Unknown architecture ${file_info} (using ${arch})" |
| 43 | } |
| 44 | |
| 45 | |
| 46 | >&2 groupscip-shell shell shell-project 0.0.0 group(). file "$fname" |
| 47 | >&2 groupscip-shell shell shell-project 0.0.0 group(). otool -L "$fname" || truescip-shell system . . true. |
| 48 | >&2 groupscip-shell shell shell-project 0.0.0 group(). lipo -info "$fname" || truescip-shell system . . true. |
| 49 | file_info="$(filescip-shell system . . file. "$fname" 2>&1)" |
| 50 | |
| 51 | case "${file_info}" in |
| 52 | *"Mach-O universal"*) |
| 53 | arches=($(printfscip-shell system . . printf. '%s' "${file_info}" | grepscip-shell system . . grep. -o 'Mach-O universal.*' | grepscip-shell system . . grep. -o '\[[^]:]*' | sedscip-shell system . . sed. 's/^\[//g')) |
| 54 | if [scip-shell system . . `[`. "${#arches[@]}" -eq 1 ]; then |
| 55 | arch="${arches[0]}" |
| 56 | elif [scip-shell system . . `[`. "${#arches[@]}" -gt 1 ]; then |
| 57 | arch="universal" |
| 58 | if [[ " ${arches[*]} " =~ " arm64 " ]] && [[ " ${arches[*]} " =~ " x86_64 " ]]; then |
| 59 | : |
| 60 | else |
| 61 | for cur_arch in "${arches[@]}"; do |
| 62 | arch="${arch}_${cur_arch}" |
| 63 | done |
| 64 | fi |
| 65 | else |
| 66 | arch="$(default_archscip-shell shell shell-project 0.0.0 default_arch(). "${file_info}")" |
| 67 | fi |
| 68 | ;; |
| 69 | *x86_64*|*x86-64*) |
| 70 | arch=x86_64 |
| 71 | ;; |
| 72 | *arm64*) |
| 73 | arch=arm64 |
| 74 | ;; |
| 75 | *) |
| 76 | arch="$(default_archscip-shell shell shell-project 0.0.0 default_arch(). "${file_info}")" |
| 77 | ;; |
| 78 | esac |
| 79 | |
| 80 | printfscip-shell system . . printf. "%s\n" "$arch" |