• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 
17 #include "host/commands/cvd/parser/load_configs_parser.h"
18 
19 #include <android-base/file.h>
20 #include <gflags/gflags.h>
21 
22 #include <stdio.h>
23 #include <fstream>
24 #include <string>
25 
26 #include "common/libs/utils/files.h"
27 #include "common/libs/utils/json.h"
28 #include "host/commands/assemble_cvd/flags_defaults.h"
29 #include "host/commands/cvd/parser/cf_configs_common.h"
30 #include "host/commands/cvd/parser/cf_configs_instances.h"
31 #include "host/commands/cvd/parser/cf_flags_validator.h"
32 #include "host/commands/cvd/parser/fetch_cvd_parser.h"
33 #include "host/commands/cvd/parser/launch_cvd_parser.h"
34 
35 namespace cuttlefish {
36 
ParseJsonFile(const std::string & file_path)37 Result<Json::Value> ParseJsonFile(const std::string& file_path) {
38   std::string file_content;
39   using android::base::ReadFileToString;
40   CF_EXPECT(ReadFileToString(file_path.c_str(), &file_content,
41                              /* follow_symlinks */ true));
42   auto root = CF_EXPECT(ParseJson(file_content), "Failed parsing JSON file");
43   return root;
44 }
45 
ParseCvdConfigs(Json::Value & root)46 Result<CvdFlags> ParseCvdConfigs(Json::Value& root) {
47   CvdFlags results;
48 
49   CF_EXPECT(ValidateCfConfigs(root), "Loaded Json validation failed");
50 
51   results.launch_cvd_flags = ParseLaunchCvdConfigs(root);
52 
53   results.fetch_cvd_flags = ParseFetchCvdConfigs(root);
54 
55   return results;
56 }
57 
58 }  // namespace cuttlefish
59