• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/section.h"
18 
19 #include "linkerconfig/log.h"
20 
21 #define LOG_TAG "linkerconfig"
22 
23 namespace android {
24 namespace linkerconfig {
25 namespace modules {
CreateNamespace(const std::string & namespace_name,bool is_isolated,bool is_visible)26 std::shared_ptr<Namespace> Section::CreateNamespace(
27     const std::string& namespace_name, bool is_isolated, bool is_visible) {
28   auto new_namespace =
29       std::make_shared<Namespace>(namespace_name, is_isolated, is_visible);
30 
31   if (namespaces_.find(namespace_name) != namespaces_.end()) {
32     LOG(INFO) << "Namespace " << namespace_name
33               << " already exists. Overwriting namespace.";
34   }
35 
36   namespaces_[namespace_name] = new_namespace;
37   return new_namespace;
38 }
39 
WriteConfig(ConfigWriter & writer)40 void Section::WriteConfig(ConfigWriter& writer) {
41   writer.WriteLine("[%s]", name_.c_str());
42 
43   std::string additional_namespaces = "";
44 
45   bool is_first = true;
46   for (auto& ns : namespaces_) {
47     if (ns.first != "default") {
48       if (!is_first) {
49         additional_namespaces += ",";
50       }
51 
52       additional_namespaces += ns.first;
53       is_first = false;
54     }
55   }
56 
57   if (!is_first) {
58     writer.WriteLine("additional.namespaces = " + additional_namespaces);
59   }
60 
61   for (auto& ns : namespaces_) {
62     ns.second->WriteConfig(writer);
63   }
64 }
65 
WriteBinaryPaths(ConfigWriter & writer)66 void Section::WriteBinaryPaths(ConfigWriter& writer) {
67   writer.SetPrefix("dir." + name_ + " = ");
68 
69   for (auto& path : binary_paths_) {
70     writer.WriteLine(path);
71   }
72 
73   writer.ResetPrefix();
74 }
75 
GetName()76 std::string Section::GetName() {
77   return name_;
78 }
79 }  // namespace modules
80 }  // namespace linkerconfig
81 }  // namespace android