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/basictypes.h" 12#include "base/memory/scoped_ptr.h" 13#include "tools/gn/source_dir.h" 14#include "tools/gn/target.h" 15 16class BuildSettings; 17class Err; 18class FunctionCallNode; 19class Location; 20class Scope; 21class Value; 22 23// Fills the variables in a Target object from a Scope (the result of a script 24// execution). Target-type-specific derivations of this class will be used 25// for each different type of function call. This class implements the common 26// behavior. 27class TargetGenerator { 28 public: 29 TargetGenerator(Target* target, 30 Scope* scope, 31 const FunctionCallNode* function_call, 32 Err* err); 33 ~TargetGenerator(); 34 35 void Run(); 36 37 // The function call is the parse tree node that invoked the target. 38 // err() will be set on failure. 39 static void GenerateTarget(Scope* scope, 40 const FunctionCallNode* function_call, 41 const std::vector<Value>& args, 42 const std::string& output_type, 43 Err* err); 44 45 protected: 46 // Derived classes implement this to do type-specific generation. 47 virtual void DoRun() = 0; 48 49 const BuildSettings* GetBuildSettings() const; 50 51 void FillSources(); 52 void FillSourcePrereqs(); 53 void FillConfigs(); 54 void FillExternal(); 55 void FillOutputs(); 56 57 Target* target_; 58 Scope* scope_; 59 const FunctionCallNode* function_call_; 60 Err* err_; 61 62 private: 63 void FillDependentConfigs(); // Includes all types of dependent configs. 64 void FillData(); 65 void FillDependencies(); // Includes data dependencies. 66 void FillGypFile(); 67 void FillHardDep(); 68 69 // Reads configs/deps from the given var name, and uses the given setting on 70 // the target to save them. 71 void FillGenericConfigs(const char* var_name, LabelConfigVector* dest); 72 void FillGenericDeps(const char* var_name, LabelTargetVector* dest); 73 74 void FillForwardDependentConfigs(); 75 76 DISALLOW_COPY_AND_ASSIGN(TargetGenerator); 77}; 78 79#endif // TOOLS_GN_TARGET_GENERATOR_H_ 80