diff options
author | Diana Picus <diana.picus@linaro.org> | 2022-05-03 12:44:35 +0300 |
---|---|---|
committer | Diana Picus <diana.picus@linaro.org> | 2022-05-18 11:25:45 +0300 |
commit | 1c0b03f6e706978f2e87408f7fd5e4c846d6c9a8 (patch) | |
tree | c95c3f4b5bcc99a877f571e3bd5bb8b0b82f4ea3 /flang | |
parent | 00999fb6e14231de14db292510c854e1bf3baded (diff) |
[flang][driver] Support parsing response files
Add support for reading response files in the flang driver. Response
files contain command line arguments and are used whenever a command
becomes longer than the shell/environment limit. Response files are
recognized via the special "@path/to/response/file.rsp" syntax, which
distinguishes them from other file inputs.
This patch hardcodes GNU tokenization, since we don't have a CL mode for
the driver. In the future we might want to add a --rsp-quoting command
line option, like clang has, to accommodate Windows platforms.
Differential Revision: https://reviews.llvm.org/D124846
Diffstat (limited to 'flang')
-rw-r--r-- | flang/test/Driver/response-file.f90 | 17 | ||||
-rw-r--r-- | flang/tools/flang-driver/driver.cpp | 12 |
2 files changed, 29 insertions, 0 deletions
diff --git a/flang/test/Driver/response-file.f90 b/flang/test/Driver/response-file.f90 new file mode 100644 index 000000000000..b2670528d3e9 --- /dev/null +++ b/flang/test/Driver/response-file.f90 @@ -0,0 +1,17 @@ +! Test that the driver can process response files. + +! RUN: echo "-DTEST" > %basename_t.rsp +! RUN: %flang -E -cpp @%basename_t.rsp %s -o - | FileCheck %s +! RUN: %flang_fc1 -E -cpp @%basename_t.rsp %s -o - | FileCheck %s +! RUN: not %flang %basename_t.rsp %s -o /dev/null +! RUN: not %flang_fc1 %basenamt_t.rsp %s -o /dev/null + +! CHECK-LABEL: program test +! CHECK: end program + +#ifdef TEST +program test +end program +#else +We should have read the define from the response file. +#endif diff --git a/flang/tools/flang-driver/driver.cpp b/flang/tools/flang-driver/driver.cpp index 1614ff14a1f1..1fee09d1df85 100644 --- a/flang/tools/flang-driver/driver.cpp +++ b/flang/tools/flang-driver/driver.cpp @@ -25,6 +25,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/Option/ArgList.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Host.h" #include "llvm/Support/InitLLVM.h" #include "llvm/Support/VirtualFileSystem.h" @@ -71,6 +72,13 @@ static int executeFC1Tool(llvm::SmallVectorImpl<const char *> &argV) { return 1; } +static void ExpandResponseFiles( + llvm::StringSaver &saver, llvm::SmallVectorImpl<const char *> &args) { + // We're defaulting to the GNU syntax, since we don't have a CL mode. + llvm::cl::TokenizerCallback tokenizer = &llvm::cl::TokenizeGNUCommandLine; + llvm::cl::ExpandResponseFiles(saver, tokenizer, args, /* MarkEOLs=*/false); +} + int main(int argc, const char **argv) { // Initialize variables to call the driver @@ -80,6 +88,10 @@ int main(int argc, const char **argv) { clang::driver::ParsedClangName targetandMode("flang", "--driver-mode=flang"); std::string driverPath = getExecutablePath(args[0]); + llvm::BumpPtrAllocator a; + llvm::StringSaver saver(a); + ExpandResponseFiles(saver, args); + // Check if flang-new is in the frontend mode auto firstArg = std::find_if( args.begin() + 1, args.end(), [](const char *a) { return a != nullptr; }); |