diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-08-20 09:24:07 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-08-20 09:24:07 +0000 |
commit | a17a413cc1b671fa55b8dbbcbb67125bebbf0080 (patch) | |
tree | 2b99c7162c9a39aad925a0726f71b1efb7c41bf5 /llvm/tools | |
parent | 6ad57b2491ef58babb1afcfd196dbe71fb663858 (diff) | |
download | bcm5719-llvm-a17a413cc1b671fa55b8dbbcbb67125bebbf0080.tar.gz bcm5719-llvm-a17a413cc1b671fa55b8dbbcbb67125bebbf0080.zip |
Implement the correct search for configuration files. llvmc will now try
the following in this order:
1. -config-dir=/path/to/configs
2. LLVM_CONFIG_DIR=/path/to/configs
3. ~/.llvm/etc
4. $prefix/etc
5. /etc/llvm
llvm-svn: 15950
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/llvmc/Configuration.cpp | 58 |
1 files changed, 42 insertions, 16 deletions
diff --git a/llvm/tools/llvmc/Configuration.cpp b/llvm/tools/llvmc/Configuration.cpp index 1463ecaa7ee..1e0e681c921 100644 --- a/llvm/tools/llvmc/Configuration.cpp +++ b/llvm/tools/llvmc/Configuration.cpp @@ -15,6 +15,7 @@ #include "Configuration.h" #include "ConfigLexer.h" #include "CompilerDriver.h" +#include "Config/config.h" #include "Support/CommandLine.h" #include "Support/StringExtras.h" #include <iostream> @@ -22,6 +23,11 @@ using namespace llvm; +namespace sys { + // From CompilerDriver.cpp (for now) + extern bool FileReadable(const std::string& fname); +} + namespace llvm { ConfigLexerInfo ConfigLexerState; InputProvider* ConfigLexerInput = 0; @@ -389,27 +395,47 @@ namespace { CompilerDriver::ConfigData* LLVMC_ConfigDataProvider::ReadConfigData(const std::string& ftype) { CompilerDriver::ConfigData* result = 0; + std::string dir_name; if (configDir.empty()) { - FileInputProvider fip( std::string("/etc/llvm/") + ftype ); - if (!fip.okay()) { - fip.error("Configuration for '" + ftype + "' is not available."); - fip.checkErrors(); - } - else { - result = new CompilerDriver::ConfigData(); - ParseConfigData(fip,*result); + // Try the environment variable + const char* conf = getenv("LLVM_CONFIG_DIR"); + if (conf) { + dir_name = conf; + dir_name += "/"; + if (!::sys::FileReadable(dir_name + ftype)) + throw "Configuration file for '" + ftype + "' is not available."; + } else { + // Try the user's home directory + const char* home = getenv("HOME"); + if (home) { + dir_name = home; + dir_name += "/.llvm/etc/"; + if (!::sys::FileReadable(dir_name + ftype)) { + // Okay, try the LLVM installation directory + dir_name = LLVM_ETCDIR; + dir_name += "/"; + if (!::sys::FileReadable(dir_name + ftype)) { + // Okay, try the "standard" place + dir_name = "/etc/llvm/"; + if (!::sys::FileReadable(dir_name + ftype)) { + throw "Configuration file for '" + ftype + "' is not available."; + } + } + } + } } } else { - FileInputProvider fip( configDir + "/" + ftype ); - if (!fip.okay()) { - fip.error("Configuration for '" + ftype + "' is not available."); - fip.checkErrors(); - } - else { - result = new CompilerDriver::ConfigData(); - ParseConfigData(fip,*result); + dir_name = configDir + "/"; + if (!::sys::FileReadable(dir_name + ftype)) { + throw "Configuration file for '" + ftype + "' is not available."; } } + FileInputProvider fip( dir_name + ftype ); + if (!fip.okay()) { + throw "Configuration file for '" + ftype + "' is not available."; + } + result = new CompilerDriver::ConfigData(); + ParseConfigData(fip,*result); return result; } |