Repository navigation
Expand file tree
/
Copy pathfetch-vcruntime.sh
More file actions
executable file
·111 lines (95 loc) · 2.78 KB
/
Copy pathfetch-vcruntime.sh
File metadata and controls
executable file
·111 lines (95 loc) · 2.78 KB
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
#!/usr/bin/env bash
set -euo pipefail
R="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DEST="$R/app/Madeira/x86_64-vcruntime"
URL="https://aka.ms/vs/17/release/vc_redist.x64.exe"
TMP="$(mktemp -d "${TMPDIR:-/tmp}/madeira-vcrt.XXXXXX" 2>/dev/null || mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
mkdir -p "$DEST"
mkdir -p "$TMP/cab_out" "$TMP/stage"
echo "fetching VC_redist.x64.exe..."
curl --proto '=https' --tlsv1.2 -fL --retry 3 -o "$TMP/VC_redist.x64.exe" "$URL"
if command -v shasum >/dev/null 2>&1; then
echo -n "downloaded sha256: "
shasum -a 256 "$TMP/VC_redist.x64.exe" | awk '{print $1}'
fi
SEVENZIP=""
if command -v 7zz >/dev/null 2>&1; then
SEVENZIP="7zz"
elif command -v 7z >/dev/null 2>&1; then
SEVENZIP="7z"
else
echo "error: 7zz or 7z not found (brew install sevenzip)" >&2
exit 1
fi
"$SEVENZIP" x "$TMP/VC_redist.x64.exe" -o"$TMP/ext" -y >/dev/null
i=0
while IFS= read -r -d '' cab; do
i=$((i + 1))
out="$TMP/cab_out/$i"
mkdir -p "$out"
if ! "$SEVENZIP" x "$cab" -o"$out" -y >"$TMP/7z-$i.log" 2>&1; then
echo "warn: could not extract $cab (log: $TMP/7z-$i.log)" >&2
fi
done < <(find "$TMP/ext" -type f -iname '*.cab' -print0)
if [ "$i" -eq 0 ]; then
echo "error: no cab files found in installer" >&2
exit 1
fi
WANTED=(
"concrt140.dll"
"msvcp140.dll"
"msvcp140_1.dll"
"msvcp140_2.dll"
"msvcp140_atomic_wait.dll"
"msvcp140_codecvt_ids.dll"
"vcamp140.dll"
"vccorlib140.dll"
"vcomp140.dll"
"vcruntime140.dll"
"vcruntime140_1.dll"
"vcruntime140_threads.dll"
"mfc140.dll"
"mfc140u.dll"
)
is_x64() {
python3 -c '
import struct, sys
try:
with open(sys.argv[1], "rb") as f:
d = f.read(1024)
if len(d) >= 0x40 and d[:2] == b"MZ":
pe = struct.unpack_from("<I", d, 0x3c)[0]
m = struct.unpack_from("<H", d, pe + 4)[0]
if m == 0x8664:
sys.exit(0)
except Exception:
pass
sys.exit(1)
' "$1" 2>/dev/null
}
missing=()
for name in "${WANTED[@]}"; do
base="${name%.dll}"
matches=()
while IFS= read -r -d '' match; do
if is_x64 "$match"; then
matches+=("$match")
fi
done < <(find "$TMP/cab_out" -type f \( -iname "$name" -o -iname "${name}_amd64" -o -iname "${name}*" -o -iname "F_CENTRAL_${base}_*" \) -print0)
if [ "${#matches[@]}" -eq 0 ]; then
missing+=("$name")
else
cp "${matches[0]}" "$TMP/stage/$name"
fi
done
if [ "${#missing[@]}" -ne 0 ]; then
echo "error: ${#missing[@]} of ${#WANTED[@]} files not found in installer:" >&2
for m in "${missing[@]}"; do
echo " - $m" >&2
done
exit 1
fi
cp "$TMP/stage/"*.dll "$DEST/"
echo "${#WANTED[@]}/${#WANTED[@]} runtime files copied to $DEST"
python3 "$R/tests/host/check-vcruntime.py" --strict