| 1 |
//===-- ClangParserTest.cpp -----------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "clang/Basic/Version.h" |
| 10 |
|
| 11 |
#include "Plugins/ExpressionParser/Clang/ClangHost.h" |
| 12 |
#include "TestingSupport/SubsystemRAII.h" |
| 13 |
#include "TestingSupport/TestUtilities.h" |
| 14 |
#include "lldb/Host/Config.h" |
| 15 |
#include "lldb/Host/FileSystem.h" |
| 16 |
#include "lldb/Host/HostInfo.h" |
| 17 |
#include "lldb/Utility/FileSpec.h" |
| 18 |
#include "lldb/lldb-defines.h" |
| 19 |
#include "gtest/gtest.h" |
| 20 |
|
| 21 |
using namespace lldb_private; |
| 22 |
|
| 23 |
namespace { |
| 24 |
struct ClangHostTest : public testing::Test { |
| 25 |
SubsystemRAII<FileSystem, HostInfo> subsystems; |
| 26 |
}; |
| 27 |
} // namespace |
| 28 |
|
| 29 |
static std::string ComputeClangResourceDir(std::string lldb_shlib_path, |
| 30 |
bool verify = false) { |
| 31 |
FileSpec clang_dir; |
| 32 |
FileSpec lldb_shlib_spec(lldb_shlib_path); |
| 33 |
ComputeClangResourceDirectory(lldb_shlib_spec, clang_dir, verify); |
| 34 |
return clang_dir.GetPath(); |
| 35 |
} |
| 36 |
|
| 37 |
TEST_F(ClangHostTest, ComputeClangResourceDirectory) { |
| 38 |
#if !defined(_WIN32) |
| 39 |
std::string path_to_liblldb = "/foo/bar/lib/"; |
| 40 |
std::string path_to_clang_dir = |
| 41 |
"/foo/bar/" LLDB_INSTALL_LIBDIR_BASENAME "/clang/" CLANG_VERSION_MAJOR_STRING; |
| 42 |
#else |
| 43 |
std::string path_to_liblldb = "C:\\foo\\bar\\lib"; |
| 44 |
std::string path_to_clang_dir = |
| 45 |
"C:\\foo\\bar\\lib\\clang\\" CLANG_VERSION_MAJOR_STRING; |
| 46 |
#endif |
| 47 |
EXPECT_EQ(ComputeClangResourceDir(path_to_liblldb), path_to_clang_dir); |
| 48 |
|
| 49 |
// The path doesn't really exist, so setting verify to true should make |
| 50 |
// ComputeClangResourceDir not give you path_to_clang_dir. |
| 51 |
EXPECT_NE(ComputeClangResourceDir(path_to_liblldb, true), path_to_clang_dir); |
| 52 |
} |
| 53 |
|
| 54 |
#if defined(__APPLE__) |
| 55 |
TEST_F(ClangHostTest, MacOSX) { |
| 56 |
// This returns whatever the POSIX fallback returns. |
| 57 |
std::string posix = "/usr/lib/liblldb.dylib"; |
| 58 |
EXPECT_FALSE(ComputeClangResourceDir(posix).empty()); |
| 59 |
|
| 60 |
std::string build = |
| 61 |
"/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Versions/A"; |
| 62 |
std::string build_clang = |
| 63 |
"/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Resources/Clang"; |
| 64 |
EXPECT_EQ(ComputeClangResourceDir(build), build_clang); |
| 65 |
|
| 66 |
std::string xcode = "/Applications/Xcode.app/Contents/SharedFrameworks/" |
| 67 |
"LLDB.framework/Versions/A"; |
| 68 |
std::string xcode_clang = |
| 69 |
"/Applications/Xcode.app/Contents/Developer/Toolchains/" |
| 70 |
"XcodeDefault.xctoolchain/usr/lib/swift/clang"; |
| 71 |
EXPECT_EQ(ComputeClangResourceDir(xcode), xcode_clang); |
| 72 |
|
| 73 |
std::string toolchain = |
| 74 |
"/Applications/Xcode.app/Contents/Developer/Toolchains/" |
| 75 |
"Swift-4.1-development-snapshot.xctoolchain/System/Library/" |
| 76 |
"PrivateFrameworks/LLDB.framework"; |
| 77 |
std::string toolchain_clang = |
| 78 |
"/Applications/Xcode.app/Contents/Developer/Toolchains/" |
| 79 |
"Swift-4.1-development-snapshot.xctoolchain/usr/lib/swift/clang"; |
| 80 |
EXPECT_EQ(ComputeClangResourceDir(toolchain), toolchain_clang); |
| 81 |
|
| 82 |
std::string cltools = "/Library/Developer/CommandLineTools/Library/" |
| 83 |
"PrivateFrameworks/LLDB.framework"; |
| 84 |
std::string cltools_clang = |
| 85 |
"/Library/Developer/CommandLineTools/Library/PrivateFrameworks/" |
| 86 |
"LLDB.framework/Resources/Clang"; |
| 87 |
EXPECT_EQ(ComputeClangResourceDir(cltools), cltools_clang); |
| 88 |
|
| 89 |
// Test that a bogus path is detected. |
| 90 |
EXPECT_NE(ComputeClangResourceDir(GetInputFilePath(xcode), true), |
| 91 |
ComputeClangResourceDir(GetInputFilePath(xcode))); |
| 92 |
} |
| 93 |
#endif // __APPLE__ |