blob: dd1a60662fbf1376025c50946693155313c81541 [file] [log] [blame]
Nico Weber3f6100c2019-11-07 09:51:05 -05001// 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
15class Config;
16class ParseNode;
17class Pool;
18class Settings;
19class SourceFile;
20class Target;
21class Toolchain;
22
23// A named item (target, config, etc.) that participates in the dependency
24// graph.
25class Item {
26 public:
27 Item(const Settings* settings,
28 const Label& label,
David 'Digit' Turner28044bc2019-11-28 16:39:43 +010029 const SourceFileSet& build_dependency_files = {});
Nico Weber3f6100c2019-11-07 09:51:05 -050030 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 Barack19bf8262021-12-18 20:43:33 -080041 bool testonly() const { return testonly_; }
42 void set_testonly(bool value) { testonly_ = value; }
43
Nico Weber3f6100c2019-11-07 09:51:05 -050044 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' Turner28044bc2019-11-28 16:39:43 +010063 const SourceFileSet& build_dependency_files() const {
Nico Weber3f6100c2019-11-07 09:51:05 -050064 return build_dependency_files_;
65 }
66
David 'Digit' Turner28044bc2019-11-28 16:39:43 +010067 SourceFileSet& build_dependency_files() { return build_dependency_files_; }
Nico Weber3f6100c2019-11-07 09:51:05 -050068
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 Barack19bf8262021-12-18 20:43:33 -080075 bool CheckTestonly(Err* err) const;
76
Nico Weber3f6100c2019-11-07 09:51:05 -050077 const Settings* settings_;
78 Label label_;
David 'Digit' Turner28044bc2019-11-28 16:39:43 +010079 SourceFileSet build_dependency_files_;
Nico Weber3f6100c2019-11-07 09:51:05 -050080 const ParseNode* defined_from_;
81
Shai Barack19bf8262021-12-18 20:43:33 -080082 bool testonly_ = false;
Nico Weber3f6100c2019-11-07 09:51:05 -050083 Visibility visibility_;
84};
85
86#endif // TOOLS_GN_ITEM_H_