diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2015-11-18 16:14:27 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2015-11-18 16:14:27 +0000 |
| commit | c02670ed50f009eeb24ad7f0fe00cbf887e008d0 (patch) | |
| tree | 91534d89cfdf7ec6423ed88a229c34a6b088160c /clang/unittests/libclang | |
| parent | 4ba4816b9701aecbc757f7d806895e114908f309 (diff) | |
| download | bcm5719-llvm-c02670ed50f009eeb24ad7f0fe00cbf887e008d0.tar.gz bcm5719-llvm-c02670ed50f009eeb24ad7f0fe00cbf887e008d0.zip | |
[libclang] Add entry points that take a full command line including argv[0].
This provides both a more uniform interface and makes libclang behave like
clang tooling wrt relative paths against argv[0]. This is necessary for
finding paths to a c++ standard library relative to a clang binary given
in a compilation database. It can also be used to find paths relative to
libclang.so if the full path to it is passed in.
Differential Revision: http://reviews.llvm.org/D14695
llvm-svn: 253466
Diffstat (limited to 'clang/unittests/libclang')
| -rw-r--r-- | clang/unittests/libclang/LibclangTest.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp index becebf076d6..fc28b172e6d 100644 --- a/clang/unittests/libclang/LibclangTest.cpp +++ b/clang/unittests/libclang/LibclangTest.cpp @@ -379,8 +379,10 @@ public: Filename = Path.str(); Files.insert(Filename); } + llvm::sys::fs::create_directories(llvm::sys::path::parent_path(Filename)); std::ofstream OS(Filename); OS << Contents; + assert(OS.good()); } void DisplayDiagnostics() { unsigned NumDiagnostics = clang_getNumDiagnostics(ClangTU); @@ -465,3 +467,27 @@ TEST_F(LibclangReparseTest, ReparseWithModule) { ASSERT_TRUE(ReparseTU(0, nullptr /* No unsaved files. */)); EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU)); } + +TEST_F(LibclangReparseTest, clang_parseTranslationUnit2FullArgv) { + std::string EmptyFiles[] = {"lib/gcc/arm-linux-gnueabi/4.6.1/crtbegin.o", + "include/arm-linux-gnueabi/.keep", + "include/c++/4.6.1/vector"}; + + for (auto &Name : EmptyFiles) + WriteFile(Name, "\n"); + + std::string Filename = "test.cc"; + WriteFile(Filename, "#include <vector>\n"); + + std::string Clang = "bin/clang"; + WriteFile(Clang, ""); + + const char *Argv[] = {Clang.c_str(), "-target", "arm-linux-gnueabi"}; + + EXPECT_EQ(CXError_Success, + clang_parseTranslationUnit2FullArgv(Index, Filename.c_str(), Argv, + sizeof(Argv) / sizeof(Argv[0]), + nullptr, 0, TUFlags, &ClangTU)); + EXPECT_EQ(0U, clang_getNumDiagnostics(ClangTU)); + DisplayDiagnostics(); +} |

