HeaderSearchOptions.h revision 0e2c34f92f00628d48968dfea096d36381f494cb
163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar//===--- HeaderSearchOptions.h ----------------------------------*- C++ -*-===// 263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar// 363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar// The LLVM Compiler Infrastructure 463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar// 563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar// This file is distributed under the University of Illinois Open Source 663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar// License. See LICENSE.TXT for details. 763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar// 863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar//===----------------------------------------------------------------------===// 963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 10c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor#ifndef LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H 11c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor#define LLVM_CLANG_LEX_HEADERSEARCHOPTIONS_H 1263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 139946fc735d7285f2195f89635370f534afd9877eDmitri Gribenko#include "clang/Basic/LLVM.h" 14c042edd54face617a3b9d0b4b9d5a3ff229d0f48Douglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h" 152a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor#include "llvm/ADT/SetVector.h" 1663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#include "llvm/ADT/StringRef.h" 172a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor#include <string> 18a61066310d4544d6343154eb3f4448fec0b15420Douglas Gregor#include <vector> 1963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 2063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarnamespace clang { 2163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 222cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbarnamespace frontend { 232cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar /// IncludeDirGroup - Identifiers the group a include entry belongs to, which 24809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett /// represents its relative positive in the search list. A \#include of a "" 2512ee102774c747874f0a6904089100667153b0c0Chris Lattner /// path starts at the -iquote group, then searches the Angled group, then 2612ee102774c747874f0a6904089100667153b0c0Chris Lattner /// searches the system group, etc. 272cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar enum IncludeDirGroup { 28809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett Quoted = 0, ///< '\#include ""' paths, added by 'gcc -iquote'. 29809d1be9820039b4cf6efa48246a0d70ffa13394James Dennett Angled, ///< Paths for '\#include <>' added by '-I'. 3065e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor IndexHeaderMap, ///< Like Angled, but marks header maps used when 3165e02fa80e1c185f18e5f81cefc30d75383a7301Douglas Gregor /// building frameworks. 322cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar System, ///< Like Angled, but marks system directories. 33ef84554239d77cc52a14b42f2bff8c2d02e7630eDaniel Dunbar ExternCSystem, ///< Like System, but headers are implicitly wrapped in 34ef84554239d77cc52a14b42f2bff8c2d02e7630eDaniel Dunbar /// extern "C". 3547adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer CSystem, ///< Like System, but only used for C. 362df6647847af283302834dadae5d9dcefa7e0ad4Joerg Sonnenberger CXXSystem, ///< Like System, but only used for C++. 3747adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer ObjCSystem, ///< Like System, but only used for ObjC. 3847adebef0df6dce752fe9a45e9190e8005b5d07cBenjamin Kramer ObjCXXSystem, ///< Like System, but only used for ObjC++. 392cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar After ///< Like System, but searched after the system directories. 402cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar }; 412cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar} 422cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar 4363c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar/// HeaderSearchOptions - Helper class for storing options related to the 4463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar/// initialization of the HeaderSearch object. 45cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenkoclass HeaderSearchOptions : public RefCountedBase<HeaderSearchOptions> { 4663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarpublic: 4763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar struct Entry { 4863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar std::string Path; 492cdafa8001ee69b75d2906cbb36f16cf8e1dc60aDaniel Dunbar frontend::IncludeDirGroup Group; 5063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar unsigned IsFramework : 1; 5123637beead1fce7dac755890c9482bcdce538b87Chris Lattner 525dd45f13dc4463f0c18b923fe6795ce55103301dBob Wilson /// IgnoreSysRoot - This is false if an absolute path should be treated 535dd45f13dc4463f0c18b923fe6795ce55103301dBob Wilson /// relative to the sysroot, or true if it should always be the absolute 5423637beead1fce7dac755890c9482bcdce538b87Chris Lattner /// path. 555dd45f13dc4463f0c18b923fe6795ce55103301dBob Wilson unsigned IgnoreSysRoot : 1; 5623637beead1fce7dac755890c9482bcdce538b87Chris Lattner 5759fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar Entry(StringRef path, frontend::IncludeDirGroup group, bool isFramework, 5859fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar bool ignoreSysRoot) 59eab6652b7e417c8e46b21c7d340f3a7d41492d6eDaniel Dunbar : Path(path), Group(group), IsFramework(isFramework), 6059fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar IgnoreSysRoot(ignoreSysRoot) {} 6163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar }; 6263c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 63f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith struct SystemHeaderPrefix { 642edbc98b046de22f3aba3c5142e85e7f3437fd03James Dennett /// A prefix to be matched against paths in \#include directives. 65f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith std::string Prefix; 66f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith 67f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith /// True if paths beginning with this prefix should be treated as system 68f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith /// headers. 69f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith bool IsSystemHeader; 70f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith 71f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith SystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) 72f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith : Prefix(Prefix), IsSystemHeader(IsSystemHeader) {} 73f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith }; 74f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith 7563c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar /// If non-empty, the directory to use as a "virtual system root" for include 7663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar /// paths. 7763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar std::string Sysroot; 7863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 7963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar /// User specified include entries. 8063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar std::vector<Entry> UserEntries; 8163c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 82f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith /// User-specified system header prefixes. 83f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith std::vector<SystemHeaderPrefix> SystemHeaderPrefixes; 84f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith 858b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar /// The directory which holds the compiler resource files (builtin includes, 868b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar /// etc.). 878b9adfea5e834eaee0f45d8cc7fb052d68df4a46Daniel Dunbar std::string ResourceDir; 8863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 899a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor /// \brief The directory used for the module cache. 909a6da6930644b4f2dbe4885b0eb4fc1274ff56a4Douglas Gregor std::string ModuleCachePath; 912a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor 92651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief The directory used for a user build. 93651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::string ModuleUserBuildPath; 94651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 956e975c4517958bcc11c834336d340797356058dbDouglas Gregor /// \brief Whether we should disable the use of the hash string within the 966e975c4517958bcc11c834336d340797356058dbDouglas Gregor /// module cache. 976e975c4517958bcc11c834336d340797356058dbDouglas Gregor /// 986e975c4517958bcc11c834336d340797356058dbDouglas Gregor /// Note: Only used for testing! 996e975c4517958bcc11c834336d340797356058dbDouglas Gregor unsigned DisableModuleHash : 1; 1002a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor 101056ec12ca14ee5014ea49786f719ceaa299a7e19Daniel Jasper /// \brief Interpret module maps. This option is implied by full modules. 102056ec12ca14ee5014ea49786f719ceaa299a7e19Daniel Jasper unsigned ModuleMaps : 1; 103056ec12ca14ee5014ea49786f719ceaa299a7e19Daniel Jasper 1040e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// \brief Set the 'home directory' of a module map file to the current 1050e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// working directory (or the home directory of the module map file that 1060e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// contained the 'extern module' directive importing this module map file 1070e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// if any) rather than the directory containing the module map file. 1080e2c34f92f00628d48968dfea096d36381f494cbStephen Hines // 1090e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// The home directory is where we look for files named in the module map 1100e2c34f92f00628d48968dfea096d36381f494cbStephen Hines /// file. 1110e2c34f92f00628d48968dfea096d36381f494cbStephen Hines unsigned ModuleMapFileHomeIsCwd : 1; 1120e2c34f92f00628d48968dfea096d36381f494cbStephen Hines 113d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// \brief The interval (in seconds) between pruning operations. 114d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// 115d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// This operation is expensive, because it requires Clang to walk through 116d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// the directory structure of the module cache, stat()'ing and removing 117d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// files. 118d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// 119d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// The default value is large, e.g., the operation runs once a week. 120d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor unsigned ModuleCachePruneInterval; 121d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor 122d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// \brief The time (in seconds) after which an unused module file will be 123d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// considered unused and will, therefore, be pruned. 124d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// 125d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// When the module cache is pruned, any module file that has not been 126d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// accessed in this many seconds will be removed. The default value is 127d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// large, e.g., a month, to avoid forcing infrequently-used modules to be 128d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor /// regenerated often. 129d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor unsigned ModuleCachePruneAfter; 130d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor 131651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief The time in seconds when the build session started. 132651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// 133651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// This time is used by other optimizations in header search and module 134651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// loading. 135651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines uint64_t BuildSessionTimestamp; 136651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1372a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor /// \brief The set of macro names that should be ignored for the purposes 1382a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor /// of computing the module hash. 1392a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor llvm::SetVector<std::string> ModulesIgnoreMacros; 1402a06085281d1b6aee628f85e8676eec04542cbc9Douglas Gregor 141651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief The set of user-provided virtual filesystem overlay files. 142651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines std::vector<std::string> VFSOverlayFiles; 143651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 1441e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar /// Include the compiler builtin includes. 1451e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar unsigned UseBuiltinIncludes : 1; 1461e69fe3a9f0a42b32a3000bda51677d51416564eDaniel Dunbar 14763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar /// Include the system standard include search directories. 148a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar unsigned UseStandardSystemIncludes : 1; 14963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 1504c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor /// Include the system standard C++ library include search directories. 1514c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor unsigned UseStandardCXXIncludes : 1; 1524c2bcad7b843c10fd4a2ffd43da40bfefb4dc8baDouglas Gregor 15313c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson /// Use libc++ instead of the default libstdc++. 15413c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson unsigned UseLibcxx : 1; 15513c4f2144b35bda21746eb60ad90e52a9bd8dcdaBob Wilson 15663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar /// Whether header search information should be output as for -v. 15763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar unsigned Verbose : 1; 15863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 159651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief If true, skip verifying input files used by modules if the 160651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// module was already verified during this build session (see 161651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \c BuildSessionTimestamp). 162651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned ModulesValidateOncePerBuildSession : 1; 163651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 164651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines /// \brief Whether to validate system input files when a module is loaded. 165651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines unsigned ModulesValidateSystemHeaders : 1; 166651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 16763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbarpublic: 168686775deca8b8685eb90801495880e3abdd844c2Chris Lattner HeaderSearchOptions(StringRef _Sysroot = "/") 169056ec12ca14ee5014ea49786f719ceaa299a7e19Daniel Jasper : Sysroot(_Sysroot), DisableModuleHash(0), ModuleMaps(0), 1700e2c34f92f00628d48968dfea096d36381f494cbStephen Hines ModuleMapFileHomeIsCwd(0), 171d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor ModuleCachePruneInterval(7*24*60*60), 172d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor ModuleCachePruneAfter(31*24*60*60), 173651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines BuildSessionTimestamp(0), 174d44d2872b2ebe58237de4dbc350b82cab944ccc5Douglas Gregor UseBuiltinIncludes(true), 175a268fc0f2229eb132ebc8501b140093aeb5516bfDaniel Dunbar UseStandardSystemIncludes(true), UseStandardCXXIncludes(true), 176651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines UseLibcxx(false), Verbose(false), 177651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ModulesValidateOncePerBuildSession(false), 178651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines ModulesValidateSystemHeaders(false) {} 17963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 1801824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// AddPath - Add the \p Path path to the specified \p Group list. 181686775deca8b8685eb90801495880e3abdd844c2Chris Lattner void AddPath(StringRef Path, frontend::IncludeDirGroup Group, 18259fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar bool IsFramework, bool IgnoreSysRoot) { 18359fd63581d6d572f23e82e81a50e0b940c8d1089Daniel Dunbar UserEntries.push_back(Entry(Path, Group, IsFramework, IgnoreSysRoot)); 18463c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar } 185f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith 1862edbc98b046de22f3aba3c5142e85e7f3437fd03James Dennett /// AddSystemHeaderPrefix - Override whether \#include directives naming a 1871824d54df85a462ada812dadda18130f951d40f3Dmitri Gribenko /// path starting with \p Prefix should be considered as naming a system 188f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith /// header. 189f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader) { 190f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith SystemHeaderPrefixes.push_back(SystemHeaderPrefix(Prefix, IsSystemHeader)); 191f122a138e39dbb29162abfa9a3d44091d8efa7afRichard Smith } 192651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 193651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines void AddVFSOverlayFile(StringRef Name) { 194651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines VFSOverlayFiles.push_back(Name); 195651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines } 19663c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar}; 19763c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 19863c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar} // end namespace clang 19963c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar 20063c8b77334f90472260d2f48df2742ed5067261eDaniel Dunbar#endif 201