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/log.h"
22 #include "linkerconfig/namespace.h"
23 #include "linkerconfig/namespacebuilder.h"
24 #include "linkerconfig/section.h"
25
26 namespace android {
27 namespace linkerconfig {
28 namespace contents {
29
30 using modules::LibProviders;
31 using modules::Namespace;
32 using modules::Section;
33
BuildSection(const Context & ctx,const std::string & name,std::vector<Namespace> && namespaces,const std::set<std::string> & visible_apexes,const LibProviders & providers)34 Section BuildSection(const Context& ctx, const std::string& name,
35 std::vector<Namespace>&& namespaces,
36 const std::set<std::string>& visible_apexes,
37 const LibProviders& providers) {
38 // add additional visible APEX namespaces
39 for (const auto& apex : ctx.GetApexModules()) {
40 if (visible_apexes.find(apex.name) == visible_apexes.end() &&
41 !apex.visible) {
42 continue;
43 }
44 if (auto it = std::find_if(
45 namespaces.begin(),
46 namespaces.end(),
47 [&apex](auto& ns) { return ns.GetName() == apex.namespace_name; });
48 it == namespaces.end()) {
49 auto ns = ctx.BuildApexNamespace(apex, true);
50 namespaces.push_back(std::move(ns));
51 } else {
52 // override "visible" when the apex is already created
53 it->SetVisible(true);
54 }
55 }
56
57 // resolve provide/require constraints
58 Section section(std::move(name), std::move(namespaces));
59 if (auto res = section.Resolve(ctx, providers); !res.ok()) {
60 LOG(ERROR) << res.error();
61 }
62
63 AddStandardSystemLinks(ctx, §ion);
64 return section;
65 }
66 } // namespace contents
67 } // namespace linkerconfig
68 } // namespace android
69