Skip to content

Commit 892e993

Browse files
committed
Create the parent directories to place the .gcda files in if they don't exist.
That's kinda weird because the .gcno files are supposed to already be there, but libgcov does this and somehow Google has managed to depend on it. llvm-svn: 130879
1 parent 3c27391 commit 892e993

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

llvm/runtime/libprofile/GCDAProfiling.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <stdio.h>
2525
#include <stdlib.h>
2626
#include <string.h>
27+
#include <sys/stat.h>
28+
#include <sys/types.h>
2729

2830
/* #define DEBUG_GCDAPROFILING */
2931

@@ -64,6 +66,21 @@ static char *mangle_filename(const char *orig_filename) {
6466
return filename;
6567
}
6668

69+
static void recursive_mkdir(const char *filename) {
70+
char *pathname;
71+
int i, e;
72+
73+
for (i = 1, e = strlen(filename); i != e; ++i) {
74+
if (filename[i] == '/') {
75+
pathname = malloc(i + 1);
76+
strncpy(pathname, filename, i);
77+
pathname[i] = '\0';
78+
mkdir(pathname, 0750); /* some of these will fail, ignore it. */
79+
free(pathname);
80+
}
81+
}
82+
}
83+
6784
/*
6885
* --- LLVM line counter API ---
6986
*/
@@ -75,6 +92,7 @@ static char *mangle_filename(const char *orig_filename) {
7592
void llvm_gcda_start_file(const char *orig_filename) {
7693
char *filename;
7794
filename = mangle_filename(orig_filename);
95+
recursive_mkdir(filename);
7896
output_file = fopen(filename, "wb");
7997

8098
/* gcda file, version 404*, stamp LLVM. */

0 commit comments

Comments
 (0)