2018-06-05 01:41:00 +08:00
|
|
|
//===-- ClangParserTest.cpp --------------------------------------*- C++-*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2018-06-05 01:41:00 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-03-06 08:45:16 +08:00
|
|
|
#include "clang/Basic/Version.h"
|
|
|
|
|
2018-06-05 01:41:00 +08:00
|
|
|
#include "Plugins/ExpressionParser/Clang/ClangHost.h"
|
2019-12-23 17:38:12 +08:00
|
|
|
#include "TestingSupport/SubsystemRAII.h"
|
2018-06-05 01:41:00 +08:00
|
|
|
#include "TestingSupport/TestUtilities.h"
|
2018-11-01 05:49:27 +08:00
|
|
|
#include "lldb/Host/FileSystem.h"
|
2018-06-05 18:29:48 +08:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2018-06-05 08:32:41 +08:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2018-06-05 01:41:00 +08:00
|
|
|
#include "lldb/lldb-defines.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2018-06-05 18:29:48 +08:00
|
|
|
namespace {
|
|
|
|
struct ClangHostTest : public testing::Test {
|
2019-12-23 17:38:12 +08:00
|
|
|
SubsystemRAII<FileSystem, HostInfo> subsystems;
|
2018-06-05 18:29:48 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2019-03-06 08:45:16 +08:00
|
|
|
static std::string ComputeClangResourceDir(std::string lldb_shlib_path,
|
|
|
|
bool verify = false) {
|
2018-06-05 01:41:00 +08:00
|
|
|
FileSpec clang_dir;
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec lldb_shlib_spec(lldb_shlib_path);
|
2019-03-06 08:45:16 +08:00
|
|
|
ComputeClangResourceDirectory(lldb_shlib_spec, clang_dir, verify);
|
2018-06-05 01:41:00 +08:00
|
|
|
return clang_dir.GetPath();
|
|
|
|
}
|
|
|
|
|
2019-03-06 08:45:16 +08:00
|
|
|
TEST_F(ClangHostTest, ComputeClangResourceDirectory) {
|
2019-03-08 04:09:15 +08:00
|
|
|
#if !defined(_WIN32)
|
2019-03-06 08:45:16 +08:00
|
|
|
std::string path_to_liblldb = "/foo/bar/lib/";
|
|
|
|
std::string path_to_clang_dir = "/foo/bar/lib/clang/" CLANG_VERSION_STRING;
|
2019-03-08 04:09:15 +08:00
|
|
|
#else
|
|
|
|
std::string path_to_liblldb = "C:\\foo\\bar\\lib";
|
|
|
|
std::string path_to_clang_dir = "C:\\foo\\bar\\lib\\clang\\" CLANG_VERSION_STRING;
|
|
|
|
#endif
|
2019-03-06 08:45:16 +08:00
|
|
|
EXPECT_EQ(ComputeClangResourceDir(path_to_liblldb), path_to_clang_dir);
|
|
|
|
|
|
|
|
// The path doesn't really exist, so setting verify to true should make
|
2019-03-27 05:00:42 +08:00
|
|
|
// ComputeClangResourceDir not give you path_to_clang_dir.
|
|
|
|
EXPECT_NE(ComputeClangResourceDir(path_to_liblldb, true), path_to_clang_dir);
|
2019-03-06 08:45:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(__APPLE__)
|
2018-06-05 18:29:48 +08:00
|
|
|
TEST_F(ClangHostTest, MacOSX) {
|
2018-06-05 01:41:00 +08:00
|
|
|
// This returns whatever the POSIX fallback returns.
|
|
|
|
std::string posix = "/usr/lib/liblldb.dylib";
|
2019-03-06 08:45:16 +08:00
|
|
|
EXPECT_FALSE(ComputeClangResourceDir(posix).empty());
|
2018-06-05 01:41:00 +08:00
|
|
|
|
|
|
|
std::string build =
|
|
|
|
"/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Versions/A";
|
|
|
|
std::string build_clang =
|
|
|
|
"/lldb-macosx-x86_64/Library/Frameworks/LLDB.framework/Resources/Clang";
|
2019-03-06 08:45:16 +08:00
|
|
|
EXPECT_EQ(ComputeClangResourceDir(build), build_clang);
|
2018-06-05 01:41:00 +08:00
|
|
|
|
|
|
|
std::string xcode = "/Applications/Xcode.app/Contents/SharedFrameworks/"
|
|
|
|
"LLDB.framework/Versions/A";
|
|
|
|
std::string xcode_clang =
|
|
|
|
"/Applications/Xcode.app/Contents/Developer/Toolchains/"
|
|
|
|
"XcodeDefault.xctoolchain/usr/lib/swift/clang";
|
2019-03-06 08:45:16 +08:00
|
|
|
EXPECT_EQ(ComputeClangResourceDir(xcode), xcode_clang);
|
2018-06-05 01:41:00 +08:00
|
|
|
|
|
|
|
std::string toolchain =
|
|
|
|
"/Applications/Xcode.app/Contents/Developer/Toolchains/"
|
|
|
|
"Swift-4.1-development-snapshot.xctoolchain/System/Library/"
|
|
|
|
"PrivateFrameworks/LLDB.framework";
|
|
|
|
std::string toolchain_clang =
|
|
|
|
"/Applications/Xcode.app/Contents/Developer/Toolchains/"
|
|
|
|
"Swift-4.1-development-snapshot.xctoolchain/usr/lib/swift/clang";
|
2019-03-06 08:45:16 +08:00
|
|
|
EXPECT_EQ(ComputeClangResourceDir(toolchain), toolchain_clang);
|
2018-06-05 01:41:00 +08:00
|
|
|
|
|
|
|
std::string cltools = "/Library/Developer/CommandLineTools/Library/"
|
|
|
|
"PrivateFrameworks/LLDB.framework";
|
|
|
|
std::string cltools_clang =
|
|
|
|
"/Library/Developer/CommandLineTools/Library/PrivateFrameworks/"
|
|
|
|
"LLDB.framework/Resources/Clang";
|
2019-03-06 08:45:16 +08:00
|
|
|
EXPECT_EQ(ComputeClangResourceDir(cltools), cltools_clang);
|
2018-06-05 01:41:00 +08:00
|
|
|
|
|
|
|
// Test that a bogus path is detected.
|
2019-03-06 08:45:16 +08:00
|
|
|
EXPECT_NE(ComputeClangResourceDir(GetInputFilePath(xcode), true),
|
|
|
|
ComputeClangResourceDir(GetInputFilePath(xcode)));
|
2018-06-05 01:41:00 +08:00
|
|
|
}
|
2019-03-06 08:45:16 +08:00
|
|
|
#endif // __APPLE__
|