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_ = {config.providelibs().begin(),
72 config.providelibs().end()};
73 system_require_libs_ = {config.requirelibs().begin(),
74 config.requirelibs().end()};
75 }
GetSystemProvideLibs() const76 const std::vector<std::string>& BaseContext::GetSystemProvideLibs() const {
77 return system_provide_libs_;
78 }
GetSystemRequireLibs() const79 const std::vector<std::string>& BaseContext::GetSystemRequireLibs() const {
80 return system_require_libs_;
81 }
82
SetVendorConfig(const android::linkerconfig::proto::LinkerConfig & config)83 void BaseContext::SetVendorConfig(
84 const android::linkerconfig::proto::LinkerConfig& config) {
85 vendor_provide_libs_ = {config.providelibs().begin(),
86 config.providelibs().end()};
87 vendor_require_libs_ = {config.requirelibs().begin(),
88 config.requirelibs().end()};
89 }
GetVendorProvideLibs() const90 const std::vector<std::string>& BaseContext::GetVendorProvideLibs() const {
91 return vendor_provide_libs_;
92 }
GetVendorRequireLibs() const93 const std::vector<std::string>& BaseContext::GetVendorRequireLibs() const {
94 return vendor_require_libs_;
95 }
96
SetProductConfig(const android::linkerconfig::proto::LinkerConfig & config)97 void BaseContext::SetProductConfig(
98 const android::linkerconfig::proto::LinkerConfig& config) {
99 product_provide_libs_ = {config.providelibs().begin(),
100 config.providelibs().end()};
101 product_require_libs_ = {config.requirelibs().begin(),
102 config.requirelibs().end()};
103 }
GetProductProvideLibs() const104 const std::vector<std::string>& BaseContext::GetProductProvideLibs() const {
105 return product_provide_libs_;
106 }
GetProductRequireLibs() const107 const std::vector<std::string>& BaseContext::GetProductRequireLibs() const {
108 return product_require_libs_;
109 }
110
111 } // namespace modules
112 } // namespace linkerconfig
113 } // namespace android
114