/* * Copyright (C) 2023 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 #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/launch_cvd_parser.h" #include "host/commands/cvd/parser/launch_cvd_templates.h" namespace cuttlefish { std::string GenerateNumInstancesFlag(const Json::Value& root) { int num_instances = root["instances"].size(); LOG(DEBUG) << "num_instances = " << num_instances; std::string result = "--num_instances=" + std::to_string(num_instances); return result; } std::string GenerateCommonGflag(const Json::Value& root, const std::string& gflag_name, const std::string& json_flag) { std::stringstream buff; // Append Header buff << "--" << gflag_name << "=" << root[json_flag].asString(); return buff.str(); } std::vector GenerateCfFlags(const Json::Value& root) { std::vector result; result.emplace_back(GenerateNumInstancesFlag(root)); result.emplace_back(GenerateCommonGflag(root, "netsim_bt", "netsim_bt")); result = MergeResults(result, GenerateInstancesFlags(root["instances"])); return result; } void InitCvdConfigs(Json::Value& root) { // Handle common flags if (!root.isMember("netsim_bt")) { root["netsim_bt"] = CF_DEFAULTS_NETSIM_BT; } // Handle instances flags InitInstancesConfigs(root["instances"]); } std::vector ParseLaunchCvdConfigs(Json::Value& root) { ExtractLaunchTemplates(root["instances"]); InitCvdConfigs(root); return GenerateCfFlags(root); } } // namespace cuttlefish