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

Unified 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: more docs 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 side-by-side diff with in-line comments
Download patch
Index: tools/gn/inherited_libraries.cc
diff --git a/tools/gn/inherited_libraries.cc b/tools/gn/inherited_libraries.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c699b789e085f22880746bc6ca0c278d68cc5b1b
--- /dev/null
+++ b/tools/gn/inherited_libraries.cc
@@ -0,0 +1,77 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tools/gn/inherited_libraries.h"
+
+#include "tools/gn/target.h"
+
+InheritedLibraries::InheritedLibraries() {
+
Dirk Pranke 2015/04/15 19:31:38 nit: stray blank line?
+}
+
+InheritedLibraries::~InheritedLibraries() {
+}
+
+std::vector<const Target*> InheritedLibraries::GetOrdered() const {
+ std::vector<const Target*> result;
+ result.resize(map_.size());
+
+ // The indices in the map should be from 0 to the number of items in the
+ // map, so insert directly into the result (with some sanity checks).
+ for (const auto& pair : map_) {
+ size_t index = pair.second.index;
+ DCHECK(index < result.size());
+ DCHECK(!result[index]);
+ result[index] = pair.first;
+ }
+
+ return result;
+}
+
+std::vector<std::pair<const Target*, bool>>
+InheritedLibraries::GetOrderedAndPublicFlag() const {
+ std::vector<std::pair<const Target*, bool>> result;
+ result.resize(map_.size());
+
+ for (const auto& pair : map_) {
+ size_t index = pair.second.index;
+ DCHECK(index < result.size());
+ DCHECK(!result[index].first);
+ result[index] = std::make_pair(pair.first, pair.second.is_public);
+ }
+
+ return result;
+}
+
+void InheritedLibraries::Append(const Target* target, bool is_public) {
+ // Try to insert a new node.
+ auto insert_result = map_.insert(
+ std::make_pair(target, Node(map_.size(), is_public)));
+
+ if (!insert_result.second) {
+ // Element already present, insert failed and insert_result indicates the
+ // old one. The old one may need to have its public flag updated.
+ if (is_public) {
+ Node& existing_node = insert_result.first->second;
+ existing_node.is_public = true;
+ }
+ }
+}
+
+void InheritedLibraries::AppendInherited(const InheritedLibraries& other,
+ bool is_public) {
+ // Append all items in order, mark them public only if the're already public
+ // and we're adding them publically.
+ for (const auto& cur : other.GetOrderedAndPublicFlag())
+ Append(cur.first, is_public && cur.second);
+}
+
+void InheritedLibraries::AppendPublicSharedLibraries(
+ const InheritedLibraries& other,
+ bool is_public) {
+ for (const auto& cur : other.GetOrderedAndPublicFlag()) {
+ if (cur.first->output_type() == Target::SHARED_LIBRARY && cur.second)
+ Append(cur.first, is_public);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698