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