@@ -98,8 +98,8 @@ static bool RoundTripArgs = DoRoundTripDefault;
98
98
static void ParseArgs (int argc, char **argv) {
99
99
ScanDepsOptTable Tbl;
100
100
llvm::StringRef ToolName = argv[0 ];
101
- llvm::BumpPtrAllocator A ;
102
- llvm::StringSaver Saver{A };
101
+ llvm::BumpPtrAllocator Alloc ;
102
+ llvm::StringSaver Saver{Alloc };
103
103
llvm::opt::InputArgList Args =
104
104
Tbl.parseArgs (argc, argv, OPT_UNKNOWN, Saver, [&](StringRef Msg) {
105
105
llvm::errs () << Msg << ' \n ' ;
@@ -186,14 +186,8 @@ static void ParseArgs(int argc, char **argv) {
186
186
}
187
187
}
188
188
189
- if (const llvm::opt::Arg *A = Args.getLastArg (OPT_compilation_database_EQ)) {
189
+ if (const llvm::opt::Arg *A = Args.getLastArg (OPT_compilation_database_EQ))
190
190
CompilationDB = A->getValue ();
191
- } else if (Format != ScanningOutputFormat::P1689) {
192
- llvm::errs () << ToolName
193
- << " : for the --compiilation-database option: must be "
194
- " specified at least once!" ;
195
- std::exit (1 );
196
- }
197
191
198
192
if (const llvm::opt::Arg *A = Args.getLastArg (OPT_module_name_EQ))
199
193
ModuleName = A->getValue ();
@@ -225,9 +219,8 @@ static void ParseArgs(int argc, char **argv) {
225
219
226
220
RoundTripArgs = Args.hasArg (OPT_round_trip_args);
227
221
228
- if (auto *A = Args.getLastArgNoClaim (OPT_DASH_DASH))
229
- CommandLine.insert (CommandLine.end (), A->getValues ().begin (),
230
- A->getValues ().end ());
222
+ if (const llvm::opt::Arg *A = Args.getLastArgNoClaim (OPT_DASH_DASH))
223
+ CommandLine.assign (A->getValues ().begin (), A->getValues ().end ());
231
224
}
232
225
233
226
class SharedStream {
@@ -694,38 +687,28 @@ static std::string getModuleCachePath(ArrayRef<std::string> Args) {
694
687
return std::string (Path);
695
688
}
696
689
697
- // getCompilationDataBase - If -compilation-database is set, load the
698
- // compilation database from the specified file. Otherwise if the we're
699
- // generating P1689 format, trying to generate the compilation database
700
- // form specified command line after the positional parameter "--".
690
+ // / Attempts to construct the compilation database from '-compilation-database'
691
+ // / or from the arguments following the positional '--'.
701
692
static std::unique_ptr<tooling::CompilationDatabase>
702
- getCompilationDataBase (int argc, char **argv, std::string &ErrorMessage) {
693
+ getCompilationDatabase (int argc, char **argv, std::string &ErrorMessage) {
703
694
ParseArgs (argc, argv);
704
695
696
+ if (!(CommandLine.empty () ^ CompilationDB.empty ())) {
697
+ llvm::errs () << " The compilation command line must be provided either via "
698
+ " '-compilation-database' or after '--'." ;
699
+ return nullptr ;
700
+ }
701
+
705
702
if (!CompilationDB.empty ())
706
703
return tooling::JSONCompilationDatabase::loadFromFile (
707
704
CompilationDB, ErrorMessage,
708
705
tooling::JSONCommandLineSyntax::AutoDetect);
709
706
710
- if (Format != ScanningOutputFormat::P1689) {
711
- llvm::errs () << " the --compilation-database option: must be specified at "
712
- " least once!" ;
713
- return nullptr ;
714
- }
715
-
716
- // Trying to get the input file, the output file and the command line options
717
- // from the positional parameter "--".
718
- char **DoubleDash = std::find (argv, argv + argc, StringRef (" --" ));
719
- if (DoubleDash == argv + argc) {
720
- llvm::errs () << " The command line arguments is required after '--' in "
721
- " P1689 per file mode." ;
722
- return nullptr ;
723
- }
724
-
725
707
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
726
708
CompilerInstance::createDiagnostics (new DiagnosticOptions);
727
709
driver::Driver TheDriver (CommandLine[0 ], llvm::sys::getDefaultTargetTriple (),
728
710
*Diags);
711
+ TheDriver.setCheckInputsExist (false );
729
712
std::unique_ptr<driver::Compilation> C (
730
713
TheDriver.BuildCompilation (CommandLine));
731
714
if (!C || C->getJobs ().empty ())
@@ -740,7 +723,8 @@ getCompilationDataBase(int argc, char **argv, std::string &ErrorMessage) {
740
723
741
724
FrontendOptions &FEOpts = CI->getFrontendOpts ();
742
725
if (FEOpts.Inputs .size () != 1 ) {
743
- llvm::errs () << " Only one input file is allowed in P1689 per file mode." ;
726
+ llvm::errs ()
727
+ << " Exactly one input file is required in the per-file mode ('--').\n " ;
744
728
return nullptr ;
745
729
}
746
730
@@ -749,8 +733,9 @@ getCompilationDataBase(int argc, char **argv, std::string &ErrorMessage) {
749
733
auto LastCmd = C->getJobs ().end ();
750
734
LastCmd--;
751
735
if (LastCmd->getOutputFilenames ().size () != 1 ) {
752
- llvm::errs () << " The command line should provide exactly one output file "
753
- " in P1689 per file mode.\n " ;
736
+ llvm::errs ()
737
+ << " Exactly one output file is required in the per-file mode ('--').\n " ;
738
+ return nullptr ;
754
739
}
755
740
StringRef OutputFile = LastCmd->getOutputFilenames ().front ();
756
741
@@ -790,7 +775,7 @@ getCompilationDataBase(int argc, char **argv, std::string &ErrorMessage) {
790
775
int clang_scan_deps_main (int argc, char **argv, const llvm::ToolContext &) {
791
776
std::string ErrorMessage;
792
777
std::unique_ptr<tooling::CompilationDatabase> Compilations =
793
- getCompilationDataBase (argc, argv, ErrorMessage);
778
+ getCompilationDatabase (argc, argv, ErrorMessage);
794
779
if (!Compilations) {
795
780
llvm::errs () << ErrorMessage << " \n " ;
796
781
return 1 ;
0 commit comments