Simplify and correct calculation of default dependency file name

This commit is contained in:
Joel Rosdahl 2010-02-27 22:53:04 +01:00
parent f447ee7c14
commit 9fbe4e4578
2 changed files with 28 additions and 21 deletions

View File

@ -1464,29 +1464,20 @@ static void process_args(int argc, char **argv)
if (generating_dependencies) {
if (!dependency_filename_specified) {
char *default_depfile_name = x_strdup(output_obj);
char *p = strrchr(default_depfile_name, '.');
char *default_depfile_name;
char *last_dot, *last_slash;
if (p) {
if (strlen(p) < 2) {
stats_update(STATS_ARGS);
cc_log("Too short file extension in %s",
default_depfile_name);
failed();
return;
}
*p = 0;
last_dot = strrchr(output_obj, '.');
last_slash = strrchr(output_obj, '/');
if (!last_dot
|| (last_slash && last_dot < last_slash)) {
/* No extension, just add .d. */
last_dot = output_obj + strlen(output_obj);
}
else {
int len = p - default_depfile_name;
p = x_malloc(len + 3);
strncpy(default_depfile_name, p, len - 1);
free(default_depfile_name);
default_depfile_name = p;
}
strcat(default_depfile_name, ".d");
x_asprintf(&default_depfile_name,
"%.*s.d",
(int)(last_dot - output_obj),
output_obj);
args_add(stripped_args, "-MF");
args_add(stripped_args, default_depfile_name);
output_dep = make_relative_path(

16
test.sh
View File

@ -483,6 +483,22 @@ EOF
rm -f other.d
##################################################################
# Check calculation of dependency file names.
$CCACHE -z >/dev/null
mkdir test.dir
# Make sure the dependency file is in the cache:
$CCACHE $COMPILER -MD -c test.c
for ext in .obj "" . .foo.bar; do
testname="dependency file calculation from object file 'test$ext'"
dep_file=test.dir/`echo test$ext | sed 's/\.[^.]*\$//'`.d
rm -f $dep_file
$CCACHE $COMPILER -MD -c test.c -o test.dir/test$ext
if [ ! -f $dep_file ]; then
test_failed "$dep_file missing"
fi
done
##################################################################
# Check that -Wp,-MD,file.d works.
testname="-Wp,-MD"