-
Notifications
You must be signed in to change notification settings - Fork 0
/
base-runner.sh
142 lines (131 loc) · 2.86 KB
/
base-runner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env bash
host_architecture() {
# there's numerous compatibility modes, so we want
# to ensure that these are valid. we also want to
# use dpkg if it's available since it gives hard-float
# information on compatible architectures
local host
local arch
if dpkg >/dev/null 2>&1; then
host=$(dpkg --print-architecture)
arch="${host}"
else
host=$(uname -m)
arch="${host}"
case "${arch}" in
aarch64|armv8b|armv8l)
arch=arm64
;;
aarch64_be)
arch=arm64be
;;
arm*)
arch=unknown
;;
ppc)
arch=powerpc
;;
ppc64le)
arch=ppc64el
;;
s390)
arch=s390x
;;
i?86)
arch=i386
;;
x64|x86_64)
arch=amd64
;;
*)
;;
esac
fi
echo "${arch}"
}
normalize_arch() {
local arch="${1}"
local debian
debian="${arch}"
case "${arch}" in
aarch64)
debian=arm64
;;
x86_64)
debian=amd64
;;
arm)
debian=armel
;;
armv7)
debian=arm
;;
armv7hf)
debian=armhf
;;
i?86)
debian=i386
;;
powerpc64)
debian=ppc64
;;
powerpc64le)
debian=ppc64el
;;
riscv64*)
debian=riscv64
;;
*)
;;
esac
echo "${debian}"
}
is_native_binary() {
# determines if the binary can run natively on the host
local arch="${1}"
local host
local target
host=$(host_architecture)
target=$(normalize_arch "${arch}")
# FIXME: this is not comprehensive. add more compatible architectures.
case "${host}" in
amd64)
if [[ "${target}" == i386 ]] || [[ "${target}" == amd64 ]]; then
return 0
fi
;;
*)
if [[ "${host}" == "${target}" ]]; then
return 0
fi
;;
esac
return 1
}
qemu_arch() {
# select qemu arch
local arch="${1}"
local qarch="${arch}"
case "${arch}" in
arm|armhf|armv7|armv7hf)
qarch="arm"
;;
i?86)
qarch="i386"
;;
powerpc)
qarch="ppc"
;;
powerpc64)
qarch="ppc64"
;;
powerpc64le)
if [ "${CROSS_RUNNER}" = "qemu-user" ]; then
qarch="ppc64le"
else
qarch="ppc64"
fi
;;
esac
echo "${qarch}"
}