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