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 BOOTLOADER_BUILD, 37 }; 38 39 /* 40 * Attempts to answer the general question "where did this file come from, and 41 * what purpose is it serving? 42 */ 43 struct CvdFile { 44 FileSource source; 45 std::string build_id; 46 std::string build_target; 47 std::string file_path; 48 49 CvdFile(); 50 CvdFile(const FileSource& source, const std::string& build_id, 51 const std::string& build_target, const std::string& file_path); 52 }; 53 54 std::ostream& operator<<(std::ostream&, const CvdFile&); 55 56 /** 57 * A report of state to transfer from fetch_cvd to downstream consumers. 58 * 59 * This includes data intended for programmatic access by other tools such as 60 * assemble_cvd. assemble_cvd can use signals like that multiple build IDs are 61 * present to judge that it needs to do super image remixing or rebuilding the 62 * boot image for a new kernel. 63 * 64 * The output json also includes data relevant for human debugging, like which 65 * flags fetch_cvd was invoked with. 66 */ 67 class FetcherConfig { 68 std::unique_ptr<Json::Value> dictionary_; 69 public: 70 FetcherConfig(); 71 FetcherConfig(FetcherConfig&&); 72 ~FetcherConfig(); 73 74 bool SaveToFile(const std::string& file) const; 75 bool LoadFromFile(const std::string& file); 76 77 // For debugging only, not intended for programmatic access. 78 void RecordFlags(); 79 80 bool add_cvd_file(const CvdFile& file, bool override_entry = false); 81 std::map<std::string, CvdFile> get_cvd_files() const; 82 83 std::string FindCvdFileWithSuffix(const std::string& suffix) const; 84 }; 85 86 } // namespace cuttlefish 87