ParsedAST TestTU::build() const { std::string FullFilename = testPath(Filename), FullHeaderName = testPath(HeaderFilename); std::vector<const char *> Cmd = {"clang", FullFilename.c_str()}; // FIXME: this shouldn't need to be conditional, but it breaks a // GoToDefinition test for some reason (getMacroArgExpandedLocation fails). if (!HeaderCode.empty()) { Cmd.push_back("-include"); Cmd.push_back(FullHeaderName.c_str()); } Cmd.insert(Cmd.end(), ExtraArgs.begin(), ExtraArgs.end()); ParseInputs Inputs; Inputs.CompileCommand.Filename = FullFilename; Inputs.CompileCommand.CommandLine = {Cmd.begin(), Cmd.end()}; Inputs.CompileCommand.Directory = testRoot(); Inputs.Contents = Code; Inputs.FS = buildTestFS({{FullFilename, Code}, {FullHeaderName, HeaderCode}}); Inputs.Opts = ParseOptions(); Inputs.Opts.ClangTidyOpts.Checks = ClangTidyChecks; Inputs.Index = ExternalIndex; if (Inputs.Index) Inputs.Opts.SuggestMissingIncludes = true; auto CI = buildCompilerInvocation(Inputs); assert(CI && "Failed to build compilation invocation."); auto Preamble = buildPreamble(FullFilename, *CI, /*OldPreamble=*/nullptr, /*OldCompileCommand=*/Inputs.CompileCommand, Inputs, /*StoreInMemory=*/true, /*PreambleCallback=*/nullptr); auto AST = buildAST(FullFilename, createInvocationFromCommandLine(Cmd), Inputs, Preamble); if (!AST.hasValue()) { ADD_FAILURE() << "Failed to build code:\n" << Code; llvm_unreachable("Failed to build TestTU!"); } return std::move(*AST); }
IntrusiveRefCntPtr<vfs::FileSystem> getFileSystem() override { Got = Context::current().getExisting(Secret); return buildTestFS({}); }