From 3677aeb564469b9db6cbb9038bd6447e7e7f1626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 27 Jun 2017 21:33:47 +0200 Subject: [PATCH] Add support for drive letters Windows... --- src/libclang/libclang_parser.cpp | 7 ++++- test/libclang_parser.cpp | 46 +++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/libclang/libclang_parser.cpp b/src/libclang/libclang_parser.cpp index 93d121d..daba8b5 100644 --- a/src/libclang/libclang_parser.cpp +++ b/src/libclang/libclang_parser.cpp @@ -104,9 +104,14 @@ namespace using cxcompile_commands = detail::raii_wrapper; + bool has_drive_prefix(const std::string& file) + { + return file.size() > 2 && file[1] == ':'; + } + std::string get_full_path(const detail::cxstring& dir, const std::string& file) { - if (file.front() == '/' || file.front() == '\\') + if (has_drive_prefix(file) || file.front() == '/' || file.front() == '\\') // absolute file return file; else if (dir[dir.length() - 1] != '/' && dir[dir.length() - 1] != '\\') diff --git a/test/libclang_parser.cpp b/test/libclang_parser.cpp index 718c99c..f15cf6e 100644 --- a/test/libclang_parser.cpp +++ b/test/libclang_parser.cpp @@ -32,7 +32,34 @@ void require_flags(const libclang_compile_config& config, const char* flags) TEST_CASE("libclang_compile_config") { - // only test database parser +// only test database parser +#ifdef _WIN32 + auto json = R"([ +{ + "directory": "C:/foo", + "command": "/usr/bin/clang++ -Irelative -IC:/absolute -DA=FOO -DB(X)=X -c -o a.o a.cpp", + "file": "a.cpp" +}, +{ + "directory": "C:/bar/", + "command": "/usr/bin/clang++ -Irelative -DA=FOO -c -o b.o b.cpp", + "file": "C:/b.cpp", +}, +{ + "directory": "C:/bar/", + "command": "/usr/bin/clang++ -IC:/absolute -DB(X)=X -c -o b.o b.cpp", + "file": "C:/b.cpp", +}, +{ + "directory": "", + "command": "/usr/bin/clang++ -std=c++14 -fms-extensions -fms-compatibility -c -o c.o c.cpp", + "file": "C:/c.cpp", +} +])"; + +#define CPPAST_DETAIL_DRIVE "C:" + +#else auto json = R"([ { "directory": "/foo", @@ -42,7 +69,6 @@ TEST_CASE("libclang_compile_config") { "directory": "/bar/", "command": "/usr/bin/clang++ -Irelative -DA=FOO -c -o b.o b.cpp", - "command": "/usr/bin/clang++ -I/absolute -DB(X)=X -c -o b.o b.cpp", "file": "/b.cpp", }, { @@ -57,14 +83,20 @@ TEST_CASE("libclang_compile_config") } ])"; +#define CPPAST_DETAIL_DRIVE + +#endif + auto database = get_database(json); - libclang_compile_config a(database, "/foo/a.cpp"); - require_flags(a, "-I/foo/relative -I/absolute -DA=FOO -DB(X)=X"); + libclang_compile_config a(database, CPPAST_DETAIL_DRIVE "/foo/a.cpp"); + require_flags(a, "-I" CPPAST_DETAIL_DRIVE "/foo/relative -I" CPPAST_DETAIL_DRIVE + "/absolute -DA=FOO -DB(X)=X"); - libclang_compile_config b(database, "/b.cpp"); - require_flags(b, "-I/bar/relative -DA=FOO -I/absolute -DB(X)=X"); + libclang_compile_config b(database, CPPAST_DETAIL_DRIVE "/b.cpp"); + require_flags(b, "-I" CPPAST_DETAIL_DRIVE "/bar/relative -DA=FOO -I" CPPAST_DETAIL_DRIVE + "/absolute -DB(X)=X"); - libclang_compile_config c(database, "/c.cpp"); + libclang_compile_config c(database, CPPAST_DETAIL_DRIVE "/c.cpp"); require_flags(c, "-std=c++14 -fms-extensions -fms-compatibility"); }