blob: e4b25ca410a4ae706eb2e2f930b2bbcf5f9528e9 [file] [log] [blame]
Tom Cherryb7349902015-08-26 11:43:36 -07001/*
2 * Copyright (C) 2015 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 "import_parser.h"
18
Tom Cherry3f5eaae52017-04-06 16:30:22 -070019#include <android-base/logging.h>
Tom Cherryb7349902015-08-26 11:43:36 -070020
Tom Cherryb7349902015-08-26 11:43:36 -070021#include "util.h"
22
Tom Cherry81f5d3e2017-06-22 12:53:17 -070023namespace android {
24namespace init {
25
Tom Cherrybbcbc2f2019-06-10 11:08:01 -070026Result<void> ImportParser::ParseSection(std::vector<std::string>&& args,
27 const std::string& filename, int line) {
Tom Cherryb7349902015-08-26 11:43:36 -070028 if (args.size() != 2) {
Tom Cherryb592dd82017-08-02 17:01:36 -070029 return Error() << "single argument needed for import\n";
Tom Cherryb7349902015-08-26 11:43:36 -070030 }
31
Tom Cherryc5cf85d2019-07-31 13:59:15 -070032 auto conf_file = ExpandProps(args[1]);
Bernie Innocenticecebbb2020-02-06 03:49:33 +090033 if (!conf_file.ok()) {
Tom Cherryc5cf85d2019-07-31 13:59:15 -070034 return Error() << "Could not expand import: " << conf_file.error();
Tom Cherryb7349902015-08-26 11:43:36 -070035 }
36
Tom Cherryc5cf85d2019-07-31 13:59:15 -070037 LOG(INFO) << "Added '" << *conf_file << "' to import list";
Tom Cherry30a6f272017-04-19 15:31:58 -070038 if (filename_.empty()) filename_ = filename;
Tom Cherryc5cf85d2019-07-31 13:59:15 -070039 imports_.emplace_back(std::move(*conf_file), line);
Tom Cherrybbcbc2f2019-06-10 11:08:01 -070040 return {};
Tom Cherryb7349902015-08-26 11:43:36 -070041}
42
Tom Cherrybbcbc2f2019-06-10 11:08:01 -070043Result<void> ImportParser::ParseLineSection(std::vector<std::string>&&, int) {
Tom Cherry194b5d12018-05-09 17:38:30 -070044 return Error() << "Unexpected line found after import statement";
45}
46
Tom Cherry30a6f272017-04-19 15:31:58 -070047void ImportParser::EndFile() {
Tom Cherryb7349902015-08-26 11:43:36 -070048 auto current_imports = std::move(imports_);
49 imports_.clear();
Tom Cherry30a6f272017-04-19 15:31:58 -070050 for (const auto& [import, line_num] : current_imports) {
Tom Cherry194b5d12018-05-09 17:38:30 -070051 parser_->ParseConfig(import);
Tom Cherryb7349902015-08-26 11:43:36 -070052 }
53}
Tom Cherry81f5d3e2017-06-22 12:53:17 -070054
55} // namespace init
56} // namespace android