diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2022-10-20 12:24:50 +0700 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2022-11-16 13:32:27 +0700 |
commit | 1f67dc8b7c225290d1b3eb93d90e2c9861aeefc0 (patch) | |
tree | f643b44b93e3fdb6ec8d9809e2ebeaea75cdf6be /llvm/lib/Support/CommandLine.cpp | |
parent | fde4ef19737e142fbe2fe2a3edd31963a254d3dd (diff) | |
download | llvm-1f67dc8b7c225290d1b3eb93d90e2c9861aeefc0.zip llvm-1f67dc8b7c225290d1b3eb93d90e2c9861aeefc0.tar.gz llvm-1f67dc8b7c225290d1b3eb93d90e2c9861aeefc0.tar.bz2 |
[Driver] Enable nested configuration files
Users may partition parameters specified by configuration file and put
different groups into separate files. These files are inserted into the
main file using constructs `@file`. Relative file names in it are
resolved relative to the including configuration file and this is not
convenient in some cases. A configuration file, which resides in system
directory, may need to include a file with user-defined parameters and
still provide default definitions if such file is absent.
To solve such problems, the option `--config=` is allowed inside
configuration files. Like `@file` it results in insertion of
command-line arguments but the algorithm of file search is different and
allows overriding system definitions with user ones.
Differential Revision: https://reviews.llvm.org/D136354
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index fbaacbb..abcfa7c 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -1191,27 +1191,44 @@ Error ExpansionContext::expandResponseFile( return Error::success(); StringRef BasePath = llvm::sys::path::parent_path(FName); - for (auto I = NewArgv.begin(), E = NewArgv.end(); I != E; ++I) { - const char *&Arg = *I; - if (Arg == nullptr) + for (const char *&Arg : NewArgv) { + if (!Arg) continue; // Substitute <CFGDIR> with the file's base path. if (InConfigFile) ExpandBasePaths(BasePath, Saver, Arg); - // Get expanded file name. - StringRef FileName(Arg); - if (!FileName.consume_front("@")) - continue; - if (!llvm::sys::path::is_relative(FileName)) + // Discover the case, when argument should be transformed into '@file' and + // evaluate 'file' for it. + StringRef ArgStr(Arg); + StringRef FileName; + bool ConfigInclusion = false; + if (ArgStr.consume_front("@")) { + FileName = ArgStr; + if (!llvm::sys::path::is_relative(FileName)) + continue; + } else if (ArgStr.consume_front("--config=")) { + FileName = ArgStr; + ConfigInclusion = true; + } else { continue; + } // Update expansion construct. SmallString<128> ResponseFile; ResponseFile.push_back('@'); - ResponseFile.append(BasePath); - llvm::sys::path::append(ResponseFile, FileName); + if (ConfigInclusion && !llvm::sys::path::has_parent_path(FileName)) { + SmallString<128> FilePath; + if (!findConfigFile(FileName, FilePath)) + return createStringError( + std::make_error_code(std::errc::no_such_file_or_directory), + "cannot not find configuration file: " + FileName); + ResponseFile.append(FilePath); + } else { + ResponseFile.append(BasePath); + llvm::sys::path::append(ResponseFile, FileName); + } Arg = Saver.save(ResponseFile.str()).data(); } return Error::success(); |