Skip to content

Commit 8ce845e

Browse files
committed
Check the dyno's STACK to download the correct version on stack change
As edmorley points out, there can be ABI changes between different stacks which could cause issues. It is, after all, the reason that we have a download specific to each stack. This change adds a .stack file in the cached directory which we use to track which version of the compiled binary was originally downloaded. When that file is missing (i.e. for anyone already using the buildpack) then we will force a download on the next deploy. Fixes gaffneyc#19
1 parent 1e33801 commit 8ce845e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

bin/compile

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ dest="$BUILD_DIR/vendor/jemalloc"
2121
# bundle is the full path to the cached jemalloc binaries for this version.
2222
bundle=$CACHE_DIR/jemalloc/$version
2323

24+
# cached checks to see if there is a compatible version in the cache.
25+
function cached() {
26+
# Returns false when there is no matching version in the cache.
27+
if [[ ! -d $bundle ]]; then
28+
return 1
29+
fi
30+
31+
if [ -f "$bundle/.stack" ]; then
32+
CACHED_STACK=$(cat $bundle/.stack)
33+
fi
34+
35+
# True when the downloaded version in the cache is for the same stack as the
36+
# compiling dyno. CACHED_STACK will be empty when the .stack file is missing
37+
# which also forces a fresh download.
38+
[[ $CACHED_STACK == $STACK ]]
39+
}
40+
2441
function download_jemalloc() {
2542
url="https://github.com/gaffneyc/heroku-buildpack-jemalloc/releases/download/$STACK/jemalloc-$version.tar.bz2"
2643

@@ -40,13 +57,17 @@ function download_jemalloc() {
4057

4158
mkdir -p $bundle
4259
tar -xj -f /tmp/jemalloc.tar.bz2 -C $bundle
60+
61+
# Store the stack version (e.g. heroku-20) that was downloaded to force a
62+
# redownload should the stack change.
63+
echo "$STACK" > "$bundle/.stack"
4364
}
4465

4566
echo "-----> jemalloc: Vendoring $version"
4667

4768
# Check if this version of jemalloc is in the cache and download it if it
4869
# doesn't exist.
49-
if [[ ! -d $bundle ]]; then
70+
if ! cached; then
5071
download_jemalloc
5172
fi
5273

0 commit comments

Comments
 (0)