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 FillPublic(); 51 bool FillConfigs(); 52 bool FillOutputs(bool allow_substitutions); 53 bool FillCheckIncludes(); 54 bool FillOutputExtension(); 55 56 // Rrturns true if the given pattern will expand to a file in the output 57 // directory. If not, returns false and sets the error, blaming the given 58 // Value. 59 bool EnsureSubstitutionIsInOutputDir(const SubstitutionPattern& pattern, 60 const Value& original_value); 61 62 Target* target_; 63 Scope* scope_; 64 const FunctionCallNode* function_call_; 65 Err* err_; 66 67 private: 68 bool FillDependentConfigs(); // Includes all types of dependent configs. 69 bool FillData(); 70 bool FillDependencies(); // Includes data dependencies. 71 bool FillMetadata(); 72 bool FillTestonly(); 73 bool FillAssertNoDeps(); 74 bool FillWriteRuntimeDeps(); 75 76 // Reads configs/deps from the given var name, and uses the given setting on 77 // the target to save them. 78 bool FillGenericConfigs(const char* var_name, 79 UniqueVector<LabelConfigPair>* dest); 80 bool FillGenericDeps(const char* var_name, LabelTargetVector* dest); 81 82 TargetGenerator(const TargetGenerator&) = delete; 83 TargetGenerator& operator=(const TargetGenerator&) = delete; 84 }; 85 86 #endif // TOOLS_GN_TARGET_GENERATOR_H_ 87