Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / tools / gn / gyp_target_writer.h
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_GYP_TARGET_WRITER_H_
6 #define TOOLS_GN_GYP_TARGET_WRITER_H_
7
8 #include <iosfwd>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "tools/gn/gyp_helper.h"
13 #include "tools/gn/path_output.h"
14
15 class BuilderRecord;
16 class Err;
17 class Settings;
18 class SourceFile;
19 class Target;
20 class Toolchain;
21
22 class GypTargetWriter {
23  public:
24   struct TargetGroup {
25     TargetGroup();
26
27     // Returns "a" record associated with this group. This is used when getting
28     // general things like the sources list that should be the same across all
29     // records in a group.
30     const BuilderRecord* get() const {
31       // We assume we always have either a host or a target debug build.
32       return debug ? debug : host_debug;
33     }
34
35     const BuilderRecord* debug;
36     const BuilderRecord* release;
37
38     // When the main compile is targeting a different architecture, these will
39     // contain the builds with the host system's toolchain. Only supported on
40     // Linux.
41     const BuilderRecord* host_debug;
42     const BuilderRecord* host_release;
43
44     // On Windows, we do both 32-bit and 64-bit builds. Null on non-Windows.
45     const BuilderRecord* debug64;
46     const BuilderRecord* release64;
47
48     // On Mac/iOS, there are some nontrivial differences between the GYP Ninja
49     // build and the GYP XCode build. In GYP, these are parameterized as
50     // conditions using the generator flag. To emulate this, we have different
51     // builds for the XCode and Ninja versions of the GYP file, and the
52     // generator wraps everything in a big condition so that GYP does the right
53     // thing.
54     //
55     // These refer to the GYP-XCode build. The "regular" debug and release
56     // targets above refer to the GYP-Ninja build.
57     const BuilderRecord* xcode_debug;
58     const BuilderRecord* xcode_release;
59
60     // Optional host versions of the xcode config when cross-compiling to iOS.
61     const BuilderRecord* xcode_host_debug;
62     const BuilderRecord* xcode_host_release;
63   };
64
65   GypTargetWriter(const Target* target,
66                   const Toolchain* toolchain,
67                   const SourceDir& gyp_dir,
68                   std::ostream& out);
69   virtual ~GypTargetWriter();
70
71   static void WriteFile(const SourceFile& gyp_file,
72                         const std::vector<TargetGroup>& targets,
73                         const Toolchain* debug_toolchain,
74                         Err* err);
75
76   virtual void Run() = 0;
77
78  protected:
79   // Writes the given number of spaces to the output stream and returns it.
80   std::ostream& Indent(int spaces);
81   static std::ostream& Indent(std::ostream& out, int spaces);
82
83   static const int kExtraIndent = 2;
84
85   const Settings* settings_;  // Non-owning.
86   const Target* target_;  // Non-owning.
87   const Toolchain* toolchain_;  // Toolchain corresponding to target_.
88   SourceDir gyp_dir_;  // Dir of GYP file.
89   std::ostream& out_;
90
91   GypHelper helper_;
92   PathOutput path_output_;
93
94  private:
95   DISALLOW_COPY_AND_ASSIGN(GypTargetWriter);
96 };
97
98 #endif  // TOOLS_GN_GYP_TARGET_WRITER_H_