• 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_TARGET_GENERATOR_H_
6 #define TOOLS_GN_TARGET_GENERATOR_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/macros.h"
12 #include "gn/label_ptr.h"
13 #include "gn/unique_vector.h"
14 
15 class BuildSettings;
16 class Err;
17 class FunctionCallNode;
18 class Scope;
19 class SubstitutionPattern;
20 class Value;
21 
22 // Fills the variables in a Target object from a Scope (the result of a script
23 // execution). Target-type-specific derivations of this class will be used
24 // for each different type of function call. This class implements the common
25 // behavior.
26 class TargetGenerator {
27  public:
28   TargetGenerator(Target* target,
29                   Scope* scope,
30                   const FunctionCallNode* function_call,
31                   Err* err);
32   virtual ~TargetGenerator();
33 
34   void Run();
35 
36   // The function call is the parse tree node that invoked the target.
37   // err() will be set on failure.
38   static void GenerateTarget(Scope* scope,
39                              const FunctionCallNode* function_call,
40                              const std::vector<Value>& args,
41                              const std::string& output_type,
42                              Err* err);
43 
44  protected:
45   // Derived classes implement this to do type-specific generation.
46   virtual void DoRun() = 0;
47 
48   const BuildSettings* GetBuildSettings() const;
49 
50   virtual bool FillSources();
51   bool FillPublic();
52   bool FillConfigs();
53   bool FillOutputs(bool allow_substitutions);
54   bool FillCheckIncludes();
55   bool FillOutputExtension();
56 
57   // Rrturns true if the given pattern will expand to a file in the output
58   // directory. If not, returns false and sets the error, blaming the given
59   // Value.
60   bool EnsureSubstitutionIsInOutputDir(const SubstitutionPattern& pattern,
61                                        const Value& original_value);
62 
63   Target* target_;
64   Scope* scope_;
65   const FunctionCallNode* function_call_;
66   Err* err_;
67 
68  private:
69   bool FillDependentConfigs();  // Includes all types of dependent configs.
70   bool FillData();
71   bool FillDependencies();  // Includes data dependencies.
72   bool FillMetadata();
73   bool FillTestonly();
74   bool FillAssertNoDeps();
75   bool FillWriteRuntimeDeps();
76 
77   // Reads configs/deps from the given var name, and uses the given setting on
78   // the target to save them.
79   bool FillGenericConfigs(const char* var_name,
80                           UniqueVector<LabelConfigPair>* dest);
81   bool FillGenericDeps(const char* var_name, LabelTargetVector* dest);
82 
83   DISALLOW_COPY_AND_ASSIGN(TargetGenerator);
84 };
85 
86 #endif  // TOOLS_GN_TARGET_GENERATOR_H_
87