@@ -115,8 +115,8 @@ static bool RoundTripArgs = DoRoundTripDefault;
115
115
static void ParseArgs (int argc, char **argv) {
116
116
ScanDepsOptTable Tbl;
117
117
llvm::StringRef ToolName = argv[0 ];
118
- llvm::BumpPtrAllocator A ;
119
- llvm::StringSaver Saver{A };
118
+ llvm::BumpPtrAllocator Alloc ;
119
+ llvm::StringSaver Saver{Alloc };
120
120
llvm::opt::InputArgList Args =
121
121
Tbl.parseArgs (argc, argv, OPT_UNKNOWN, Saver, [&](StringRef Msg) {
122
122
llvm::errs () << Msg << ' \n ' ;
@@ -207,14 +207,8 @@ static void ParseArgs(int argc, char **argv) {
207
207
}
208
208
}
209
209
210
- if (const llvm::opt::Arg *A = Args.getLastArg (OPT_compilation_database_EQ)) {
210
+ if (const llvm::opt::Arg *A = Args.getLastArg (OPT_compilation_database_EQ))
211
211
CompilationDB = A->getValue ();
212
- } else if (Format != ScanningOutputFormat::P1689) {
213
- llvm::errs () << ToolName
214
- << " : for the --compiilation-database option: must be "
215
- " specified at least once!" ;
216
- std::exit (1 );
217
- }
218
212
219
213
if (const llvm::opt::Arg *A = Args.getLastArg (OPT_module_name_EQ))
220
214
ModuleName = A->getValue ();
@@ -265,9 +259,8 @@ static void ParseArgs(int argc, char **argv) {
265
259
266
260
RoundTripArgs = Args.hasArg (OPT_round_trip_args);
267
261
268
- if (auto *A = Args.getLastArgNoClaim (OPT_DASH_DASH))
269
- CommandLine.insert (CommandLine.end (), A->getValues ().begin (),
270
- A->getValues ().end ());
262
+ if (const llvm::opt::Arg *A = Args.getLastArgNoClaim (OPT_DASH_DASH))
263
+ CommandLine.assign (A->getValues ().begin (), A->getValues ().end ());
271
264
}
272
265
273
266
class SharedStream {
@@ -975,39 +968,29 @@ static std::string getModuleCachePath(ArrayRef<std::string> Args) {
975
968
return std::string (Path);
976
969
}
977
970
978
- // getCompilationDataBase - If -compilation-database is set, load the
979
- // compilation database from the specified file. Otherwise if the we're
980
- // generating P1689 format, trying to generate the compilation database
981
- // form specified command line after the positional parameter "--".
971
+ // / Attempts to construct the compilation database from '-compilation-database'
972
+ // / or from the arguments following the positional '--'.
982
973
static std::unique_ptr<tooling::CompilationDatabase>
983
- getCompilationDataBase (int argc, char **argv, std::string &ErrorMessage) {
974
+ getCompilationDatabase (int argc, char **argv, std::string &ErrorMessage) {
984
975
llvm::InitLLVM X (argc, argv);
985
976
ParseArgs (argc, argv);
986
977
978
+ if (!(CommandLine.empty () ^ CompilationDB.empty ())) {
979
+ llvm::errs () << " The compilation command line must be provided either via "
980
+ " '-compilation-database' or after '--'." ;
981
+ return nullptr ;
982
+ }
983
+
987
984
if (!CompilationDB.empty ())
988
985
return tooling::JSONCompilationDatabase::loadFromFile (
989
986
CompilationDB, ErrorMessage,
990
987
tooling::JSONCommandLineSyntax::AutoDetect);
991
988
992
- if (Format != ScanningOutputFormat::P1689) {
993
- llvm::errs () << " the --compilation-database option: must be specified at "
994
- " least once!" ;
995
- return nullptr ;
996
- }
997
-
998
- // Trying to get the input file, the output file and the command line options
999
- // from the positional parameter "--".
1000
- char **DoubleDash = std::find (argv, argv + argc, StringRef (" --" ));
1001
- if (DoubleDash == argv + argc) {
1002
- llvm::errs () << " The command line arguments is required after '--' in "
1003
- " P1689 per file mode." ;
1004
- return nullptr ;
1005
- }
1006
-
1007
989
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
1008
990
CompilerInstance::createDiagnostics (new DiagnosticOptions);
1009
991
driver::Driver TheDriver (CommandLine[0 ], llvm::sys::getDefaultTargetTriple (),
1010
992
*Diags);
993
+ TheDriver.setCheckInputsExist (false );
1011
994
std::unique_ptr<driver::Compilation> C (
1012
995
TheDriver.BuildCompilation (CommandLine));
1013
996
if (!C)
@@ -1022,7 +1005,8 @@ getCompilationDataBase(int argc, char **argv, std::string &ErrorMessage) {
1022
1005
1023
1006
FrontendOptions &FEOpts = CI->getFrontendOpts ();
1024
1007
if (FEOpts.Inputs .size () != 1 ) {
1025
- llvm::errs () << " Only one input file is allowed in P1689 per file mode." ;
1008
+ llvm::errs ()
1009
+ << " Exactly one input file is required in the per-file mode ('--').\n " ;
1026
1010
return nullptr ;
1027
1011
}
1028
1012
@@ -1031,8 +1015,9 @@ getCompilationDataBase(int argc, char **argv, std::string &ErrorMessage) {
1031
1015
auto LastCmd = C->getJobs ().end ();
1032
1016
LastCmd--;
1033
1017
if (LastCmd->getOutputFilenames ().size () != 1 ) {
1034
- llvm::errs () << " The command line should provide exactly one output file "
1035
- " in P1689 per file mode.\n " ;
1018
+ llvm::errs ()
1019
+ << " Exactly one output file is required in the per-file mode ('--').\n " ;
1020
+ return nullptr ;
1036
1021
}
1037
1022
StringRef OutputFile = LastCmd->getOutputFilenames ().front ();
1038
1023
@@ -1072,7 +1057,7 @@ getCompilationDataBase(int argc, char **argv, std::string &ErrorMessage) {
1072
1057
int clang_scan_deps_main (int argc, char **argv, const llvm::ToolContext &) {
1073
1058
std::string ErrorMessage;
1074
1059
std::unique_ptr<tooling::CompilationDatabase> Compilations =
1075
- getCompilationDataBase (argc, argv, ErrorMessage);
1060
+ getCompilationDatabase (argc, argv, ErrorMessage);
1076
1061
if (!Compilations) {
1077
1062
llvm::errs () << ErrorMessage << " \n " ;
1078
1063
return 1 ;
0 commit comments