diff --git a/bin/compile b/bin/compile index fb494c6..af544c2 100755 --- a/bin/compile +++ b/bin/compile @@ -29,6 +29,17 @@ function indent() { 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" APT_SOURCELIST_DIR="$CACHE_DIR/apt/sources" # place custom sources.list here @@ -42,12 +53,12 @@ case "$APT_VERSION" in *) APT_FORCE_YES="--allow-downgrades --allow-remove-essential --allow-change-held-packages";; esac -if [ -f $APT_CACHE_DIR/Aptfile ] && cmp -s $BUILD_DIR/Aptfile $APT_CACHE_DIR/Aptfile ; then - # Old Aptfile is the same as new +if [ -f $APT_CACHE_DIR/Aptfile ] && cmp -s $BUILD_DIR/Aptfile $APT_CACHE_DIR/Aptfile && [[ $CACHED_STACK == $STACK ]] ; then + # Old Aptfile is the same as new and STACK has not changed topic "Reusing cache" else - # Aptfile changed or does not exist - topic "Detected Aptfile changes, flushing cache" + # Aptfile changed or does not exist or STACK changed + topic "Detected Aptfile or Stack changes, flushing cache" rm -rf $APT_CACHE_DIR mkdir -p "$APT_CACHE_DIR/archives/partial" mkdir -p "$APT_STATE_DIR/lists/partial" diff --git a/test/compile_test.sh b/test/compile_test.sh index a742ab5..f5c4a40 100644 --- a/test/compile_test.sh +++ b/test/compile_test.sh @@ -3,11 +3,7 @@ . ${BUILDPACK_TEST_RUNNER_HOME}/lib/test_utils.sh testCompile() { - cat > ${BUILD_DIR}/Aptfile < "$CACHE_DIR/.apt/STACK" + + #Load the Aptfile into the cache, to exclusively test the stack changes + mkdir -p "$CACHE_DIR/apt/cache" + cp $BUILD_DIR/Aptfile "$CACHE_DIR/apt/cache" + + compile + + assertCapturedSuccess + + assertCaptured "Detected Aptfile or Stack changes, flushing cache" +} + +testStackNoChange() { + loadFixture "Aptfile" + + #Load the Aptfile into the cache, to exclusively test the stack changes + mkdir -p "$CACHE_DIR/apt/cache" + cp $BUILD_DIR/Aptfile "$CACHE_DIR/apt/cache" + + compile + + assertCaptured "Reusing cache" +} + +testStackCached() { + loadFixture "Aptfile" + + compile + assertCapturedSuccess + + assertTrue 'STACK not cached' "[ -e $CACHE_DIR/.apt/STACK ]" +} + +loadFixture() { + cp -a $BUILDPACK_HOME/test/fixtures/$1/. ${BUILD_DIR} +} \ No newline at end of file diff --git a/test/fixtures/Aptfile/Aptfile b/test/fixtures/Aptfile/Aptfile new file mode 100644 index 0000000..b24b956 --- /dev/null +++ b/test/fixtures/Aptfile/Aptfile @@ -0,0 +1,3 @@ +# Test comment +s3cmd +wget \ No newline at end of file