Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: tools/gn/inherited_libraries.cc

Issue 1083663007: Propagate GN public shared libraries through shared libraries (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/inherited_libraries.h ('k') | tools/gn/inherited_libraries_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "tools/gn/inherited_libraries.h"
6
7 #include "tools/gn/target.h"
8
9 InheritedLibraries::InheritedLibraries() {
10 }
11
12 InheritedLibraries::~InheritedLibraries() {
13 }
14
15 std::vector<const Target*> InheritedLibraries::GetOrdered() const {
16 std::vector<const Target*> result;
17 result.resize(map_.size());
18
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;
26 }
27
28 return result;
29 }
30
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());
35
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);
41 }
42
43 return result;
44 }
45
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)));
50
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;
57 }
58 }
59 }
60
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);
67 }
68
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);
75 }
76 }
OLDNEW
« no previous file with comments | « tools/gn/inherited_libraries.h ('k') | tools/gn/inherited_libraries_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698