Nico Weber | 3f6100c | 2019-11-07 09:51:05 -0500 | [diff] [blame] | 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, |
David 'Digit' Turner | 28044bc | 2019-11-28 16:39:43 +0100 | [diff] [blame] | 29 | const SourceFileSet& build_dependency_files = {}); |
Nico Weber | 3f6100c | 2019-11-07 09:51:05 -0500 | [diff] [blame] | 30 | virtual ~Item(); |
| 31 | |
| 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. |
| 36 | const Label& label() const { return label_; } |
| 37 | |
| 38 | const ParseNode* defined_from() const { return defined_from_; } |
| 39 | void set_defined_from(const ParseNode* df) { defined_from_ = df; } |
| 40 | |
Shai Barack | 19bf826 | 2021-12-18 20:43:33 -0800 | [diff] [blame] | 41 | bool testonly() const { return testonly_; } |
| 42 | void set_testonly(bool value) { testonly_ = value; } |
| 43 | |
Nico Weber | 3f6100c | 2019-11-07 09:51:05 -0500 | [diff] [blame] | 44 | Visibility& visibility() { return 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. |
David 'Digit' Turner | 28044bc | 2019-11-28 16:39:43 +0100 | [diff] [blame] | 63 | const SourceFileSet& build_dependency_files() const { |
Nico Weber | 3f6100c | 2019-11-07 09:51:05 -0500 | [diff] [blame] | 64 | return build_dependency_files_; |
| 65 | } |
| 66 | |
David 'Digit' Turner | 28044bc | 2019-11-28 16:39:43 +0100 | [diff] [blame] | 67 | SourceFileSet& build_dependency_files() { return build_dependency_files_; } |
Nico Weber | 3f6100c | 2019-11-07 09:51:05 -0500 | [diff] [blame] | 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: |
Shai Barack | 19bf826 | 2021-12-18 20:43:33 -0800 | [diff] [blame] | 75 | bool CheckTestonly(Err* err) const; |
| 76 | |
Nico Weber | 3f6100c | 2019-11-07 09:51:05 -0500 | [diff] [blame] | 77 | const Settings* settings_; |
| 78 | Label label_; |
David 'Digit' Turner | 28044bc | 2019-11-28 16:39:43 +0100 | [diff] [blame] | 79 | SourceFileSet build_dependency_files_; |
Nico Weber | 3f6100c | 2019-11-07 09:51:05 -0500 | [diff] [blame] | 80 | const ParseNode* defined_from_; |
| 81 | |
Shai Barack | 19bf826 | 2021-12-18 20:43:33 -0800 | [diff] [blame] | 82 | bool testonly_ = false; |
Nico Weber | 3f6100c | 2019-11-07 09:51:05 -0500 | [diff] [blame] | 83 | Visibility visibility_; |
| 84 | }; |
| 85 | |
| 86 | #endif // TOOLS_GN_ITEM_H_ |