/* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "host/commands/cvd/parser/load_configs_parser.h" #include #include #include #include #include #include "common/libs/utils/files.h" #include "common/libs/utils/json.h" #include "host/commands/assemble_cvd/flags_defaults.h" #include "host/commands/cvd/parser/cf_configs_common.h" #include "host/commands/cvd/parser/cf_configs_instances.h" #include "host/commands/cvd/parser/cf_flags_validator.h" #include "host/commands/cvd/parser/fetch_cvd_parser.h" #include "host/commands/cvd/parser/launch_cvd_parser.h" namespace cuttlefish { Result ParseJsonFile(const std::string& file_path) { std::string file_content; using android::base::ReadFileToString; CF_EXPECT(ReadFileToString(file_path.c_str(), &file_content, /* follow_symlinks */ true)); auto root = CF_EXPECT(ParseJson(file_content), "Failed parsing JSON file"); return root; } Result ParseCvdConfigs(Json::Value& root) { CvdFlags results; CF_EXPECT(ValidateCfConfigs(root), "Loaded Json validation failed"); results.launch_cvd_flags = ParseLaunchCvdConfigs(root); results.fetch_cvd_flags = ParseFetchCvdConfigs(root); return results; } } // namespace cuttlefish