Autofill: Add WalletIntegrationAvailable() to components.
[chromium-blink-merge.git] / tools / gn / inherited_libraries.cc
blob06ac9ae4480fb8c2261f624b5e574c29d6480b7a
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "tools/gn/inherited_libraries.h"
7 #include "tools/gn/target.h"
9 InheritedLibraries::InheritedLibraries() {
12 InheritedLibraries::~InheritedLibraries() {
15 std::vector<const Target*> InheritedLibraries::GetOrdered() const {
16 std::vector<const Target*> result;
17 result.resize(map_.size());
19 // The indices in the map should be from 0 to the number of items in the
20 // map, so insert directly into the result (with some sanity checks).
21 for (const auto& pair : map_) {
22 size_t index = pair.second.index;
23 DCHECK(index < result.size());
24 DCHECK(!result[index]);
25 result[index] = pair.first;
28 return result;
31 std::vector<std::pair<const Target*, bool>>
32 InheritedLibraries::GetOrderedAndPublicFlag() const {
33 std::vector<std::pair<const Target*, bool>> result;
34 result.resize(map_.size());
36 for (const auto& pair : map_) {
37 size_t index = pair.second.index;
38 DCHECK(index < result.size());
39 DCHECK(!result[index].first);
40 result[index] = std::make_pair(pair.first, pair.second.is_public);
43 return result;
46 void InheritedLibraries::Append(const Target* target, bool is_public) {
47 // Try to insert a new node.
48 auto insert_result = map_.insert(
49 std::make_pair(target, Node(map_.size(), is_public)));
51 if (!insert_result.second) {
52 // Element already present, insert failed and insert_result indicates the
53 // old one. The old one may need to have its public flag updated.
54 if (is_public) {
55 Node& existing_node = insert_result.first->second;
56 existing_node.is_public = true;
61 void InheritedLibraries::AppendInherited(const InheritedLibraries& other,
62 bool is_public) {
63 // Append all items in order, mark them public only if the're already public
64 // and we're adding them publically.
65 for (const auto& cur : other.GetOrderedAndPublicFlag())
66 Append(cur.first, is_public && cur.second);
69 void InheritedLibraries::AppendPublicSharedLibraries(
70 const InheritedLibraries& other,
71 bool is_public) {
72 for (const auto& cur : other.GetOrderedAndPublicFlag()) {
73 if (cur.first->output_type() == Target::SHARED_LIBRARY && cur.second)
74 Append(cur.first, is_public);