| 1 | //===- HeaderSearchOptions.h ------------------------------------*- C++ -*-===// |
|---|---|
| 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 | #ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H |
| 10 | #define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H |
| 11 | |
| 12 | #include "clang/Basic/LLVM.h" |
| 13 | #include "llvm/ADT/CachedHashString.h" |
| 14 | #include "llvm/ADT/SetVector.h" |
| 15 | #include "llvm/ADT/StringRef.h" |
| 16 | #include <cstdint> |
| 17 | #include <string> |
| 18 | #include <vector> |
| 19 | #include <map> |
| 20 | |
| 21 | namespace clang { |
| 22 | |
| 23 | namespace frontend { |
| 24 | |
| 25 | /// IncludeDirGroup - Identifies the group an include Entry belongs to, |
| 26 | /// representing its relative positive in the search list. |
| 27 | /// \#include directives whose paths are enclosed by string quotes ("") |
| 28 | /// start searching at the Quoted group (specified by '-iquote'), |
| 29 | /// then search the Angled group, then the System group, etc. |
| 30 | enum IncludeDirGroup { |
| 31 | /// '\#include ""' paths, added by 'gcc -iquote'. |
| 32 | Quoted = 0, |
| 33 | |
| 34 | /// Paths for '\#include <>' added by '-I'. |
| 35 | Angled, |
| 36 | |
| 37 | /// Like Angled, but marks header maps used when building frameworks. |
| 38 | IndexHeaderMap, |
| 39 | |
| 40 | /// Like Angled, but marks system directories. |
| 41 | System, |
| 42 | |
| 43 | /// Like System, but headers are implicitly wrapped in extern "C". |
| 44 | ExternCSystem, |
| 45 | |
| 46 | /// Like System, but only used for C. |
| 47 | CSystem, |
| 48 | |
| 49 | /// Like System, but only used for C++. |
| 50 | CXXSystem, |
| 51 | |
| 52 | /// Like System, but only used for ObjC. |
| 53 | ObjCSystem, |
| 54 | |
| 55 | /// Like System, but only used for ObjC++. |
| 56 | ObjCXXSystem, |
| 57 | |
| 58 | /// Like System, but searched after the system directories. |
| 59 | After |
| 60 | }; |
| 61 | |
| 62 | } // namespace frontend |
| 63 | |
| 64 | /// HeaderSearchOptions - Helper class for storing options related to the |
| 65 | /// initialization of the HeaderSearch object. |
| 66 | class HeaderSearchOptions { |
| 67 | public: |
| 68 | struct Entry { |
| 69 | std::string Path; |
| 70 | frontend::IncludeDirGroup Group; |
| 71 | unsigned IsFramework : 1; |
| 72 | |
| 73 | /// IgnoreSysRoot - This is false if an absolute path should be treated |
| 74 | /// relative to the sysroot, or true if it should always be the absolute |
| 75 | /// path. |
| 76 | unsigned IgnoreSysRoot : 1; |
| 77 | |
| 78 | Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework, |
| 79 | bool ignoreSysRoot) |
| 80 | : Path(path), Group(group), IsFramework(isFramework), |
| 81 | IgnoreSysRoot(ignoreSysRoot) {} |
| 82 | }; |
| 83 | |
| 84 | struct SystemHeaderPrefix { |
| 85 | /// A prefix to be matched against paths in \#include directives. |
| 86 | std::string Prefix; |
| 87 | |
| 88 | /// True if paths beginning with this prefix should be treated as system |
| 89 | /// headers. |
| 90 | bool IsSystemHeader; |
| 91 | |
| 92 | SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) |
| 93 | : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {} |
| 94 | }; |
| 95 | |
| 96 | /// If non-empty, the directory to use as a "virtual system root" for include |
| 97 | /// paths. |
| 98 | std::string Sysroot; |
| 99 | |
| 100 | /// User specified include entries. |
| 101 | std::vector<Entry> UserEntries; |
| 102 | |
| 103 | /// User-specified system header prefixes. |
| 104 | std::vector<SystemHeaderPrefix> SystemHeaderPrefixes; |
| 105 | |
| 106 | /// The directory which holds the compiler resource files (builtin includes, |
| 107 | /// etc.). |
| 108 | std::string ResourceDir; |
| 109 | |
| 110 | /// The directory used for the module cache. |
| 111 | std::string ModuleCachePath; |
| 112 | |
| 113 | /// The directory used for a user build. |
| 114 | std::string ModuleUserBuildPath; |
| 115 | |
| 116 | /// The mapping of module names to prebuilt module files. |
| 117 | std::map<std::string, std::string> PrebuiltModuleFiles; |
| 118 | |
| 119 | /// The directories used to load prebuilt module files. |
| 120 | std::vector<std::string> PrebuiltModulePaths; |
| 121 | |
| 122 | /// The module/pch container format. |
| 123 | std::string ModuleFormat; |
| 124 | |
| 125 | /// Whether we should disable the use of the hash string within the |
| 126 | /// module cache. |
| 127 | /// |
| 128 | /// Note: Only used for testing! |
| 129 | unsigned DisableModuleHash : 1; |
| 130 | |
| 131 | /// Implicit module maps. This option is enabld by default when |
| 132 | /// modules is enabled. |
| 133 | unsigned ImplicitModuleMaps : 1; |
| 134 | |
| 135 | /// Set the 'home directory' of a module map file to the current |
| 136 | /// working directory (or the home directory of the module map file that |
| 137 | /// contained the 'extern module' directive importing this module map file |
| 138 | /// if any) rather than the directory containing the module map file. |
| 139 | // |
| 140 | /// The home directory is where we look for files named in the module map |
| 141 | /// file. |
| 142 | unsigned ModuleMapFileHomeIsCwd : 1; |
| 143 | |
| 144 | /// The interval (in seconds) between pruning operations. |
| 145 | /// |
| 146 | /// This operation is expensive, because it requires Clang to walk through |
| 147 | /// the directory structure of the module cache, stat()'ing and removing |
| 148 | /// files. |
| 149 | /// |
| 150 | /// The default value is large, e.g., the operation runs once a week. |
| 151 | unsigned ModuleCachePruneInterval = 7 * 24 * 60 * 60; |
| 152 | |
| 153 | /// The time (in seconds) after which an unused module file will be |
| 154 | /// considered unused and will, therefore, be pruned. |
| 155 | /// |
| 156 | /// When the module cache is pruned, any module file that has not been |
| 157 | /// accessed in this many seconds will be removed. The default value is |
| 158 | /// large, e.g., a month, to avoid forcing infrequently-used modules to be |
| 159 | /// regenerated often. |
| 160 | unsigned ModuleCachePruneAfter = 31 * 24 * 60 * 60; |
| 161 | |
| 162 | /// The time in seconds when the build session started. |
| 163 | /// |
| 164 | /// This time is used by other optimizations in header search and module |
| 165 | /// loading. |
| 166 | uint64_t BuildSessionTimestamp = 0; |
| 167 | |
| 168 | /// The set of macro names that should be ignored for the purposes |
| 169 | /// of computing the module hash. |
| 170 | llvm::SmallSetVector<llvm::CachedHashString, 16> ModulesIgnoreMacros; |
| 171 | |
| 172 | /// The set of user-provided virtual filesystem overlay files. |
| 173 | std::vector<std::string> VFSOverlayFiles; |
| 174 | |
| 175 | /// Include the compiler builtin includes. |
| 176 | unsigned UseBuiltinIncludes : 1; |
| 177 | |
| 178 | /// Include the system standard include search directories. |
| 179 | unsigned UseStandardSystemIncludes : 1; |
| 180 | |
| 181 | /// Include the system standard C++ library include search directories. |
| 182 | unsigned UseStandardCXXIncludes : 1; |
| 183 | |
| 184 | /// Use libc++ instead of the default libstdc++. |
| 185 | unsigned UseLibcxx : 1; |
| 186 | |
| 187 | /// Whether header search information should be output as for -v. |
| 188 | unsigned Verbose : 1; |
| 189 | |
| 190 | /// If true, skip verifying input files used by modules if the |
| 191 | /// module was already verified during this build session (see |
| 192 | /// \c BuildSessionTimestamp). |
| 193 | unsigned ModulesValidateOncePerBuildSession : 1; |
| 194 | |
| 195 | /// Whether to validate system input files when a module is loaded. |
| 196 | unsigned ModulesValidateSystemHeaders : 1; |
| 197 | |
| 198 | /// Whether the module includes debug information (-gmodules). |
| 199 | unsigned UseDebugInfo : 1; |
| 200 | |
| 201 | unsigned ModulesValidateDiagnosticOptions : 1; |
| 202 | |
| 203 | unsigned ModulesHashContent : 1; |
| 204 | |
| 205 | HeaderSearchOptions(StringRef _Sysroot = "/") |
| 206 | : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(false), |
| 207 | ImplicitModuleMaps(false), ModuleMapFileHomeIsCwd(false), |
| 208 | UseBuiltinIncludes(true), UseStandardSystemIncludes(true), |
| 209 | UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false), |
| 210 | ModulesValidateOncePerBuildSession(false), |
| 211 | ModulesValidateSystemHeaders(false), UseDebugInfo(false), |
| 212 | ModulesValidateDiagnosticOptions(true), ModulesHashContent(false) {} |
| 213 | |
| 214 | /// AddPath - Add the \p Path path to the specified \p Group list. |
| 215 | void AddPath(StringRef Path, frontend::IncludeDirGroup Group, |
| 216 | bool IsFramework, bool IgnoreSysRoot) { |
| 217 | UserEntries.emplace_back(Path, Group, IsFramework, IgnoreSysRoot); |
| 218 | } |
| 219 | |
| 220 | /// AddSystemHeaderPrefix - Override whether \#include directives naming a |
| 221 | /// path starting with \p Prefix should be considered as naming a system |
| 222 | /// header. |
| 223 | void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) { |
| 224 | SystemHeaderPrefixes.emplace_back(Prefix, IsSystemHeader); |
| 225 | } |
| 226 | |
| 227 | void AddVFSOverlayFile(StringRef Name) { |
| 228 | VFSOverlayFiles.push_back(Name); |
| 229 | } |
| 230 | |
| 231 | void AddPrebuiltModulePath(StringRef Name) { |
| 232 | PrebuiltModulePaths.push_back(Name); |
| 233 | } |
| 234 | }; |
| 235 | |
| 236 | } // namespace clang |
| 237 | |
| 238 | #endif // LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H |
| 239 |