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.
5 #ifndef TOOLS_GN_GYP_TARGET_WRITER_H_
6 #define TOOLS_GN_GYP_TARGET_WRITER_H_
11 #include "base/basictypes.h"
12 #include "tools/gn/gyp_helper.h"
13 #include "tools/gn/path_output.h"
22 class GypTargetWriter {
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;
35 const BuilderRecord* debug;
36 const BuilderRecord* release;
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
41 const BuilderRecord* host_debug;
42 const BuilderRecord* host_release;
44 // On Windows, we do both 32-bit and 64-bit builds. Null on non-Windows.
45 const BuilderRecord* debug64;
46 const BuilderRecord* release64;
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
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;
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;
65 GypTargetWriter(const Target* target,
66 const Toolchain* toolchain,
67 const SourceDir& gyp_dir,
69 virtual ~GypTargetWriter();
71 static void WriteFile(const SourceFile& gyp_file,
72 const std::vector<TargetGroup>& targets,
73 const Toolchain* debug_toolchain,
76 virtual void Run() = 0;
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);
83 static const int kExtraIndent = 2;
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.
92 PathOutput path_output_;
95 DISALLOW_COPY_AND_ASSIGN(GypTargetWriter);
98 #endif // TOOLS_GN_GYP_TARGET_WRITER_H_