-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathbuild-release.sh
executable file
·147 lines (117 loc) · 4.24 KB
/
build-release.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
143
144
145
146
147
#!/usr/bin/env bash
set -e
# This script takes a target platform as an argument, and then
# builds the server for that platform - installing the correct
# native-built modules for the platform as appropriate.
# ------------------------------------------------------------------------
# Configure everything for the target platform
# ------------------------------------------------------------------------
TARGET_PLATFORM=$1
TARGET_ARCH=$2
echo "CONFIGURING FOR $TARGET_PLATFORM $TARGET_ARCH"
if [ -z "$TARGET_PLATFORM" ]; then
echo 'A target platform (linux/win32/darwin) is required'
exit 1
fi
if [ -z "$TARGET_ARCH" ]; then
echo 'A target platform (x64/arm/arm64) is required'
exit 1
fi
export PATH=./node_modules/.bin:$PATH
# Pick the target platform for prebuild-install:
export npm_config_platform=$TARGET_PLATFORM
# Pick the target platform for node-pre-gyp:
export npm_config_target_platform=$TARGET_PLATFORM
# Same for architecture:
export npm_config_arch=$TARGET_ARCH
export npm_config_target_arch=$TARGET_ARCH
# Disable node-gyp-build for win-version-info only. Without this, it's
# rebuilt for Linux, even given $TARGET_PLATFORM=win32, and then breaks
# at runtime even though there are valid win32 prebuilds available.
export WIN_VERSION_INFO=disable-prebuild
TARGET=$TARGET_PLATFORM-$TARGET_ARCH
# ------------------------------------------------------------------------
# Clean the existing build workspace, to keep targets 100% independent
# ------------------------------------------------------------------------
rm -rf ./tmp || true
# ------------------------------------------------------------------------
# Build the package for this platform
# ------------------------------------------------------------------------
echo
echo "BUILDING FOR $TARGET_PLATFORM $TARGET_ARCH"
echo
oclif-dev pack --targets=$TARGET
echo
echo "BUILT"
echo
# ------------------------------------------------------------------------
# Confirm that the installed binaries all support the target platform.
# This is not 100% by any means, but catches obvious mistakes.
# ------------------------------------------------------------------------
# Whitelist (as a regex) for packages that may include binaries for other platforms
PACKAGE_WHITELIST=''
case "$TARGET_ARCH" in
x64)
EXPECTED_ARCH_STRING='x86[_-]64|80386'
;;
arm64)
EXPECTED_ARCH_STRING='arm64|aarch64'
;;
*)
echo "Unknown arch $TARGET_ARCH"
exit 1
;;
esac
case "$TARGET_PLATFORM" in
linux)
EXPECTED_PLATFORM_STRING='ELF'
# Registry-js builds raw on non-Windows, but never used
# Win-version info includes prebuilds for Windows on all platforms
PACKAGE_WHITELIST='registry-js|win-version-info/prebuilds'
;;
win32)
EXPECTED_PLATFORM_STRING='MS Windows'
PACKAGE_WHITELIST=''
;;
darwin)
EXPECTED_PLATFORM_STRING='Mach-O'
# Registry-js builds raw on non-Windows, but never used
# Win-version info includes prebuilds for Windows on all platforms
PACKAGE_WHITELIST='registry-js|win-version-info/prebuilds'
;;
*)
echo "Unknown platform $TARGET_PLATFORM"
exit 1
;;
esac
echo "CHECKING FOR BAD CONFIG"
echo "EXPECTING: $EXPECTED_PLATFORM_STRING and $EXPECTED_ARCH_STRING"
echo "WHITELIST: $PACKAGE_WHITELIST"
# Find all *.node files in the build that `file` doesn't describe with the above
NATIVE_BINARIES=$(
find ./tmp/$TARGET/ \
-name '*.node' \
-type f \
-exec file {} \; \
| sed "s#^./tmp/$TARGET/##" # Don't match the build targets's own path name!
)
echo "NATIVE BINS: $NATIVE_BINARIES"
BAD_PLATFORM_BINS=$(echo "$NATIVE_BINARIES" | grep -v "$EXPECTED_PLATFORM_STRING" || true)
BAD_ARCH_BINS=$(echo "$NATIVE_BINARIES" | grep -vE "$EXPECTED_ARCH_STRING" || true)
BAD_BINS="$BAD_PLATFORM_BINS
$BAD_ARCH_BINS"
if [[ ! -z "$PACKAGE_WHITELIST" ]]; then
BAD_BINS=$(echo "$BAD_BINS" | grep -vE "$PACKAGE_WHITELIST" || true)
fi
if [ `echo "$BAD_BINS" | wc -w` -ne 0 ]; then
echo
echo "***** BUILD FAILED *****"
echo
echo "Invalid build! $TARGET build has binaries for the wrong platform."
echo "Bad binaries are:"
echo "$BAD_BINS"
echo
echo "---"
exit 1
fi
echo "BUILD SUCCESSFUL"