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);
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)
}
}
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);
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"
+
}