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 #include "tools/gn/gyp_target_writer.h"
9 #include "base/file_util.h"
10 #include "base/files/file_path.h"
11 #include "tools/gn/build_settings.h"
12 #include "tools/gn/filesystem_utils.h"
13 #include "tools/gn/gyp_binary_target_writer.h"
14 #include "tools/gn/scheduler.h"
15 #include "tools/gn/settings.h"
16 #include "tools/gn/target.h"
18 GypTargetWriter::GypTargetWriter(const Target
* target
, std::ostream
& out
)
19 : settings_(target
->settings()),
24 GypTargetWriter::~GypTargetWriter() {
28 void GypTargetWriter::WriteFile(const SourceFile
& gyp_file
,
29 const std::vector
<TargetGroup
>& targets
,
33 const BuildSettings
* debug_build_settings
=
34 targets
[0].debug
->settings()->build_settings();
36 std::stringstream file
;
37 file
<< "# Generated by GN. Do not edit.\n\n";
39 file
<< " 'skip_includes': 1,\n";
41 if (targets
[0].debug
->settings()->IsMac()) {
42 // Global settings for make/ninja. This must match common.gypi :(
43 file
<< " 'make_global_settings': [\n";
44 file
<< " ['CC', 'third_party/llvm-build/Release+Asserts/bin/clang'],\n";
46 " ['CXX', 'third_party/llvm-build/Release+Asserts/bin/clang++'],\n";
47 file
<< " ['CC.host', '$(CC)'],\n";
48 file
<< " ['CXX.host', '$(CXX)'],\n";
51 // TODO(brettw) android.
53 file
<< " 'targets': [\n";
55 for (size_t i
= 0; i
< targets
.size(); i
++) {
56 switch (targets
[i
].debug
->output_type()) {
57 case Target::COPY_FILES
:
60 break; // TODO(brettw)
61 case Target::EXECUTABLE
:
62 case Target::STATIC_LIBRARY
:
63 case Target::SHARED_LIBRARY
:
64 case Target::SOURCE_SET
: {
65 GypBinaryTargetWriter
writer(targets
[i
], file
);
76 base::FilePath gyp_file_path
= debug_build_settings
->GetFullPath(gyp_file
);
77 std::string contents
= file
.str();
78 file_util::WriteFile(gyp_file_path
, contents
.c_str(),
79 static_cast<int>(contents
.size()));