1 /* 2 * Copyright (C) 2019 The Android Open Source Project 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 #pragma once 17 18 #include <map> 19 #include <ostream> 20 #include <string> 21 22 namespace Json { 23 class Value; 24 } 25 26 namespace cuttlefish { 27 28 // Order in enum is not guaranteed to be stable, serialized as a string. 29 enum FileSource { 30 UNKNOWN_PURPOSE = 0, 31 DEFAULT_BUILD, 32 SYSTEM_BUILD, 33 KERNEL_BUILD, 34 LOCAL_FILE, 35 GENERATED, 36 }; 37 38 /* 39 * Attempts to answer the general question "where did this file come from, and 40 * what purpose is it serving? 41 */ 42 struct CvdFile { 43 FileSource source; 44 std::string build_id; 45 std::string build_target; 46 std::string file_path; 47 48 CvdFile(); 49 CvdFile(const FileSource& source, const std::string& build_id, 50 const std::string& build_target, const std::string& file_path); 51 }; 52 53 std::ostream& operator<<(std::ostream&, const CvdFile&); 54 55 /** 56 * A report of state to transfer from fetch_cvd to downstream consumers. 57 * 58 * This includes data intended for programmatic access by other tools such as 59 * assemble_cvd. assemble_cvd can use signals like that multiple build IDs are 60 * present to judge that it needs to do super image remixing or rebuilding the 61 * boot image for a new kernel. 62 * 63 * The output json also includes data relevant for human debugging, like which 64 * flags fetch_cvd was invoked with. 65 */ 66 class FetcherConfig { 67 std::unique_ptr<Json::Value> dictionary_; 68 public: 69 FetcherConfig(); 70 FetcherConfig(FetcherConfig&&); 71 ~FetcherConfig(); 72 73 bool SaveToFile(const std::string& file) const; 74 bool LoadFromFile(const std::string& file); 75 76 // For debugging only, not intended for programmatic access. 77 void RecordFlags(); 78 79 bool add_cvd_file(const CvdFile& file, bool override_entry = false); 80 std::map<std::string, CvdFile> get_cvd_files() const; 81 82 std::string FindCvdFileWithSuffix(const std::string& suffix) const; 83 }; 84 85 } // namespace cuttlefish 86