Home | History | Annotate | Download | only in gn
      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/gtest_prod_util.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "tools/gn/source_dir.h"
     15 #include "tools/gn/target.h"
     16 
     17 class BuildSettings;
     18 class Err;
     19 class Location;
     20 class Scope;
     21 class Token;
     22 class Value;
     23 
     24 // Creates Target objects from a Scope (the result of a script execution).
     25 class TargetGenerator {
     26  public:
     27   TargetGenerator(Target* target,
     28                   Scope* scope,
     29                   const Token& function_token,
     30                   const std::vector<Value>& args,
     31                   const std::string& output_type,
     32                   Err* err);
     33   ~TargetGenerator();
     34 
     35   void Run();
     36 
     37   // The function token is the token of the function name of the generator for
     38   // this target. err() will be set on failure.
     39   static void GenerateTarget(Scope* scope,
     40                              const Token& function_token,
     41                              const std::vector<Value>& args,
     42                              const std::string& output_type,
     43                              Err* err);
     44 
     45  private:
     46   // Sets err_ on failure.
     47   Target::OutputType GetOutputType() const;
     48 
     49   // Reads configs/deps from the given var name, and uses the given setting on
     50   // the target to save them.
     51   void FillGenericConfigs(const char* var_name,
     52                           void (Target::*setter)(std::vector<const Config*>*));
     53   void FillGenericDeps(const char* var_name,
     54                        void (Target::*setter)(std::vector<const Target*>*));
     55 
     56   void FillConfigs();
     57   void FillAllDependentConfigs();
     58   void FillDirectDependentConfigs();
     59   void FillSources();
     60   void FillData();
     61   void FillDependencies();
     62   void FillDataDependencies();
     63   void FillDestDir();
     64   void FillScript();
     65   void FillScriptArgs();
     66   void FillOutputs();
     67 
     68   const BuildSettings* GetBuildSettings() const;
     69 
     70   Target* target_;
     71   Scope* scope_;
     72   const Token& function_token_;
     73   std::vector<Value> args_;
     74   std::string output_type_;
     75   Err* err_;
     76 
     77   // Sources are relative to this. This comes from the input file which doesn't
     78   // get freed so we don't acautlly have to make a copy.
     79   const SourceDir& input_directory_;
     80 
     81   FRIEND_TEST_ALL_PREFIXES(TargetGenerator, ResolveInputPath);
     82 
     83   DISALLOW_COPY_AND_ASSIGN(TargetGenerator);
     84 };
     85 
     86 #endif  // TOOLS_GN_TARGET_GENERATOR_H_
     87