kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/cxx_extractor_main.cc (about) 1 /* 2 * Copyright 2014 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 // cxx_extractor is meant to be a drop-in replacement for clang/gcc's frontend. 18 // It collects all of the resources that clang would use to compile a single 19 // source file (as determined by the command line arguments) and produces a 20 // .kzip file. 21 // 22 // We read environment variables KYTHE_CORPUS (to set the default corpus), 23 // KYTHE_ROOT_DIRECTORY (to set the default root directory and to configure 24 // Clang's header search), KYTHE_OUTPUT_DIRECTORY (to control where kzip 25 // files are deposited), and KYTHE_VNAMES (to control vname generation). 26 // 27 // If the first two arguments are --with_executable /foo/bar, the extractor 28 // will consider /foo/bar to be the executable it was called as for purposes 29 // of argument interpretation. These arguments are then stripped. 30 31 // If -resource-dir (a Clang argument) is *not* provided, versions of the 32 // compiler header files embedded into the extractor's executable will be 33 // mapped to /kythe_builtins and used. 34 35 #include <string> 36 #include <vector> 37 38 #include "google/protobuf/stubs/common.h" 39 #include "kythe/cxx/common/init.h" 40 #include "kythe/cxx/extractor/cxx_extractor.h" 41 #include "kythe/cxx/extractor/language.h" 42 43 int main(int argc, char* argv[]) { 44 GOOGLE_PROTOBUF_VERIFY_VERSION; 45 kythe::InitializeProgram(argv[0]); 46 47 kythe::ExtractorConfiguration config; 48 config.SetArgs(std::vector<std::string>(argv, argv + argc)); 49 config.InitializeFromEnvironment(); 50 bool success = config.Extract(kythe::supported_language::Language::kCpp); 51 google::protobuf::ShutdownProtobufLibrary(); 52 return success ? 0 : 1; 53 }