]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Copy rather than link depend from the cache (#379)
authorAnders Björklund <anders.f.bjorklund@gmail.com>
Mon, 15 Apr 2019 19:35:08 +0000 (21:35 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 15 Apr 2019 19:35:08 +0000 (21:35 +0200)
The depends are small enough to avoid the copy, since it leads
to issues with mv when using automake to generate the Makefile.

src/ccache.c
test/suites/hardlink.bash

index d324c93d468714b561badd14524c3644e6d2e3c4..6604c0f8fa0dcf58298b81187af524feefab712d 100644 (file)
@@ -1250,12 +1250,12 @@ move_file_to_cache_same_fs(const char *source, const char *dest)
        do_copy_or_move_file_to_cache(source, dest, false);
 }
 
-// Copy or link a file from the cache.
+// Helper method for get_file_from_cache and copy_file_from_cache.
 static void
-get_file_from_cache(const char *source, const char *dest)
+do_copy_or_link_file_from_cache(const char *source, const char *dest, bool copy)
 {
        int ret;
-       bool do_link = conf->hard_link && !file_is_compressed(source);
+       bool do_link = !copy && conf->hard_link && !file_is_compressed(source);
        if (do_link) {
                x_unlink(dest);
                ret = link(source, dest);
@@ -1292,6 +1292,27 @@ get_file_from_cache(const char *source, const char *dest)
        cc_log("Created from cache: %s -> %s", source, dest);
 }
 
+// Copy or link a file from the cache.
+//
+// source must be a path in the cache (see get_path_in_cache). dest does not
+// have to be on the same file system as source.
+//
+// An attempt will be made to hard link source to dest if conf->hard_link is
+// true and conf->compression is false, otherwise copy. dest will be compressed
+// if conf->compression is true.
+static void
+get_file_from_cache(const char *source, const char *dest)
+{
+       do_copy_or_link_file_from_cache(source, dest, false);
+}
+
+// Copy a file from the cache.
+static void
+copy_file_from_cache(const char *source, const char *dest)
+{
+       do_copy_or_link_file_from_cache(source, dest, true);
+}
+
 // Send cached stderr, if any, to stderr.
 static void
 send_cached_stderr(void)
@@ -2243,7 +2264,8 @@ from_cache(enum fromcache_call_mode mode, bool put_object_in_manifest)
                }
        }
        if (produce_dep_file) {
-               get_file_from_cache(cached_dep, output_dep);
+               // Make a copy rather than a link, for move
+               copy_file_from_cache(cached_dep, output_dep);
        }
        if (generating_coverage) {
                get_file_from_cache(cached_cov, output_cov);
index bc93018572520a40c92b782d7edc721c7cb248c7..388bd1f9db251206c0a733a26d28b30ff4ded55d 100644 (file)
@@ -60,4 +60,20 @@ SUITE_hardlink() {
     expect_stat 'cache miss' 2
     expect_stat 'files in cache' 2
     expect_equal_object_files reference_test1.o test1.o
+
+    # -------------------------------------------------------------------------
+    TEST "Automake depend move"
+
+    unset CCACHE_NODIRECT
+
+    generate_code 1 test1.c
+
+    CCACHE_HARDLINK=1 CCACHE_DEPEND=1 $CCACHE_COMPILE -c -MMD -MF test1.d.tmp test1.c
+    expect_stat 'cache hit (direct)' 0
+    mv test1.d.tmp test1.d || test_failed "first mv failed"
+
+    CCACHE_HARDLINK=1 CCACHE_DEPEND=1 $CCACHE_COMPILE -c -MMD -MF test1.d.tmp test1.c
+    expect_stat 'cache hit (direct)' 1
+    mv test1.d.tmp test1.d || test_failed "second mv failed"
+
 }