13#include "llvm/TargetParser/Triple.h"
35static llvm::SmallVector<std::string, 2>
37 llvm::SmallVector<std::string, 2> paths;
38 if (!triple.str().empty()) {
39 paths.push_back(
"/usr/include/" + triple.str());
40 if (!triple.getArchName().empty() ||
41 triple.getOSAndEnvironmentName().empty())
42 paths.push_back((
"/usr/include/" + triple.getArchName() +
"-" +
43 triple.getOSAndEnvironmentName())
51static std::optional<llvm::StringRef>
55 size_t pos = path_to_file.find(pattern);
56 if (pos == llvm::StringRef::npos)
59 return path_to_file.substr(0, pos + pattern.size());
63 const llvm::Triple &triple) {
64 using namespace llvm::sys::path;
67 llvm::StringRef posix_dir(dir_buffer);
70 static llvm::Regex libcpp_regex(R
"regex(/c[+][+]/v[0-9]/)regex");
74 if (libcpp_regex.match(convert_to_slash(f.
GetPath())) &&
75 parent_path(posix_dir, Style::posix).ends_with(
"c++")) {
78 if (triple.str().empty())
81 posix_dir.consume_back(
"c++/v1");
84 (posix_dir + triple.str() +
"/c++/v1").str());
87 std::optional<llvm::StringRef> inc_path;
101static std::string
MakePath(llvm::StringRef lhs, llvm::StringRef rhs) {
102 llvm::SmallString<256> result(lhs);
103 llvm::sys::path::append(result, rhs);
104 return std::string(result);
114 const std::vector<std::string> files_to_check = {
126 for (llvm::StringRef file_to_check : files_to_check) {
135 const FileSpecList &support_files,
const llvm::Triple &triple) {
137 bool error = !llvm::all_of(support_files, [&](
auto &file) {
144 llvm::SmallString<256> resource_dir;
static llvm::raw_ostream & error(Stream &strm)
static std::optional< llvm::StringRef > guessIncludePath(llvm::StringRef path_to_file, llvm::StringRef pattern)
Returns the include path matching the given pattern for the given file path (or std::nullopt if the p...
static std::string MakePath(llvm::StringRef lhs, llvm::StringRef rhs)
Utility function for just appending two paths.
static llvm::SmallVector< std::string, 2 > getTargetIncludePaths(const llvm::Triple &triple)
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
bool m_first
True iff this path hasn't been set yet.
llvm::StringRef Get() const
Return the path if there is one.
bool TrySet(llvm::StringRef path)
Try setting the path.
bool Valid() const
Returns true iff this path was set exactly once so far.
bool analyzeFile(const FileSpec &f, const llvm::Triple &triple)
Analyze a given source file to build the current configuration.
SetOncePath m_c_inc
If valid, the include path to the C library (e.g. /usr/include).
std::string m_resource_inc
The Clang resource include path for this configuration.
bool hasValidConfig()
Returns true iff this is a valid configuration that can be used to load and compile modules.
std::vector< std::string > m_imported_modules
SetOncePath m_std_target_inc
If valid, the per-target include path used for the std module.
CppModuleConfiguration()=default
Creates an empty and invalid configuration.
SetOncePath m_std_inc
If valid, the include path used for the std module.
SetOncePath m_c_target_inc
If valid, the include path to target-specific C library files (e.g.
std::vector< std::string > m_include_dirs
const ConstString & GetDirectory() const
Directory string const get accessor.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static FileSystem & Instance()
A class that represents a running process on the host machine.
FileSpec GetClangResourceDir()