kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/tools/fyi/fyi_main.cc (about) 1 /* 2 * Copyright 2015 The Kythe Authors. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <memory> 18 19 #include "absl/flags/usage.h" 20 #include "absl/log/log.h" 21 #include "absl/memory/memory.h" 22 #include "clang/Tooling/CommonOptionsParser.h" 23 #include "clang/Tooling/Tooling.h" 24 #include "kythe/cxx/common/init.h" 25 #include "kythe/cxx/common/net_client.h" 26 #include "kythe/cxx/tools/fyi/fyi.h" 27 #include "llvm/Support/CommandLine.h" 28 29 // We use the default support in Clang for compilation databases. 30 31 namespace cl = llvm::cl; 32 static cl::extrahelp common_help( 33 clang::tooling::CommonOptionsParser::HelpMessage); 34 static cl::OptionCategory fyi_options("Tool options"); 35 static cl::opt<std::string> xrefs("xrefs", 36 cl::desc("Base URI for xrefs service"), 37 cl::init("http://localhost:8080")); 38 39 int main(int argc, const char** argv) { 40 GOOGLE_PROTOBUF_VERIFY_VERSION; 41 kythe::InitializeProgram(argv[0]); 42 absl::SetProgramUsageMessage("fyi: repair a C++ file with missing includes"); 43 auto options = 44 clang::tooling::CommonOptionsParser::create(argc, argv, fyi_options); 45 if (!options) { 46 llvm::errs() << options.takeError(); 47 return 1; 48 } 49 kythe::JsonClient::InitNetwork(); 50 auto xrefs_db = std::make_unique<kythe::XrefsJsonClient>( 51 std::make_unique<kythe::JsonClient>(), xrefs); 52 clang::tooling::ClangTool tool(options->getCompilations(), 53 options->getSourcePathList()); 54 kythe::fyi::ActionFactory factory(std::move(xrefs_db), 5); 55 return tool.run(&factory); 56 }