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