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 
17 #include "linkerconfig/configuration.h"
18 
19 #include <unordered_map>
20 
21 #include "linkerconfig/log.h"
22 #include "linkerconfig/variables.h"
23 
24 namespace android {
25 namespace linkerconfig {
26 namespace modules {
WriteConfig(ConfigWriter & writer)27 void Configuration::WriteConfig(ConfigWriter& writer) {
28   std::unordered_map<std::string, std::string> resolved_dirs;
29 
30   for (const auto& [dir, section] : dir_to_section_list_) {
31     auto it = resolved_dirs.find(dir);
32     if (it != resolved_dirs.end()) {
33       LOG(WARNING) << "Binary path " << dir << " already found from "
34                    << it->second << ". Path from " << section
35                    << " will be ignored.";
36     } else {
37       resolved_dirs[dir] = section;
38       writer.WriteLine("dir." + section + " = " + dir);
39     }
40   }
41 
42   for (auto& section : sections_) {
43     section.WriteConfig(writer);
44   }
45 }
46 
GetSection(const std::string & name)47 Section* Configuration::GetSection(const std::string& name) {
48   for (auto& section : sections_) {
49     if (section.GetName() == name) {
50       return &section;
51     }
52   }
53 
54   return nullptr;
55 }
56 }  // namespace modules
57 }  // namespace linkerconfig
58 }  // namespace android