-
Notifications
You must be signed in to change notification settings - Fork 101
/
build-release.sh
executable file
·120 lines (94 loc) · 3.56 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
#!/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
echo "CONFIGURING FOR $TARGET_PLATFORM"
if [ -z "$TARGET_PLATFORM" ]; then
echo 'A target platform (linux/win32/darwin) is required'
exit 1
fi
TARGET_ARCH=`node -e 'console.log(process.arch)'`
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
# 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"
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_PLATFORM" in
linux)
EXPECTED_BIN_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_BIN_STRING="MS Windows"
PACKAGE_WHITELIST=""
;;
darwin)
EXPECTED_BIN_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_BIN_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 {} \;
)
echo "NATIVE BINS: $NATIVE_BINARIES"
BAD_BINS=$(echo "$NATIVE_BINARIES" | grep -v "$EXPECTED_BIN_STRING" || true)
if [[ ! -z "$PACKAGE_WHITELIST" ]]; then
BAD_BINS=$(echo "$BAD_BINS" | grep -E -v "$PACKAGE_WHITELIST" || true)
fi
if [ `echo "$BAD_BINS" | wc -w` -ne 0 ]; then
echo
echo "***** BUILD FAILED *****"
echo
echo "Invalid build! $TARGET_PLATFORM build has binaries for the wrong platform."
echo "Bad binaries are:"
echo "$BAD_BINS"
echo
echo "---"
exit 1
fi
echo "BUILD SUCCESSFUL"