3 #include "clang-c/Index.h"
4 #include "llvm/Support/AutoConvert.h"
13 static int print_remappings(const char *path
) {
19 remap
= clang_getRemappings(path
);
23 N
= clang_remap_getNumFiles(remap
);
24 for (i
= 0; i
!= N
; ++i
) {
25 clang_remap_getFilenames(remap
, i
, &origFname
, &transFname
);
27 fprintf(stdout
, "%s\n", clang_getCString(origFname
));
28 fprintf(stdout
, "%s\n", clang_getCString(transFname
));
30 clang_disposeString(origFname
);
31 clang_disposeString(transFname
);
34 clang_remap_dispose(remap
);
38 static int print_remappings_filelist(const char **files
, unsigned numFiles
) {
44 remap
= clang_getRemappingsFromFileList(files
, numFiles
);
48 N
= clang_remap_getNumFiles(remap
);
49 for (i
= 0; i
!= N
; ++i
) {
50 clang_remap_getFilenames(remap
, i
, &origFname
, &transFname
);
52 fprintf(stdout
, "%s\n", clang_getCString(origFname
));
53 fprintf(stdout
, "%s\n", clang_getCString(transFname
));
55 clang_disposeString(origFname
);
56 clang_disposeString(transFname
);
59 clang_remap_dispose(remap
);
63 /******************************************************************************/
64 /* Command line processing. */
65 /******************************************************************************/
67 static void print_usage(void) {
69 "usage: c-arcmt-test -mt-migrate-directory <path>\n"
70 " c-arcmt-test <remap-file-path1> <remap-file-path2> ...\n\n\n");
75 int carcmttest_main(int argc
, const char **argv
) {
76 clang_enableStackTraces();
77 if (argc
== 3 && strncmp(argv
[1], "-mt-migrate-directory", 21) == 0)
78 return print_remappings(argv
[2]);
81 return print_remappings_filelist(argv
+1, argc
-1);
89 /* We intentionally run in a separate thread to ensure we at least minimal
90 * testing of a multithreaded environment (for example, having a reduced stack
93 typedef struct thread_info
{
98 void thread_runner(void *client_data_v
) {
99 thread_info
*client_data
= client_data_v
;
100 client_data
->result
= carcmttest_main(client_data
->argc
, client_data
->argv
);
103 static void flush_atexit(void) {
104 /* stdout, and surprisingly even stderr, are not always flushed on process
105 * and thread exit, particularly when the system is under heavy load. */
110 int main(int argc
, const char **argv
) {
112 if (enablezOSAutoConversion(fileno(stdout
)) == -1)
113 fprintf(stderr
, "Setting conversion on stdout failed\n");
115 if (enablezOSAutoConversion(fileno(stderr
)) == -1)
116 fprintf(stderr
, "Setting conversion on stderr failed\n");
119 thread_info client_data
;
121 atexit(flush_atexit
);
124 if (getenv("LIBCLANG_LOGGING") == NULL
)
125 putenv("LIBCLANG_LOGGING=1");
126 _setmode( _fileno(stdout
), _O_BINARY
);
128 setenv("LIBCLANG_LOGGING", "1", /*overwrite=*/0);
131 if (getenv("CINDEXTEST_NOTHREADS"))
132 return carcmttest_main(argc
, argv
);
134 client_data
.argc
= argc
;
135 client_data
.argv
= argv
;
136 clang_executeOnThread(thread_runner
, &client_data
, 0);
137 return client_data
.result
;