2011-07-10 00:00:58 +04:00
|
|
|
/* c-arcmt-test.c */
|
|
|
|
|
2011-07-12 00:15:00 +04:00
|
|
|
#include "clang-c/Index.h"
|
2011-07-10 00:00:58 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2011-07-10 23:48:34 +04:00
|
|
|
#if defined(_WIN32)
|
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
2011-07-10 00:00:58 +04:00
|
|
|
|
|
|
|
static int print_remappings(const char *path) {
|
2011-07-12 00:15:00 +04:00
|
|
|
CXRemapping remap;
|
2011-07-10 00:00:58 +04:00
|
|
|
unsigned i, N;
|
|
|
|
CXString origFname;
|
|
|
|
CXString transFname;
|
|
|
|
|
2011-07-12 00:15:00 +04:00
|
|
|
remap = clang_getRemappings(path);
|
2011-07-10 00:00:58 +04:00
|
|
|
if (!remap)
|
|
|
|
return 1;
|
|
|
|
|
2011-07-12 00:15:00 +04:00
|
|
|
N = clang_remap_getNumFiles(remap);
|
2011-07-10 00:00:58 +04:00
|
|
|
for (i = 0; i != N; ++i) {
|
2011-07-12 00:15:00 +04:00
|
|
|
clang_remap_getFilenames(remap, i, &origFname, &transFname);
|
2011-07-10 00:00:58 +04:00
|
|
|
|
|
|
|
fprintf(stdout, "%s\n", clang_getCString(origFname));
|
|
|
|
fprintf(stdout, "%s\n", clang_getCString(transFname));
|
|
|
|
|
|
|
|
clang_disposeString(origFname);
|
|
|
|
clang_disposeString(transFname);
|
|
|
|
}
|
|
|
|
|
2011-07-12 00:15:00 +04:00
|
|
|
clang_remap_dispose(remap);
|
2011-07-10 00:00:58 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-07 00:06:33 +04:00
|
|
|
static int print_remappings_filelist(const char **files, unsigned numFiles) {
|
|
|
|
CXRemapping remap;
|
|
|
|
unsigned i, N;
|
|
|
|
CXString origFname;
|
|
|
|
CXString transFname;
|
|
|
|
|
|
|
|
remap = clang_getRemappingsFromFileList(files, numFiles);
|
|
|
|
if (!remap)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
N = clang_remap_getNumFiles(remap);
|
|
|
|
for (i = 0; i != N; ++i) {
|
|
|
|
clang_remap_getFilenames(remap, i, &origFname, &transFname);
|
|
|
|
|
|
|
|
fprintf(stdout, "%s\n", clang_getCString(origFname));
|
|
|
|
fprintf(stdout, "%s\n", clang_getCString(transFname));
|
|
|
|
|
|
|
|
clang_disposeString(origFname);
|
|
|
|
clang_disposeString(transFname);
|
|
|
|
}
|
|
|
|
|
|
|
|
clang_remap_dispose(remap);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-10 00:00:58 +04:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Command line processing. */
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
static void print_usage(void) {
|
|
|
|
fprintf(stderr,
|
2012-03-07 00:06:33 +04:00
|
|
|
"usage: c-arcmt-test -mt-migrate-directory <path>\n"
|
|
|
|
" c-arcmt-test <remap-file-path1> <remap-file-path2> ...\n\n\n");
|
2011-07-10 00:00:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
|
|
|
int carcmttest_main(int argc, const char **argv) {
|
|
|
|
clang_enableStackTraces();
|
2012-03-07 00:06:33 +04:00
|
|
|
if (argc == 3 && strncmp(argv[1], "-mt-migrate-directory", 21) == 0)
|
2011-07-10 00:00:58 +04:00
|
|
|
return print_remappings(argv[2]);
|
|
|
|
|
2012-03-07 00:06:33 +04:00
|
|
|
if (argc > 1)
|
|
|
|
return print_remappings_filelist(argv+1, argc-1);
|
|
|
|
|
2011-07-10 00:00:58 +04:00
|
|
|
print_usage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
|
|
|
/* We intentionally run in a separate thread to ensure we at least minimal
|
|
|
|
* testing of a multithreaded environment (for example, having a reduced stack
|
|
|
|
* size). */
|
|
|
|
|
|
|
|
typedef struct thread_info {
|
|
|
|
int argc;
|
|
|
|
const char **argv;
|
|
|
|
int result;
|
|
|
|
} thread_info;
|
|
|
|
void thread_runner(void *client_data_v) {
|
|
|
|
thread_info *client_data = client_data_v;
|
|
|
|
client_data->result = carcmttest_main(client_data->argc, client_data->argv);
|
2014-06-05 04:13:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void flush_atexit(void) {
|
2014-06-06 15:04:46 +04:00
|
|
|
/* stdout, and surprisingly even stderr, are not always flushed on process
|
|
|
|
* and thread exit, particularly when the system is under heavy load. */
|
2014-06-05 04:13:43 +04:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
2011-07-10 00:00:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, const char **argv) {
|
|
|
|
thread_info client_data;
|
|
|
|
|
2014-06-05 04:13:43 +04:00
|
|
|
atexit(flush_atexit);
|
|
|
|
|
2011-07-10 07:10:43 +04:00
|
|
|
#if defined(_WIN32)
|
|
|
|
if (getenv("LIBCLANG_LOGGING") == NULL)
|
|
|
|
putenv("LIBCLANG_LOGGING=1");
|
2011-07-10 23:48:34 +04:00
|
|
|
_setmode( _fileno(stdout), _O_BINARY );
|
2011-07-10 07:10:43 +04:00
|
|
|
#else
|
2011-07-10 00:00:58 +04:00
|
|
|
setenv("LIBCLANG_LOGGING", "1", /*overwrite=*/0);
|
2011-07-10 07:10:43 +04:00
|
|
|
#endif
|
2011-07-10 00:00:58 +04:00
|
|
|
|
|
|
|
if (getenv("CINDEXTEST_NOTHREADS"))
|
|
|
|
return carcmttest_main(argc, argv);
|
|
|
|
|
|
|
|
client_data.argc = argc;
|
|
|
|
client_data.argv = argv;
|
|
|
|
clang_executeOnThread(thread_runner, &client_data, 0);
|
|
|
|
return client_data.result;
|
|
|
|
}
|