• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gn/inherited_libraries.h"
6 
7 #include "gn/target.h"
8 
9 InheritedLibraries::InheritedLibraries() = default;
10 
11 InheritedLibraries::~InheritedLibraries() = default;
12 
13 std::vector<std::pair<const Target*, bool>>
GetOrderedAndPublicFlag() const14 InheritedLibraries::GetOrderedAndPublicFlag() const {
15   std::vector<std::pair<const Target*, bool>> result;
16   result.reserve(targets_.size());
17   for (size_t i = 0; i < targets_.size(); ++i)
18     result.emplace_back(targets_[i], public_flags_[i]);
19   return result;
20 }
21 
Append(const Target * target,bool is_public)22 void InheritedLibraries::Append(const Target* target, bool is_public) {
23   // Try to insert a new node.
24   auto ret = targets_.PushBackWithIndex(target);
25   if (ret.first) {
26     public_flags_.push_back(is_public);
27   } else if (is_public) {
28     // Target already present, if |is_public|, set its flag.
29     public_flags_[ret.second] = true;
30   }
31 }
32 
AppendInherited(const InheritedLibraries & other,bool is_public)33 void InheritedLibraries::AppendInherited(const InheritedLibraries& other,
34                                          bool is_public) {
35   // Append all items in order, mark them public only if the're already public
36   // and we're adding them publicly.
37   for (size_t i = 0; i < other.targets_.size(); ++i) {
38     Append(other.targets_[i], is_public && other.public_flags_[i]);
39   }
40 }
41 
AppendPublicSharedLibraries(const InheritedLibraries & other,bool is_public)42 void InheritedLibraries::AppendPublicSharedLibraries(
43     const InheritedLibraries& other,
44     bool is_public) {
45   for (size_t i = 0; i < other.targets_.size(); ++i) {
46     const Target* target = other.targets_[i];
47     if (target->output_type() == Target::SHARED_LIBRARY &&
48         other.public_flags_[i]) {
49       Append(target, is_public);
50     }
51   }
52 }
53