]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don't try to store file hash in manifest in read-only mode
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 3 Mar 2010 20:59:12 +0000 (21:59 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 3 Mar 2010 20:59:12 +0000 (21:59 +0100)
ccache.c
test.sh

index 8bcef371de2df386d071170871ed15d4ec6de06b..acd9205263669ce599d3b60b7b7c074e7c851738 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -1057,7 +1057,9 @@ static void from_cache(enum fromcache_call_mode mode, int put_object_in_manifest
        }
 
        /* Create or update the manifest file. */
-       if (put_object_in_manifest && included_files) {
+       if (put_object_in_manifest
+           && included_files
+           && !getenv("CCACHE_READONLY")) {
                if (manifest_put(manifest_path, object_hash, included_files)) {
                        cc_log("Added object file hash to %s",
                                manifest_path);
diff --git a/test.sh b/test.sh
index 1ce581910ad2d7864e98da1394b0b2f2b38bf9f5..eda5443be76936e53d08be701256e0e3b7d5331c 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -886,6 +886,63 @@ EOF
     checkstat 'cache miss' 1
 }
 
+readonly_suite() {
+    ##################################################################
+    # Create some code to compile.
+    echo "int test;" >test.c
+    echo "int test2;" >test2.c
+
+    # Cache a compilation.
+    $CCACHE $COMPILER -c test.c -o test.o
+    checkstat 'cache hit (preprocessed)' 0
+    checkstat 'cache miss' 1
+
+    # Make the cache readonly
+    # Check that readonly mode finds the result.
+    testname="cache hit"
+    rm -f test.o
+    chmod -R a-w $CCACHE_DIR
+    CCACHE_READONLY=1 CCACHE_TEMPDIR=/tmp CCACHE_PREFIX=false $CCACHE $COMPILER -c test.c -o test.o
+    status=$?
+    chmod -R a+w $CCACHE_DIR
+    if [ $status -ne 0 ]; then
+        test_failed "failure when compiling test.c readonly"
+    fi
+    if [ ! -f test.o ]; then
+        test_failed "test.o missing"
+    fi
+
+    # Check that readonly mode doesn't try to store new results.
+    testname="cache miss"
+    files_before=`find $CCACHE_DIR -type f | wc -l`
+    CCACHE_READONLY=1 CCACHE_TEMPDIR=/tmp $CCACHE $COMPILER -c test2.c -o test2.o
+    if [ $? -ne 0 ]; then
+        test_failed "failure when compiling test2.c readonly"
+    fi
+    if [ ! -f test2.o ]; then
+        test_failed "test2.o missing"
+    fi
+    files_after=`find $CCACHE_DIR -type f | wc -l`
+    if [ $files_before -ne $files_after ]; then
+        test_failed "readonly mode stored files in the cache"
+    fi
+
+    # Chech that readonly mode and direct mode works.
+    unset CCACHE_NODIRECT
+    files_before=`find $CCACHE_DIR -type f | wc -l`
+    CCACHE_READONLY=1 CCACHE_TEMPDIR=/tmp $CCACHE $COMPILER -c test.c -o test.o
+    export CCACHE_NODIRECT=1
+    if [ $? -ne 0 ]; then
+        test_failed "failure when compiling test2.c readonly"
+    fi
+    files_after=`find $CCACHE_DIR -type f | wc -l`
+    if [ $files_before -ne $files_after ]; then
+        test_failed "readonly mode + direct mode stored files in the cache"
+    fi
+
+    ##################################################################
+}
+
 ######################################################################
 # main program
 
@@ -913,6 +970,7 @@ nlevels1
 direct
 basedir
 compression
+readonly
 "
 
 if [ -z "$suites" ]; then