1 // Copyright (c) 2013 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_ITEM_H_ 6 #define TOOLS_GN_ITEM_H_ 7 8 #include <set> 9 #include <string> 10 11 #include "gn/label.h" 12 #include "gn/source_file.h" 13 #include "gn/visibility.h" 14 15 class Config; 16 class ParseNode; 17 class Pool; 18 class Settings; 19 class SourceFile; 20 class Target; 21 class Toolchain; 22 23 // A named item (target, config, etc.) that participates in the dependency 24 // graph. 25 class Item { 26 public: 27 Item(const Settings* settings, 28 const Label& label, 29 const SourceFileSet& build_dependency_files = {}); 30 virtual ~Item(); 31 settings()32 const Settings* settings() const { return settings_; } 33 34 // This is guaranteed to never change after construction so this can be 35 // accessed from any thread with no locking once the item is constructed. label()36 const Label& label() const { return label_; } 37 defined_from()38 const ParseNode* defined_from() const { return defined_from_; } set_defined_from(const ParseNode * df)39 void set_defined_from(const ParseNode* df) { defined_from_ = df; } 40 testonly()41 bool testonly() const { return testonly_; } set_testonly(bool value)42 void set_testonly(bool value) { testonly_ = value; } 43 visibility()44 Visibility& visibility() { return visibility_; } visibility()45 const Visibility& visibility() const { return visibility_; } 46 47 // Manual RTTI. 48 virtual Config* AsConfig(); 49 virtual const Config* AsConfig() const; 50 virtual Pool* AsPool(); 51 virtual const Pool* AsPool() const; 52 virtual Target* AsTarget(); 53 virtual const Target* AsTarget() const; 54 virtual Toolchain* AsToolchain(); 55 virtual const Toolchain* AsToolchain() const; 56 57 // Returns a name like "target" or "config" for the type of item this is, to 58 // be used in logging and error messages. 59 std::string GetItemTypeName() const; 60 61 // Returns the set of build files that may affect this item, please refer to 62 // Scope for how this is determined. build_dependency_files()63 const SourceFileSet& build_dependency_files() const { 64 return build_dependency_files_; 65 } 66 build_dependency_files()67 SourceFileSet& build_dependency_files() { return build_dependency_files_; } 68 69 // Called when this item is resolved, meaning it and all of its dependents 70 // have no unresolved deps. Returns true on success. Sets the error and 71 // returns false on failure. 72 virtual bool OnResolved(Err* err); 73 74 private: 75 bool CheckTestonly(Err* err) const; 76 77 const Settings* settings_; 78 Label label_; 79 SourceFileSet build_dependency_files_; 80 const ParseNode* defined_from_; 81 82 bool testonly_ = false; 83 Visibility visibility_; 84 }; 85 86 #endif // TOOLS_GN_ITEM_H_ 87