• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
checkflag()45   bool checkflag() const { return checkflag_; }
set_checkflag(bool value)46   void set_checkflag(bool value) { checkflag_ = value; }
47 
visibility()48   Visibility& visibility() { return visibility_; }
visibility()49   const Visibility& visibility() const { return visibility_; }
50 
51   // Manual RTTI.
52   virtual Config* AsConfig();
53   virtual const Config* AsConfig() const;
54   virtual Pool* AsPool();
55   virtual const Pool* AsPool() const;
56   virtual Target* AsTarget();
57   virtual const Target* AsTarget() const;
58   virtual Toolchain* AsToolchain();
59   virtual const Toolchain* AsToolchain() const;
60 
61   // Returns a name like "target" or "config" for the type of item this is, to
62   // be used in logging and error messages.
63   std::string GetItemTypeName() const;
64 
65   // Returns the set of build files that may affect this item, please refer to
66   // Scope for how this is determined.
build_dependency_files()67   const SourceFileSet& build_dependency_files() const {
68     return build_dependency_files_;
69   }
70 
build_dependency_files()71   SourceFileSet& build_dependency_files() { return build_dependency_files_; }
72 
73   // Called when this item is resolved, meaning it and all of its dependents
74   // have no unresolved deps. Returns true on success. Sets the error and
75   // returns false on failure.
76   virtual bool OnResolved(Err* err);
77 
ohos_component()78   const OhosComponent *ohos_component() const { return component; }
79 
80  private:
81   bool CheckTestonly(Err* err) const;
82 
83   const Settings* settings_;
84   Label label_;
85   SourceFileSet build_dependency_files_;
86   const ParseNode* defined_from_;
87 
88   bool testonly_ = false;
89   bool checkflag_ = true;
90   Visibility visibility_;
91 
92   const OhosComponent *component;
93 };
94 
95 #endif  // TOOLS_GN_ITEM_H_
96