kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/extractor/proto/proto_extractor.h (about) 1 /* 2 * Copyright 2019 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 #ifndef KYTHE_CXX_EXTRACTOR_PROTO_PROTO_EXTRACTOR_H_ 18 #define KYTHE_CXX_EXTRACTOR_PROTO_PROTO_EXTRACTOR_H_ 19 20 #include "absl/strings/string_view.h" 21 #include "kythe/cxx/common/file_vname_generator.h" 22 #include "kythe/cxx/common/index_writer.h" 23 #include "kythe/proto/analysis.pb.h" 24 25 namespace kythe { 26 namespace lang_proto { 27 28 class ProtoExtractor { 29 public: 30 /// Reads KYTHE_VNAMES, KYTHE_CORPUS, and KYTHE_ROOT_DIRECTORY environment 31 /// variables and configures vname_gen, corpus, and root_directory 32 /// appropriately. 33 void ConfigureFromEnv(); 34 35 /// \brief Extracts the given list of proto files and all of their imported 36 /// dependencies. 37 /// 38 /// \param proto_filenames A list of toplevel protos to extract. These are 39 /// added to the compilation unit's "source_file" and "required_input" lists. 40 /// \param index_writer A writer to save all required input files to. 41 /// \return A compilation unit with all proto files and --proto_path arguments 42 /// recorded. Note that the returned compilation unit is not written to the 43 /// index_writer. 44 proto::CompilationUnit ExtractProtos( 45 const std::vector<std::string>& proto_filenames, 46 IndexWriter* index_writer) const; 47 48 /// Search paths where the proto compiler will look for proto files. See 49 /// indexer/proto/search_path.h for details. 50 std::vector<std::pair<std::string, std::string>> path_substitutions; 51 /// Used to generate vnames for each proto file. 52 FileVNameGenerator vname_gen; 53 /// All paths recorded in the compilation unit will be made relative to this 54 /// directory. 55 std::string root_directory = "."; 56 /// Any path that is not assigned a corpus by the FileVNameGenerator is given 57 /// this corpus id. 58 std::string corpus; 59 }; 60 61 } // namespace lang_proto 62 } // namespace kythe 63 64 #endif // KYTHE_CXX_EXTRACTOR_PROTO_PROTO_EXTRACTOR_H_