1 /*
2  * Copyright (C) 2020 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/basecontext.h"
18 
19 namespace android {
20 namespace linkerconfig {
21 namespace modules {
BaseContext()22 BaseContext::BaseContext() : strict_(false) {
23 }
24 
SetApexModules(std::vector<ApexInfo> && apex_modules)25 void BaseContext::SetApexModules(std::vector<ApexInfo>&& apex_modules) {
26   apex_modules_ = std::move(apex_modules);
27 
28   for (const auto& apex_module : apex_modules_) {
29     for (const auto& lib : apex_module.provide_libs) {
30       apex_module_map_.emplace(lib, std::cref<ApexInfo>(apex_module));
31     }
32   }
33 }
34 
GetApexModules() const35 const std::vector<ApexInfo>& BaseContext::GetApexModules() const {
36   return apex_modules_;
37 }
38 
39 const std::unordered_map<std::string, std::reference_wrapper<const ApexInfo>>&
GetApexModuleMap() const40 BaseContext::GetApexModuleMap() const {
41   return apex_module_map_;
42 }
43 
SetStrictMode(bool strict)44 void BaseContext::SetStrictMode(bool strict) {
45   strict_ = strict;
46 }
47 
IsStrictMode() const48 bool BaseContext::IsStrictMode() const {
49   return strict_;
50 }
51 
SetTargetApex(const std::string & target_apex)52 void BaseContext::SetTargetApex(const std::string& target_apex) {
53   target_apex_ = target_apex;
54 }
55 
GetTargetApex() const56 const std::string& BaseContext::GetTargetApex() const {
57   return target_apex_;
58 }
59 
BuildApexNamespace(const ApexInfo & apex_info,bool visible) const60 Namespace BaseContext::BuildApexNamespace(const ApexInfo& apex_info,
61                                           bool visible) const {
62   Namespace ns(apex_info.namespace_name,
63                /*is_isolated=*/true,
64                visible);
65   InitializeWithApex(ns, apex_info);
66   return ns;
67 }
68 
SetSystemConfig(const android::linkerconfig::proto::LinkerConfig & config)69 void BaseContext::SetSystemConfig(
70     const android::linkerconfig::proto::LinkerConfig& config) {
71   system_provide_libs_.insert(system_provide_libs_.end(),
72                               config.providelibs().begin(),
73                               config.providelibs().end());
74   system_require_libs_.insert(system_require_libs_.end(),
75                               config.requirelibs().begin(),
76                               config.requirelibs().end());
77 }
78 
GetSystemProvideLibs() const79 const std::vector<std::string>& BaseContext::GetSystemProvideLibs() const {
80   return system_provide_libs_;
81 }
GetSystemRequireLibs() const82 const std::vector<std::string>& BaseContext::GetSystemRequireLibs() const {
83   return system_require_libs_;
84 }
85 
SetVendorConfig(const android::linkerconfig::proto::LinkerConfig & config)86 void BaseContext::SetVendorConfig(
87     const android::linkerconfig::proto::LinkerConfig& config) {
88   vendor_provide_libs_ = {config.providelibs().begin(),
89                           config.providelibs().end()};
90   vendor_require_libs_ = {config.requirelibs().begin(),
91                           config.requirelibs().end()};
92 }
GetVendorProvideLibs() const93 const std::vector<std::string>& BaseContext::GetVendorProvideLibs() const {
94   return vendor_provide_libs_;
95 }
GetVendorRequireLibs() const96 const std::vector<std::string>& BaseContext::GetVendorRequireLibs() const {
97   return vendor_require_libs_;
98 }
99 
SetProductConfig(const android::linkerconfig::proto::LinkerConfig & config)100 void BaseContext::SetProductConfig(
101     const android::linkerconfig::proto::LinkerConfig& config) {
102   product_provide_libs_ = {config.providelibs().begin(),
103                            config.providelibs().end()};
104   product_require_libs_ = {config.requirelibs().begin(),
105                            config.requirelibs().end()};
106 }
GetProductProvideLibs() const107 const std::vector<std::string>& BaseContext::GetProductProvideLibs() const {
108   return product_provide_libs_;
109 }
GetProductRequireLibs() const110 const std::vector<std::string>& BaseContext::GetProductRequireLibs() const {
111   return product_require_libs_;
112 }
113 
114 }  // namespace modules
115 }  // namespace linkerconfig
116 }  // namespace android
117