From f4294371aeda31d28fa712e1e20506dd547adb18 Mon Sep 17 00:00:00 2001 From: Kevin Brolly Date: Thu, 17 Oct 2019 13:55:52 +0100 Subject: [PATCH 1/7] Cache the STACK in use and use it to bust cache if it changes --- bin/compile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/compile b/bin/compile index fb494c6..bbe505e 100755 --- a/bin/compile +++ b/bin/compile @@ -29,6 +29,13 @@ 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 + 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,7 +49,7 @@ 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 +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 topic "Reusing cache" else @@ -112,3 +119,6 @@ export | grep -E -e ' (PATH|LD_LIBRARY_PATH|LIBRARY_PATH|INCLUDE_PATH|CPATH|CPPP 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' + +# Store which STACK we are running on in the cache to bust the cache if it changes +echo "$STACK" > "$CACHE_DIR/.apt/STACK" \ No newline at end of file From 5135ddfc0eb211b605a29cd7a64af8d9f364126c Mon Sep 17 00:00:00 2001 From: Kevin Brolly Date: Thu, 17 Oct 2019 13:58:24 +0100 Subject: [PATCH 2/7] Refactored tests and added fixtures to make future tests easier --- test/compile_test.sh | 10 +++++----- test/fixtures/Aptfile/Aptfile | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/Aptfile/Aptfile diff --git a/test/compile_test.sh b/test/compile_test.sh index a742ab5..052bcc2 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 < Date: Thu, 17 Oct 2019 13:59:10 +0100 Subject: [PATCH 3/7] Added tests for new stack cache busting feature --- test/compile_test.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/compile_test.sh b/test/compile_test.sh index 052bcc2..f0da86e 100644 --- a/test/compile_test.sh +++ b/test/compile_test.sh @@ -15,6 +15,36 @@ testCompile() { assertCaptured "Installing wget_" } +testStackChange() { + loadFixture "Aptfile" + + #Set the cached STACK value to a non-existent stack, so it is guaranteed to change. + mkdir -p "$CACHE_DIR/.apt/" + echo "cedar-10" > "$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" +} + loadFixture() { cp -a $BUILDPACK_HOME/test/fixtures/$1/. ${BUILD_DIR} } \ No newline at end of file From cf5aceb6921697774f38fa156ae12b7eb2f72b08 Mon Sep 17 00:00:00 2001 From: Kevin Brolly Date: Thu, 17 Oct 2019 14:22:55 +0100 Subject: [PATCH 4/7] Fixed issue with stack not getting cached --- bin/compile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/compile b/bin/compile index bbe505e..49c40d9 100755 --- a/bin/compile +++ b/bin/compile @@ -34,6 +34,9 @@ if [ -f $CACHE_DIR/.apt/STACK ]; then CACHED_STACK=$(cat "$CACHE_DIR/.apt/STACK") else CACHED_STACK=$STACK + # Store the STACK in the cache for next time. + mkdir -p "$CACHE_DIR/.apt" + echo "$STACK" > "$CACHE_DIR/.apt/STACK" fi APT_CACHE_DIR="$CACHE_DIR/apt/cache" @@ -119,6 +122,3 @@ export | grep -E -e ' (PATH|LD_LIBRARY_PATH|LIBRARY_PATH|INCLUDE_PATH|CPATH|CPPP 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' - -# Store which STACK we are running on in the cache to bust the cache if it changes -echo "$STACK" > "$CACHE_DIR/.apt/STACK" \ No newline at end of file From a20191864cd4a1f2262936119cf3bac061235cef Mon Sep 17 00:00:00 2001 From: Kevin Brolly Date: Thu, 17 Oct 2019 14:25:40 +0100 Subject: [PATCH 5/7] Added new text for when stack changes --- bin/compile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/compile b/bin/compile index 49c40d9..b683beb 100755 --- a/bin/compile +++ b/bin/compile @@ -53,11 +53,11 @@ case "$APT_VERSION" in esac 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 + # 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" From 9a1c7b68dd0fd6724f52ef4336222140a669c36b Mon Sep 17 00:00:00 2001 From: Kevin Brolly Date: Thu, 17 Oct 2019 15:53:02 +0100 Subject: [PATCH 6/7] Fixed issue where STACK was not always cached --- bin/compile | 7 ++++--- test/compile_test.sh | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/bin/compile b/bin/compile index b683beb..af544c2 100755 --- a/bin/compile +++ b/bin/compile @@ -34,11 +34,12 @@ if [ -f $CACHE_DIR/.apt/STACK ]; then CACHED_STACK=$(cat "$CACHE_DIR/.apt/STACK") else CACHED_STACK=$STACK - # Store the STACK in the cache for next time. - mkdir -p "$CACHE_DIR/.apt" - echo "$STACK" > "$CACHE_DIR/.apt/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 diff --git a/test/compile_test.sh b/test/compile_test.sh index f0da86e..af95c4b 100644 --- a/test/compile_test.sh +++ b/test/compile_test.sh @@ -45,6 +45,17 @@ testStackNoChange() { assertCaptured "Reusing cache" } +testStackCached() { + # Test that we are correctly storing the value of STACK in the cache + loadFixture "Aptfile" + + compile + assertCapturedSuccess + + CACHED_STACK=$(cat "$CACHE_DIR/.apt/STACK") + assertTrue 'STACK not cached' "[[ $CACHED_STACK == $STACK ]]" +} + loadFixture() { cp -a $BUILDPACK_HOME/test/fixtures/$1/. ${BUILD_DIR} } \ No newline at end of file From 6d2c69f690a060d92e7ccd206a76a013ec100f80 Mon Sep 17 00:00:00 2001 From: Kevin Brolly Date: Thu, 17 Oct 2019 16:13:56 +0100 Subject: [PATCH 7/7] Fixed test to ensure STACK is cached --- test/compile_test.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/compile_test.sh b/test/compile_test.sh index af95c4b..f5c4a40 100644 --- a/test/compile_test.sh +++ b/test/compile_test.sh @@ -46,14 +46,12 @@ testStackNoChange() { } testStackCached() { - # Test that we are correctly storing the value of STACK in the cache loadFixture "Aptfile" compile assertCapturedSuccess - CACHED_STACK=$(cat "$CACHE_DIR/.apt/STACK") - assertTrue 'STACK not cached' "[[ $CACHED_STACK == $STACK ]]" + assertTrue 'STACK not cached' "[ -e $CACHE_DIR/.apt/STACK ]" } loadFixture() {