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 #ifndef TOOLS_GN_INHERITED_LIBRARIES_H_ 6 #define TOOLS_GN_INHERITED_LIBRARIES_H_ 7 8 #include <stddef.h> 9 10 #include <utility> 11 #include <vector> 12 13 #include "gn/unique_vector.h" 14 15 class Target; 16 17 // Represents an ordered uniquified set of all shared/static libraries for 18 // a given target. These are pushed up the dependency tree. 19 // 20 // Maintaining the order is important so GN links all libraries in the same 21 // order specified in the build files. 22 // 23 // Since this list is uniquified, appending to the list will not actually 24 // append a new item if the target already exists. However, the existing one 25 // may have its is_public flag updated. "Public" always wins, so is_public will 26 // be true if any dependency with that name has been set to public. 27 class InheritedLibraries { 28 public: 29 InheritedLibraries(); 30 ~InheritedLibraries(); 31 32 // Returns the list of dependencies in order, optionally with the flag 33 // indicating whether the dependency is public. GetOrdered()34 std::vector<const Target*> GetOrdered() const { return targets_.vector(); } 35 std::vector<std::pair<const Target*, bool>> GetOrderedAndPublicFlag() const; 36 37 // Adds a single dependency to the end of the list. See note on adding above. 38 void Append(const Target* target, bool is_public); 39 40 // Appends all items from the "other" list to the current one. The is_public 41 // parameter indicates how the current target depends on the items in 42 // "other". If is_public is true, the existing public flags of the appended 43 // items will be preserved (propagating the public-ness up the dependency 44 // chain). If is_public is false, all deps will be added as private since 45 // the current target isn't forwarding them. 46 void AppendInherited(const InheritedLibraries& other, bool is_public); 47 48 // Like AppendInherited but only appends the items in "other" that are of 49 // type SHARED_LIBRARY and only when they're marked public. This is used 50 // to push shared libraries up the dependency chain, following only public 51 // deps, to dependent targets that need to use them. 52 void AppendPublicSharedLibraries(const InheritedLibraries& other, 53 bool is_public); 54 55 private: 56 UniqueVector<const Target*> targets_; 57 std::vector<bool> public_flags_; 58 59 InheritedLibraries(const InheritedLibraries&) = delete; 60 InheritedLibraries& operator=(const InheritedLibraries&) = delete; 61 }; 62 63 #endif // TOOLS_GN_INHERITED_LIBRARIES_H_ 64