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 #include "linkerconfig/sectionbuilder.h"
17
18 #include <algorithm>
19
20 #include "linkerconfig/common.h"
21 #include "linkerconfig/environment.h"
22 #include "linkerconfig/log.h"
23 #include "linkerconfig/namespace.h"
24 #include "linkerconfig/namespacebuilder.h"
25 #include "linkerconfig/section.h"
26
27 namespace android {
28 namespace linkerconfig {
29 namespace contents {
30
31 using modules::LibProvider;
32 using modules::LibProviders;
33 using modules::Namespace;
34 using modules::Section;
35 using modules::SharedLibs;
36
BuildSection(const Context & ctx,const std::string & name,std::vector<Namespace> && namespaces,const std::set<std::string> & visible_apexes,const LibProviders & providers)37 Section BuildSection(const Context& ctx, const std::string& name,
38 std::vector<Namespace>&& namespaces,
39 const std::set<std::string>& visible_apexes,
40 const LibProviders& providers) {
41 // add additional visible APEX namespaces
42 for (const auto& apex : ctx.GetApexModules()) {
43 if (visible_apexes.find(apex.name) == visible_apexes.end() &&
44 !apex.visible) {
45 continue;
46 }
47 if (auto it = std::find_if(
48 namespaces.begin(),
49 namespaces.end(),
50 [&apex](auto& ns) { return ns.GetName() == apex.namespace_name; });
51 it == namespaces.end()) {
52 auto ns = ctx.BuildApexNamespace(apex, true);
53 namespaces.push_back(std::move(ns));
54 } else {
55 // override "visible" when the apex is already created
56 it->SetVisible(true);
57 }
58 }
59
60 // resolve provide/require constraints
61 Section section(std::move(name), std::move(namespaces));
62 section.Resolve(ctx, providers);
63
64 AddStandardSystemLinks(ctx, §ion);
65 return section;
66 }
67
GetVndkProvider(const Context & ctx,VndkUserPartition partition)68 std::vector<LibProvider> GetVndkProvider(const Context& ctx,
69 VndkUserPartition partition) {
70 std::vector<LibProvider> provider;
71 std::string partition_suffix =
72 partition == VndkUserPartition::Vendor ? "VENDOR" : "PRODUCT";
73 provider.push_back(LibProvider{
74 "vndk",
75 std::bind(BuildVndkNamespace, ctx, partition),
76 SharedLibs{
77 std::vector{Var("VNDK_SAMEPROCESS_LIBRARIES_" + partition_suffix),
78 Var("VNDK_CORE_LIBRARIES_" + partition_suffix)}},
79 });
80 if (modules::IsVndkInSystemNamespace()) {
81 provider.push_back(LibProvider{
82 "vndk_in_system",
83 std::bind(BuildVndkInSystemNamespace, ctx),
84 SharedLibs{std::vector{Var("VNDK_USING_CORE_VARIANT_LIBRARIES")}},
85 });
86 }
87 return provider;
88 }
89
90 } // namespace contents
91 } // namespace linkerconfig
92 } // namespace android
93