OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "tools/gn/gyp_target_writer.h" | 5 #include "tools/gn/gyp_target_writer.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "tools/gn/build_settings.h" | 11 #include "tools/gn/build_settings.h" |
12 #include "tools/gn/builder_record.h" | 12 #include "tools/gn/builder_record.h" |
13 #include "tools/gn/filesystem_utils.h" | 13 #include "tools/gn/filesystem_utils.h" |
14 #include "tools/gn/gyp_binary_target_writer.h" | 14 #include "tools/gn/gyp_binary_target_writer.h" |
| 15 #include "tools/gn/gyp_script_target_writer.h" |
15 #include "tools/gn/scheduler.h" | 16 #include "tools/gn/scheduler.h" |
16 #include "tools/gn/settings.h" | 17 #include "tools/gn/settings.h" |
17 #include "tools/gn/target.h" | 18 #include "tools/gn/target.h" |
18 | 19 |
19 GypTargetWriter::GypTargetWriter(const Target* target, std::ostream& out) | 20 GypTargetWriter::GypTargetWriter(const Target* target, |
| 21 const SourceDir& gyp_dir, |
| 22 std::ostream& out) |
20 : settings_(target->settings()), | 23 : settings_(target->settings()), |
21 target_(target), | 24 target_(target), |
22 out_(out) { | 25 gyp_dir_(gyp_dir), |
| 26 out_(out), |
| 27 // All GYP paths are relative to GYP file. |
| 28 path_output_(gyp_dir, ESCAPE_JSON, false) { |
23 } | 29 } |
24 | 30 |
25 GypTargetWriter::~GypTargetWriter() { | 31 GypTargetWriter::~GypTargetWriter() { |
26 } | 32 } |
27 | 33 |
28 // static | 34 // static |
29 void GypTargetWriter::WriteFile(const SourceFile& gyp_file, | 35 void GypTargetWriter::WriteFile(const SourceFile& gyp_file, |
30 const std::vector<TargetGroup>& targets, | 36 const std::vector<TargetGroup>& targets, |
31 Err* err) { | 37 Err* err) { |
32 if (targets.empty()) | 38 if (targets.empty()) |
(...skipping 21 matching lines...) Expand all Loading... |
54 file << " ],\n"; | 60 file << " ],\n"; |
55 } | 61 } |
56 // TODO(brettw) android. | 62 // TODO(brettw) android. |
57 | 63 |
58 file << " 'targets': [\n"; | 64 file << " 'targets': [\n"; |
59 | 65 |
60 for (size_t i = 0; i < targets.size(); i++) { | 66 for (size_t i = 0; i < targets.size(); i++) { |
61 const Target* cur = targets[i].debug->item()->AsTarget(); | 67 const Target* cur = targets[i].debug->item()->AsTarget(); |
62 switch (cur->output_type()) { | 68 switch (cur->output_type()) { |
63 case Target::COPY_FILES: | 69 case Target::COPY_FILES: |
64 case Target::CUSTOM: | 70 break; // TODO(brettw) |
| 71 case Target::CUSTOM: { |
| 72 GypScriptTargetWriter writer(targets[i], gyp_file.GetDir(), file); |
| 73 writer.Run(); |
| 74 break; |
| 75 } |
65 case Target::GROUP: | 76 case Target::GROUP: |
66 break; // TODO(brettw) | 77 break; // TODO(brettw) |
67 case Target::EXECUTABLE: | 78 case Target::EXECUTABLE: |
68 case Target::STATIC_LIBRARY: | 79 case Target::STATIC_LIBRARY: |
69 case Target::SHARED_LIBRARY: | 80 case Target::SHARED_LIBRARY: |
70 case Target::SOURCE_SET: { | 81 case Target::SOURCE_SET: { |
71 GypBinaryTargetWriter writer(targets[i], file); | 82 GypBinaryTargetWriter writer(targets[i], gyp_file.GetDir(), file); |
72 writer.Run(); | 83 writer.Run(); |
73 break; | 84 break; |
74 } | 85 } |
75 default: | 86 default: |
76 CHECK(0); | 87 CHECK(0); |
77 } | 88 } |
78 } | 89 } |
79 | 90 |
80 file << " ],\n}\n"; | 91 file << " ],\n}\n"; |
81 | 92 |
82 std::string contents = file.str(); | 93 std::string contents = file.str(); |
83 file_util::WriteFile(gyp_file_path, contents.c_str(), | 94 file_util::WriteFile(gyp_file_path, contents.c_str(), |
84 static_cast<int>(contents.size())); | 95 static_cast<int>(contents.size())); |
85 } | 96 } |
86 | 97 |
| 98 std::ostream& GypTargetWriter::Indent(int spaces) { |
| 99 return Indent(out_, spaces); |
| 100 } |
| 101 |
| 102 // static |
| 103 std::ostream& GypTargetWriter::Indent(std::ostream& out, int spaces) { |
| 104 const char kSpaces[81] = |
| 105 " " |
| 106 " "; |
| 107 CHECK(static_cast<size_t>(spaces) <= arraysize(kSpaces) - 1); |
| 108 out.write(kSpaces, spaces); |
| 109 return out; |
| 110 } |
OLD | NEW |