bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation, ArrayRef<const char *> OrigArgs, DiagnosticEngine &Diags, StringRef UnresolvedPrimaryFile, std::string &Error) { SmallVector<const char *, 16> Args; sanitizeCompilerArgs(OrigArgs, Args); Invocation.setRuntimeResourcePath(Impl.RuntimeResourcePath); bool Err = Invocation.parseArgs(Args, Diags); if (Err) { // FIXME: Get the actual diagnostic. Error = "error when parsing the compiler arguments"; return Err; } // FIXME: The frontend should be dealing with symlinks, maybe similar to // clang's FileManager ? std::string PrimaryFile = SwiftLangSupport::resolvePathSymlinks(UnresolvedPrimaryFile); for (auto &InputFile : Invocation.getFrontendOptions().InputFilenames) { InputFile = SwiftLangSupport::resolvePathSymlinks(InputFile); } ClangImporterOptions &ImporterOpts = Invocation.getClangImporterOptions(); ImporterOpts.DetailedPreprocessingRecord = true; setModuleName(Invocation); Invocation.setSerializedDiagnosticsPath(StringRef()); Invocation.getLangOptions().AttachCommentsToDecls = true; auto &FrontendOpts = Invocation.getFrontendOptions(); if (FrontendOpts.PlaygroundTransform) { // The playground instrumenter changes the AST in ways that disrupt the // SourceKit functionality. Since we don't need the instrumenter, and all we // actually need is the playground semantics visible to the user, like // silencing the "expression resolves to an unused l-value" error, disable it. FrontendOpts.PlaygroundTransform = false; } if (!PrimaryFile.empty()) { Optional<unsigned> PrimaryIndex; for (auto i : indices(Invocation.getFrontendOptions().InputFilenames)) { auto &CurFile = Invocation.getFrontendOptions().InputFilenames[i]; if (PrimaryFile == CurFile) { PrimaryIndex = i; break; } } if (!PrimaryIndex) { llvm::SmallString<64> Err; llvm::raw_svector_ostream OS(Err); OS << "'" << PrimaryFile << "' is not part of the input files"; Error = OS.str(); return true; } Invocation.getFrontendOptions().PrimaryInput = SelectedInput(*PrimaryIndex); } return Err; }
bool SwiftASTManager::initCompilerInvocation(CompilerInvocation &Invocation, ArrayRef<const char *> OrigArgs, DiagnosticEngine &Diags, StringRef UnresolvedPrimaryFile, std::string &Error) { SmallVector<const char *, 16> Args; sanitizeCompilerArgs(OrigArgs, Args); Invocation.setRuntimeResourcePath(Impl.RuntimeResourcePath); if (Invocation.parseArgs(Args, Diags)) { // FIXME: Get the actual diagnostic. Error = "error when parsing the compiler arguments"; return true; } Invocation.getFrontendOptions().Inputs = resolveSymbolicLinksInInputs( Invocation.getFrontendOptions().Inputs, UnresolvedPrimaryFile, Error); if (!Error.empty()) return true; ClangImporterOptions &ImporterOpts = Invocation.getClangImporterOptions(); ImporterOpts.DetailedPreprocessingRecord = true; setModuleName(Invocation); Invocation.setSerializedDiagnosticsPath(StringRef()); Invocation.getLangOptions().AttachCommentsToDecls = true; Invocation.getLangOptions().DiagnosticsEditorMode = true; Invocation.getLangOptions().KeepSyntaxInfoInSourceFile = true; auto &FrontendOpts = Invocation.getFrontendOptions(); if (FrontendOpts.PlaygroundTransform) { // The playground instrumenter changes the AST in ways that disrupt the // SourceKit functionality. Since we don't need the instrumenter, and all we // actually need is the playground semantics visible to the user, like // silencing the "expression resolves to an unused l-value" error, disable it. FrontendOpts.PlaygroundTransform = false; } // Disable the index-store functionality for the sourcekitd requests. FrontendOpts.IndexStorePath.clear(); ImporterOpts.IndexStorePath.clear(); return false; }