1616#include " llvm/ADT/StringRef.h"
1717#include " llvm/ADT/iterator.h"
1818#include " llvm/Option/Option.h"
19+ #include " llvm/Support/Program.h"
1920#include < memory>
2021#include < string>
2122#include < utility>
@@ -36,6 +37,69 @@ struct CrashReportInfo {
3637 : Filename(Filename), VFSPath(VFSPath) {}
3738};
3839
40+ // Encodes the kind of response file supported for a command invocation.
41+ // Response files are necessary if the command line gets too large, requiring
42+ // the arguments to be transferred to a file.
43+ struct ResponseFileSupport {
44+ enum ResponseFileKind {
45+ // Provides full support for response files, which means we can transfer
46+ // all tool input arguments to a file.
47+ RF_Full,
48+ // Input file names can live in a file, but flags can't. This is a special
49+ // case for old versions of Apple's ld64.
50+ RF_FileList,
51+ // Does not support response files: all arguments must be passed via
52+ // command line.
53+ RF_None
54+ };
55+ // / The level of support for response files.
56+ ResponseFileKind ResponseKind;
57+
58+ // / The encoding to use when writing response files on Windows. Ignored on
59+ // / other host OSes.
60+ // /
61+ // / Windows use cases: - GCC and Binutils on mingw only accept ANSI response
62+ // / files encoded with the system current code page.
63+ // / - MSVC's CL.exe and LINK.exe accept UTF16 on Windows.
64+ // / - Clang accepts both UTF8 and UTF16.
65+ // /
66+ // / FIXME: When GNU tools learn how to parse UTF16 on Windows, we should
67+ // / always use UTF16 for Windows, which is the Windows official encoding for
68+ // / international characters.
69+ llvm::sys::WindowsEncodingMethod ResponseEncoding;
70+
71+ // / What prefix to use for the command-line argument when passing a response
72+ // / file.
73+ const char *ResponseFlag;
74+
75+ // / Returns a ResponseFileSupport indicating that response files are not
76+ // / supported.
77+ static constexpr ResponseFileSupport None () {
78+ return {RF_None, llvm::sys::WEM_UTF8, nullptr };
79+ }
80+
81+ // / Returns a ResponseFileSupport indicating that response files are
82+ // / supported, using the @file syntax. On windows, the file is written in the
83+ // / UTF8 encoding. On other OSes, no re-encoding occurs.
84+ static constexpr ResponseFileSupport AtFileUTF8 () {
85+ return {RF_Full, llvm::sys::WEM_UTF8, " @" };
86+ }
87+
88+ // / Returns a ResponseFileSupport indicating that response files are
89+ // / supported, using the @file syntax. On windows, the file is written in the
90+ // / current ANSI code-page encoding. On other OSes, no re-encoding occurs.
91+ static constexpr ResponseFileSupport AtFileCurCP () {
92+ return {RF_Full, llvm::sys::WEM_CurrentCodePage, " @" };
93+ }
94+
95+ // / Returns a ResponseFileSupport indicating that response files are
96+ // / supported, using the @file syntax. On windows, the file is written in the
97+ // / UTF-16 encoding. On other OSes, no re-encoding occurs.
98+ static constexpr ResponseFileSupport AtFileUTF16 () {
99+ return {RF_Full, llvm::sys::WEM_UTF16, " @" };
100+ }
101+ };
102+
39103// / Command - An executable path/name and argument vector to
40104// / execute.
41105class Command {
@@ -45,6 +109,9 @@ class Command {
45109 // / Tool - The tool which caused the creation of this job.
46110 const Tool &Creator;
47111
112+ // / Whether and how to generate response files if the arguments are too long.
113+ ResponseFileSupport ResponseSupport;
114+
48115 // / The executable to run.
49116 const char *Executable;
50117
@@ -89,7 +156,8 @@ class Command {
89156 // / Whether the command will be executed in this process or not.
90157 bool InProcess = false ;
91158
92- Command (const Action &Source, const Tool &Creator, const char *Executable,
159+ Command (const Action &Source, const Tool &Creator,
160+ ResponseFileSupport ResponseSupport, const char *Executable,
93161 const llvm::opt::ArgStringList &Arguments,
94162 ArrayRef<InputInfo> Inputs);
95163 // FIXME: This really shouldn't be copyable, but is currently copied in some
@@ -109,11 +177,16 @@ class Command {
109177 // / getCreator - Return the Tool which caused the creation of this job.
110178 const Tool &getCreator () const { return Creator; }
111179
180+ // / Returns the kind of response file supported by the current invocation.
181+ const ResponseFileSupport &getResponseFileSupport () {
182+ return ResponseSupport;
183+ }
184+
112185 // / Set to pass arguments via a response file when launching the command
113186 void setResponseFile (const char *FileName);
114187
115- // / Set an input file list, necessary if we need to use a response file but
116- // / the tool being called only supports input files lists .
188+ // / Set an input file list, necessary if you specified an RF_FileList response
189+ // / file support .
117190 void setInputFileList (llvm::opt::ArgStringList List) {
118191 InputFileList = std::move (List);
119192 }
@@ -136,7 +209,8 @@ class Command {
136209// / Use the CC1 tool callback when available, to avoid creating a new process
137210class CC1Command : public Command {
138211public:
139- CC1Command (const Action &Source, const Tool &Creator, const char *Executable,
212+ CC1Command (const Action &Source, const Tool &Creator,
213+ ResponseFileSupport ResponseSupport, const char *Executable,
140214 const llvm::opt::ArgStringList &Arguments,
141215 ArrayRef<InputInfo> Inputs);
142216
@@ -154,7 +228,7 @@ class CC1Command : public Command {
154228class FallbackCommand : public Command {
155229public:
156230 FallbackCommand (const Action &Source_, const Tool &Creator_,
157- const char *Executable_,
231+ ResponseFileSupport ResponseSupport, const char *Executable_,
158232 const llvm::opt::ArgStringList &Arguments_,
159233 ArrayRef<InputInfo> Inputs,
160234 std::unique_ptr<Command> Fallback_);
@@ -173,6 +247,7 @@ class FallbackCommand : public Command {
173247class ForceSuccessCommand : public Command {
174248public:
175249 ForceSuccessCommand (const Action &Source_, const Tool &Creator_,
250+ ResponseFileSupport ResponseSupport,
176251 const char *Executable_,
177252 const llvm::opt::ArgStringList &Arguments_,
178253 ArrayRef<InputInfo> Inputs);
0 commit comments