OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/json_project_writer.h" | 5 #include "tools/gn/json_project_writer.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 // in the generated project (and thus stability of the file generated). | 75 // in the generated project (and thus stability of the file generated). |
76 std::sort(targets->begin(), targets->end(), | 76 std::sort(targets->begin(), targets->end(), |
77 [](const Target* a, const Target* b) { | 77 [](const Target* a, const Target* b) { |
78 return a->label().name() < b->label().name(); | 78 return a->label().name() < b->label().name(); |
79 }); | 79 }); |
80 | 80 |
81 return true; | 81 return true; |
82 } | 82 } |
83 | 83 |
84 std::string RenderJSON(const BuildSettings* build_settings, | 84 std::string RenderJSON(const BuildSettings* build_settings, |
85 const Builder* builder, | 85 const Builder& builder, |
86 std::vector<const Target*>& all_targets) { | 86 std::vector<const Target*>& all_targets) { |
87 Label default_toolchain_label; | 87 Label default_toolchain_label; |
88 | 88 |
89 auto targets = base::WrapUnique(new base::DictionaryValue()); | 89 auto targets = base::WrapUnique(new base::DictionaryValue()); |
90 for (const auto* target : all_targets) { | 90 for (const auto* target : all_targets) { |
91 if (default_toolchain_label.is_null()) | 91 if (default_toolchain_label.is_null()) |
92 default_toolchain_label = target->settings()->default_toolchain_label(); | 92 default_toolchain_label = target->settings()->default_toolchain_label(); |
93 auto description = | 93 auto description = |
94 DescBuilder::DescriptionForTarget(target, "", false, false, false); | 94 DescBuilder::DescriptionForTarget(target, "", false, false, false); |
95 // Outputs need to be asked for separately. | 95 // Outputs need to be asked for separately. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 return false; | 160 return false; |
161 } | 161 } |
162 | 162 |
163 return true; | 163 return true; |
164 } | 164 } |
165 | 165 |
166 } // namespace | 166 } // namespace |
167 | 167 |
168 bool JSONProjectWriter::RunAndWriteFiles( | 168 bool JSONProjectWriter::RunAndWriteFiles( |
169 const BuildSettings* build_settings, | 169 const BuildSettings* build_settings, |
170 const Builder* builder, | 170 const Builder& builder, |
171 const std::string& file_name, | 171 const std::string& file_name, |
172 const std::string& exec_script, | 172 const std::string& exec_script, |
173 const std::string& exec_script_extra_args, | 173 const std::string& exec_script_extra_args, |
174 const std::string& dir_filter_string, | 174 const std::string& dir_filter_string, |
175 bool quiet, | 175 bool quiet, |
176 Err* err) { | 176 Err* err) { |
177 SourceFile output_file = build_settings->build_dir().ResolveRelativeFile( | 177 SourceFile output_file = build_settings->build_dir().ResolveRelativeFile( |
178 Value(nullptr, file_name), err); | 178 Value(nullptr, file_name), err); |
179 if (output_file.is_null()) { | 179 if (output_file.is_null()) { |
180 return false; | 180 return false; |
181 } | 181 } |
182 | 182 |
183 base::FilePath output_path = build_settings->GetFullPath(output_file); | 183 base::FilePath output_path = build_settings->GetFullPath(output_file); |
184 | 184 |
185 std::vector<const Target*> all_targets = builder->GetAllResolvedTargets(); | 185 std::vector<const Target*> all_targets = builder.GetAllResolvedTargets(); |
186 std::vector<const Target*> targets; | 186 std::vector<const Target*> targets; |
187 if (!FilterTargets(build_settings, all_targets, &targets, dir_filter_string, | 187 if (!FilterTargets(build_settings, all_targets, &targets, dir_filter_string, |
188 err)) { | 188 err)) { |
189 return false; | 189 return false; |
190 } | 190 } |
191 | 191 |
192 std::string json = RenderJSON(build_settings, builder, targets); | 192 std::string json = RenderJSON(build_settings, builder, targets); |
193 if (!ContentsEqual(output_path, json)) { | 193 if (!ContentsEqual(output_path, json)) { |
194 if (!WriteFileIfChanged(output_path, json, err)) { | 194 if (!WriteFileIfChanged(output_path, json, err)) { |
195 return false; | 195 return false; |
(...skipping 12 matching lines...) Expand all Loading... |
208 script_file = SourceFile(exec_script); | 208 script_file = SourceFile(exec_script); |
209 } | 209 } |
210 base::FilePath script_path = build_settings->GetFullPath(script_file); | 210 base::FilePath script_path = build_settings->GetFullPath(script_file); |
211 return InvokePython(build_settings, script_path, exec_script_extra_args, | 211 return InvokePython(build_settings, script_path, exec_script_extra_args, |
212 output_path, quiet, err); | 212 output_path, quiet, err); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 return true; | 216 return true; |
217 } | 217 } |
OLD | NEW |