-
Notifications
You must be signed in to change notification settings - Fork 304
/
Copy pathcompile
executable file
·179 lines (156 loc) · 4.72 KB
/
compile
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
# fail fast
set -eo pipefail
# debug
# set -x
# parse and derive params
BUILD_DIR=$1
CACHE_DIR=$2
ENV_DIR=$3
LP_DIR=`cd $(dirname $0); cd ..; pwd`
function error() {
echo " ! $*" >&2
exit 1
}
function topic() {
echo "-----> $*"
}
function indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";;
*) sed -u "$c";;
esac
}
# Store which STACK we are running on in the cache to bust the cache if it changes
if [ -f $CACHE_DIR/.apt/STACK ]; then
CACHED_STACK=$(cat "$CACHE_DIR/.apt/STACK")
else
CACHED_STACK=$STACK
fi
# Ensure we store the STACK in the cache for next time.
mkdir -p "$CACHE_DIR/.apt"
echo "$STACK" > "$CACHE_DIR/.apt/STACK"
APT_CACHE_DIR="$CACHE_DIR/apt/cache"
APT_STATE_DIR="$CACHE_DIR/apt/state"
if [ $CACHED_STACK == $STACK ]; then
# STACK has not changed
topic "Reusing cache"
else
# STACK changed
topic "Detected Stack changes, flushing cache"
rm -rf $APT_CACHE_DIR
fi
mkdir -p "$APT_CACHE_DIR/archives/partial"
mkdir -p "$APT_STATE_DIR/lists/partial"
case "${STACK}" in
"heroku-20" | "heroku-22")
PACKAGES="
fonts-liberation
libasound2
libatk-bridge2.0-0
libatk1.0-0
libatspi2.0-0
libcups2
libdbus-1-3
libdrm2
libgbm1
libgcc1
libglib2.0-0
libgtk-3-0
libnspr4
libnss3
libpango-1.0-0
libpangocairo-1.0-0
libuuid1
libx11-xcb1
libxcb-dri3-0
libxcomposite1
libxcursor1
libxdamage1
libxfixes3
libxi6
libxkbcommon0
libxrandr2
libxshmfence1
libxss1
libxtst6
"
;;
"heroku-24")
PACKAGES="
fonts-liberation
libasound2t64
libatk-bridge2.0-0
libatk1.0-0
libatspi2.0-0
libcups2
libdbus-1-3
libdrm2
libgbm1
libgcc1
libglib2.0-0
libgtk-3-0
libnspr4
libnss3
libpango-1.0-0
libpangocairo-1.0-0
libuuid1
libx11-xcb1
libxcb-dri3-0
libxcomposite1
libxcursor1
libxdamage1
libxfixes3
libxi6
libxkbcommon0
libxrandr2
libxshmfence1
libxss1
libxtst6
"
;;
*)
error "STACK must be 'heroku-20', 'heroku-22' or 'heroku-24', not '${STACK}'."
esac
APT_OPTIONS="-o debug::nolocking=true -o dir::cache=$APT_CACHE_DIR -o dir::state=$APT_STATE_DIR"
APT_FLAGS="--allow-downgrades --allow-remove-essential --allow-change-held-packages"
topic "Updating apt caches"
apt-get $APT_OPTIONS update | indent
for PACKAGE in $PACKAGES; do
if [[ $PACKAGE == *deb ]]; then
PACKAGE_NAME=$(basename $PACKAGE .deb)
PACKAGE_FILE=$APT_CACHE_DIR/archives/$PACKAGE_NAME.deb
topic "Fetching $PACKAGE"
curl -s -L -z $PACKAGE_FILE -o $PACKAGE_FILE $PACKAGE 2>&1 | indent
else
topic "Fetching .debs for $PACKAGE"
apt-get $APT_OPTIONS -y $APT_FLAGS -d install --reinstall $PACKAGE | indent
fi
done
mkdir -p $BUILD_DIR/.apt
for DEB in $(ls -1 $APT_CACHE_DIR/archives/*.deb); do
topic "Installing $(basename $DEB)"
dpkg -x $DEB $BUILD_DIR/.apt/
done
topic "Writing profile script"
mkdir -p $BUILD_DIR/.profile.d
cat <<EOF >$BUILD_DIR/.profile.d/puppeteer.sh
export LD_LIBRARY_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu:\$HOME/.apt/usr/lib/i386-linux-gnu:\$HOME/.apt/usr/lib:\$LD_LIBRARY_PATH"
export LIBRARY_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu:\$HOME/.apt/usr/lib/i386-linux-gnu:\$HOME/.apt/usr/lib:\$LIBRARY_PATH"
export INCLUDE_PATH="\$HOME/.apt/usr/include:\$HOME/.apt/usr/include/x86_64-linux-gnu:\$INCLUDE_PATH"
export CPATH="\$INCLUDE_PATH"
export CPPPATH="\$INCLUDE_PATH"
export PKG_CONFIG_PATH="\$HOME/.apt/usr/lib/x86_64-linux-gnu/pkgconfig:\$HOME/.apt/usr/lib/i386-linux-gnu/pkgconfig:\$HOME/.apt/usr/lib/pkgconfig:\$PKG_CONFIG_PATH"
EOF
export LD_LIBRARY_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu:$BUILD_DIR/.apt/usr/lib:$LD_LIBRARY_PATH"
export LIBRARY_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu:$BUILD_DIR/.apt/usr/lib:$LIBRARY_PATH"
export INCLUDE_PATH="$BUILD_DIR/.apt/usr/include:$BUILD_DIR/.apt/usr/include/x86_64-linux-gnu:$INCLUDE_PATH"
export CPATH="$INCLUDE_PATH"
export CPPPATH="$INCLUDE_PATH"
export PKG_CONFIG_PATH="$BUILD_DIR/.apt/usr/lib/x86_64-linux-gnu/pkgconfig:$BUILD_DIR/.apt/usr/lib/i386-linux-gnu/pkgconfig:$BUILD_DIR/.apt/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
#give environment to later buildpacks
export | grep -E -e ' (LD_LIBRARY_PATH|LIBRARY_PATH|INCLUDE_PATH|CPATH|CPPPATH|PKG_CONFIG_PATH)=' > "$LP_DIR/export"
topic "Rewrite package-config files"
find $BUILD_DIR/.apt -type f -ipath '*/pkgconfig/*.pc' | xargs --no-run-if-empty -n 1 sed -i -e 's!^prefix=\(.*\)$!prefix='"$BUILD_DIR"'/.apt\1!g'