66//
77// ===----------------------------------------------------------------------===//
88
9- #include " clang/Tooling/DependencyScanning/ DependencyScannerImpl.h"
9+ #include " DependencyScannerImpl.h"
1010#include " clang/Basic/DiagnosticFrontend.h"
1111#include " clang/Basic/DiagnosticSerialization.h"
1212#include " clang/Driver/Driver.h"
@@ -490,9 +490,6 @@ bool initializeScanCompilerInstance(
490490 IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
491491 DiagnosticConsumer *DiagConsumer, DependencyScanningService &Service,
492492 IntrusiveRefCntPtr<DependencyScanningWorkerFilesystem> DepFS) {
493- // TODO: the commented out code here should be un-commented when
494- // we enable CAS.
495- // ScanInstance.getInvocation().getCASOpts() = Worker.CASOpts;
496493 ScanInstance.setBuildingModule (false );
497494
498495 ScanInstance.createVirtualFileSystem (FS, DiagConsumer);
@@ -728,20 +725,22 @@ llvm::Error CompilerInstanceWithContext::initialize() {
728725 llvm::inconvertibleErrorCode ());
729726 }
730727
728+ assert (Compilation->getJobs ().size () &&
729+ " Must have a job list of non-zero size" );
731730 const driver::Command &Command = *(Compilation->getJobs ().begin ());
732731 const auto &CommandArgs = Command.getArguments ();
733732 size_t ArgSize = CommandArgs.size ();
734733 assert (ArgSize >= 1 && " Cannot have a command with 0 args" );
735734 const char *FirstArg = CommandArgs[0 ];
736- if (strcmp (FirstArg, " -cc1" ) )
735+ if (StringRef (FirstArg) != " -cc1" )
737736 return llvm::make_error<llvm::StringError>(
738737 " Incorrect compilation command, missing cc1" ,
739738 llvm::inconvertibleErrorCode ());
740- Invocation = std::make_unique<CompilerInvocation>();
739+ OriginalInvocation = std::make_unique<CompilerInvocation>();
741740
742- if (!CompilerInvocation::CreateFromArgs (*Invocation, Command. getArguments (),
743- *DiagEngineWithCmdAndOpts-> DiagEngine ,
744- Command.getExecutable ())) {
741+ if (!CompilerInvocation::CreateFromArgs (
742+ *OriginalInvocation, Command. getArguments () ,
743+ *DiagEngineWithCmdAndOpts-> DiagEngine , Command.getExecutable ())) {
745744 DiagEngineWithCmdAndOpts->DiagEngine ->Report (
746745 diag::err_fe_expected_compiler_job)
747746 << llvm::join (CommandLine, " " );
@@ -750,36 +749,15 @@ llvm::Error CompilerInstanceWithContext::initialize() {
750749 llvm::inconvertibleErrorCode ());
751750 }
752751
753- // TODO: CMDArgsStrVector is making string copies. We should optimize later
754- // and avoid the copies.
755- std::vector<std::string> CMDArgsStrVector (ArgSize + 1 );
756- CMDArgsStrVector.push_back (Command.getExecutable ());
757- llvm::transform (CommandArgs, CMDArgsStrVector.begin () + 1 ,
758- [](const char *s) { return std::string (s); });
759-
760- Invocation = createCompilerInvocation (CMDArgsStrVector,
761- *DiagEngineWithCmdAndOpts->DiagEngine );
762- if (!Invocation) {
763- DiagEngineWithCmdAndOpts->DiagEngine ->Report (
764- diag::err_fe_expected_compiler_job)
765- << llvm::join (CommandLine, " " );
766- return llvm::make_error<llvm::StringError>(
767- " Cannot create CompilerInvocation from Args" ,
768- llvm::inconvertibleErrorCode ());
769- }
770-
771- Invocation->getFrontendOpts ().DisableFree = false ;
772- Invocation->getCodeGenOpts ().DisableFree = false ;
773-
774752 if (any (Worker.Service .getOptimizeArgs () & ScanningOptimizations::Macros))
775- canonicalizeDefines (Invocation ->getPreprocessorOpts ());
753+ canonicalizeDefines (OriginalInvocation ->getPreprocessorOpts ());
776754
777755 // Create the CompilerInstance.
778756 IntrusiveRefCntPtr<ModuleCache> ModCache =
779757 makeInProcessModuleCache (Worker.Service .getModuleCacheEntries ());
780758 CIPtr = std::make_unique<CompilerInstance>(
781- std::make_shared<CompilerInvocation>(*Invocation), Worker. PCHContainerOps ,
782- ModCache.get ());
759+ std::make_shared<CompilerInvocation>(*OriginalInvocation) ,
760+ Worker. PCHContainerOps , ModCache.get ());
783761 auto &CI = *CIPtr;
784762
785763 if (!initializeScanCompilerInstance (
@@ -801,7 +779,6 @@ llvm::Error CompilerInstanceWithContext::initialize() {
801779 OutputOpts = takeDependencyOutputOptionsFrom (CI);
802780
803781 CI.createTarget ();
804- // CI.initializeDelayedInputFileFromCAS();
805782
806783 return llvm::Error::success ();
807784}
@@ -810,21 +787,19 @@ llvm::Error CompilerInstanceWithContext::computeDependencies(
810787 StringRef ModuleName, DependencyConsumer &Consumer,
811788 DependencyActionController &Controller) {
812789 auto &CI = *CIPtr;
813- CompilerInvocation Inv (*Invocation );
790+ CompilerInvocation Inv (*OriginalInvocation );
814791
815792 CI.clearDependencyCollectors ();
816793 auto MDC = initializeScanInstanceDependencyCollector (
817794 CI, std::make_unique<DependencyOutputOptions>(*OutputOpts), CWD, Consumer,
818- Worker.Service , *Invocation, Controller, PrebuiltModuleASTMap,
819- StableDirs);
795+ Worker.Service , Inv, Controller, PrebuiltModuleASTMap, StableDirs);
820796
821797 if (!SrcLocOffset) {
822798 // When SrcLocOffset is zero, we are at the beginning of the fake source
823799 // file. In this case, we call BeginSourceFile to initialize.
824800 std::unique_ptr<FrontendAction> Action =
825- std::make_unique<GetDependenciesByModuleNameAction>(ModuleName );
801+ std::make_unique<PreprocessOnlyAction>( );
826802 auto InputFile = CI.getFrontendOpts ().Inputs .begin ();
827-
828803 Action->BeginSourceFile (CI, *InputFile);
829804 }
830805
@@ -872,14 +847,6 @@ llvm::Error CompilerInstanceWithContext::computeDependencies(
872847 MDC->applyDiscoveredDependencies (Inv);
873848 Consumer.handleBuildCommand ({CommandLine[0 ], Inv.getCC1CommandLine ()});
874849
875- // TODO: enable CAS
876- // std::string ID = Inv.getFileSystemOpts().CASFileSystemRootID;
877- // if (!ID.empty())
878- // Consumer.handleCASFileSystemRootID(std::move(ID));
879- // ID = Inv.getFrontendOpts().CASIncludeTreeID;
880- // if (!ID.empty())
881- // Consumer.handleIncludeTreeID(std::move(ID));
882-
883850 // Remove the PPCallbacks since they are going out of scope.
884851 CI.getPreprocessor ().removePPCallbacks ();
885852 return llvm::Error::success ();
0 commit comments