3 #include "clang-c/Index.h"
12 static int print_remappings(const char *path
) {
18 remap
= clang_getRemappings(path
);
22 N
= clang_remap_getNumFiles(remap
);
23 for (i
= 0; i
!= N
; ++i
) {
24 clang_remap_getFilenames(remap
, i
, &origFname
, &transFname
);
26 fprintf(stdout
, "%s\n", clang_getCString(origFname
));
27 fprintf(stdout
, "%s\n", clang_getCString(transFname
));
29 clang_disposeString(origFname
);
30 clang_disposeString(transFname
);
33 clang_remap_dispose(remap
);
37 static int print_remappings_filelist(const char **files
, unsigned numFiles
) {
43 remap
= clang_getRemappingsFromFileList(files
, numFiles
);
47 N
= clang_remap_getNumFiles(remap
);
48 for (i
= 0; i
!= N
; ++i
) {
49 clang_remap_getFilenames(remap
, i
, &origFname
, &transFname
);
51 fprintf(stdout
, "%s\n", clang_getCString(origFname
));
52 fprintf(stdout
, "%s\n", clang_getCString(transFname
));
54 clang_disposeString(origFname
);
55 clang_disposeString(transFname
);
58 clang_remap_dispose(remap
);
62 /******************************************************************************/
63 /* Command line processing. */
64 /******************************************************************************/
66 static void print_usage(void) {
68 "usage: c-arcmt-test -mt-migrate-directory <path>\n"
69 " c-arcmt-test <remap-file-path1> <remap-file-path2> ...\n\n\n");
74 int carcmttest_main(int argc
, const char **argv
) {
75 clang_enableStackTraces();
76 if (argc
== 3 && strncmp(argv
[1], "-mt-migrate-directory", 21) == 0)
77 return print_remappings(argv
[2]);
80 return print_remappings_filelist(argv
+1, argc
-1);
88 /* We intentionally run in a separate thread to ensure we at least minimal
89 * testing of a multithreaded environment (for example, having a reduced stack
92 typedef struct thread_info
{
97 void thread_runner(void *client_data_v
) {
98 thread_info
*client_data
= client_data_v
;
99 client_data
->result
= carcmttest_main(client_data
->argc
, client_data
->argv
);
102 static void flush_atexit(void) {
103 /* stdout, and surprisingly even stderr, are not always flushed on process
104 * and thread exit, particularly when the system is under heavy load. */
109 int main(int argc
, const char **argv
) {
110 thread_info client_data
;
112 atexit(flush_atexit
);
115 if (getenv("LIBCLANG_LOGGING") == NULL
)
116 putenv("LIBCLANG_LOGGING=1");
117 _setmode( _fileno(stdout
), _O_BINARY
);
119 setenv("LIBCLANG_LOGGING", "1", /*overwrite=*/0);
122 if (getenv("CINDEXTEST_NOTHREADS"))
123 return carcmttest_main(argc
, argv
);
125 client_data
.argc
= argc
;
126 client_data
.argv
= argv
;
127 clang_executeOnThread(thread_runner
, &client_data
, 0);
128 return client_data
.result
;