diff options
author | Anders F Björklund <anders.f.bjorklund@gmail.com> | 2017-03-17 20:21:09 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2017-03-25 20:36:09 +0100 |
commit | 13341d006f4c8086d7d01cce96d48c8202d0c0aa (patch) | |
tree | 43f0bf789f87f857b5cfa35a7a903dac349ba2b2 | |
parent | 0ffb141fdc904f3005156cc8e71dd48eeab7c970 (diff) | |
download | ccache-13341d006f4c8086d7d01cce96d48c8202d0c0aa.tar.gz |
Support using multiple -fdebug-prefix-map
Previously only the last one was actually being applied to the hash.
Note that the compiler will actually only *use* one of all the paths.
Closes #163.
-rw-r--r-- | ccache.c | 20 | ||||
-rwxr-xr-x | test.sh | 26 |
2 files changed, 41 insertions, 5 deletions
@@ -172,7 +172,10 @@ static bool generating_dependencies; static bool generating_coverage; // Relocating debuginfo in the format old=new. -static char *debug_prefix_map = NULL; +static char **debug_prefix_maps = NULL; + +// Size of debug_prefix_maps list. +static size_t debug_prefix_maps_len = 0; // Is the compiler being asked to output coverage data (.gcda) at runtime? static bool profile_arcs; @@ -1548,8 +1551,8 @@ calculate_common_hash(struct args *args, struct mdfour *hash) // Possibly hash the current working directory. if (generating_debuginfo && conf->hash_dir) { char *cwd = gnu_getcwd(); - if (debug_prefix_map) { - char *map = debug_prefix_map; + for (size_t i = 0; i < debug_prefix_maps_len; i++) { + char *map = debug_prefix_maps[i]; char *sep = strchr(map, '='); if (sep) { char *old = x_strndup(map, sep - map); @@ -2307,7 +2310,9 @@ cc_process_args(struct args *args, struct args **preprocessor_args, continue; } if (str_startswith(argv[i], "-fdebug-prefix-map=")) { - debug_prefix_map = x_strdup(argv[i] + 19); + debug_prefix_maps = x_realloc(debug_prefix_maps, + (debug_prefix_maps_len + 1) * sizeof(char *)); + debug_prefix_maps[debug_prefix_maps_len++] = x_strdup(argv[i] + 19); args_add(stripped_args, argv[i]); continue; } @@ -3062,7 +3067,12 @@ cc_reset(void) free(primary_config_path); primary_config_path = NULL; free(secondary_config_path); secondary_config_path = NULL; free(current_working_dir); current_working_dir = NULL; - free(debug_prefix_map); debug_prefix_map = NULL; + for (size_t i = 0; i < debug_prefix_maps_len; i++) { + free(debug_prefix_maps[i]); + debug_prefix_maps[i] = NULL; + } + free(debug_prefix_maps); debug_prefix_maps = NULL; + debug_prefix_maps_len = 0; free(profile_dir); profile_dir = NULL; free(included_pch_file); included_pch_file = NULL; args_free(orig_args); orig_args = NULL; @@ -1323,6 +1323,32 @@ SUITE_debug_prefix_map() { if grep -E "[^=]`pwd`[^=]" test.o >/dev/null 2>&1; then test_failed "Source dir (`pwd`) found in test.o" fi + + # ------------------------------------------------------------------------- + TEST "Multiple -fdebug-prefix-map" + + cd dir1 + CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=foobar -fdebug-prefix-map=foo=bar -c `pwd`/src/test.c -o `pwd`/test.o + expect_stat 'cache hit (direct)' 0 + expect_stat 'cache hit (preprocessed)' 0 + expect_stat 'cache miss' 1 + expect_stat 'files in cache' 2 + if grep -E "[^=]`pwd`[^=]" test.o >/dev/null 2>&1; then + test_failed "Source dir (`pwd`) found in test.o" + fi + if ! grep "foobar" test.o >/dev/null 2>&1; then + test_failed "Relocation (foobar) not found in test.o" + fi + + cd ../dir2 + CCACHE_BASEDIR=`pwd` $CCACHE_COMPILE -I`pwd`/include -g -fdebug-prefix-map=`pwd`=foobar -fdebug-prefix-map=foo=bar -c `pwd`/src/test.c -o `pwd`/test.o + expect_stat 'cache hit (direct)' 1 + expect_stat 'cache hit (preprocessed)' 0 + expect_stat 'cache miss' 1 + expect_stat 'files in cache' 2 + if grep -E "[^=]`pwd`[^=]" test.o >/dev/null 2>&1; then + test_failed "Source dir (`pwd`) found in test.o" + fi } # ============================================================================= |