Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: tools/gn/desc_builder.cc

Issue 2064533002: [GN] Add JSON project writer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase, fix build, fix variable names Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <set>
6
7 #include "base/memory/ptr_util.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "tools/gn/commands.h"
10 #include "tools/gn/config.h"
11 #include "tools/gn/config_values_extractors.h"
12 #include "tools/gn/deps_iterator.h"
13 #include "tools/gn/desc_builder.h"
14 #include "tools/gn/input_file.h"
15 #include "tools/gn/parse_tree.h"
16 #include "tools/gn/runtime_deps.h"
17 #include "tools/gn/settings.h"
18 #include "tools/gn/substitution_writer.h"
19 #include "tools/gn/variables.h"
20
21 namespace {
brettw 2016/07/06 22:19:26 Somewhere (I'm thinking at the top of this file mi
22
23 std::string FormatSourceDir(const SourceDir& dir) {
24 #if defined(OS_WIN)
25 // On Windows we fix up system absolute paths to look like native ones.
26 // Internally, they'll look like "/C:\foo\bar/"
27 if (dir.is_system_absolute()) {
28 std::string buf = dir.value();
29 if (buf.size() > 3 && buf[2] == ':') {
30 buf.erase(buf.begin()); // Erase beginning slash.
31 return buf;
32 }
33 }
34 #endif
35 return dir.value();
36 }
37
38 void RecursiveCollectChildDeps(const Target* target,
39 std::set<const Target*>* result);
40
41 void RecursiveCollectDeps(const Target* target,
42 std::set<const Target*>* result) {
43 if (result->find(target) != result->end())
44 return; // Already did this target.
45 result->insert(target);
46
47 RecursiveCollectChildDeps(target, result);
48 }
49
50 void RecursiveCollectChildDeps(const Target* target,
51 std::set<const Target*>* result) {
52 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
53 RecursiveCollectDeps(pair.ptr, result);
54 }
55
56 // Common functionality for target and config description builder
57 class BaseDescBuilder {
58 public:
59 typedef std::unique_ptr<base::Value> ValuePtr;
60
61 BaseDescBuilder(const std::set<std::string>& what,
62 bool all,
63 bool tree,
64 bool blame)
65 : what_(what), all_(all), tree_(tree), blame_(blame) {}
66
67 protected:
68 virtual Label GetToolchainLabel() const = 0;
69
70 bool what(const std::string& w) const {
71 return what_.empty() || what_.find(w) != what_.end();
72 }
73
74 template <typename T>
75 ValuePtr RenderValue(const std::vector<T>& vector) {
76 auto res = new base::ListValue();
brettw 2016/07/06 22:19:26 I prefer not to have owning bare pointers floating
matt.k 2016/07/08 00:39:07 Done.
77 for (const auto& v : vector) {
78 res->Append(RenderValue(v));
79 }
80 return base::WrapUnique(res);
81 }
82
83 ValuePtr RenderValue(const std::string& s, bool optional = false) {
84 return (s.empty() && optional) ? base::Value::CreateNullValue()
85 : ValuePtr(new base::StringValue(s));
86 }
87
88 ValuePtr RenderValue(const SourceDir& d) {
89 return d.is_null() ? base::Value::CreateNullValue()
90 : ValuePtr(new base::StringValue(FormatSourceDir(d)));
91 }
92
93 ValuePtr RenderValue(const SourceFile& f) {
94 return f.is_null() ? base::Value::CreateNullValue()
95 : ValuePtr(new base::StringValue(f.value()));
96 }
97
98 ValuePtr RenderValue(const LibFile& lib) {
99 if (lib.is_source_file())
100 return RenderValue(lib.source_file());
101 else
brettw 2016/07/06 22:19:26 According to the style guide, just delete the "els
matt.k 2016/07/08 00:39:07 Done.
102 return RenderValue(lib.value());
103 }
104
105 template <class VectorType>
106 void FillInConfigVector(base::ListValue* out,
107 const VectorType& configs,
108 int indent = 0) {
109 for (const auto& config : configs) {
110 std::string name(indent * 2, ' ');
111 name.append(config.label.GetUserVisibleName(GetToolchainLabel()));
112 out->AppendString(name);
113 if (tree_) {
114 FillInConfigVector(out, config.ptr->configs(), indent + 1);
115 }
116 }
117 }
118
119 void FillInPrecompiledHeader(base::DictionaryValue* out,
120 const ConfigValues& values) {
121 if (what(variables::kPrecompiledHeader) &&
122 !values.precompiled_header().empty()) {
123 out->Set(variables::kPrecompiledHeader,
124 RenderValue(values.precompiled_header(), true));
125 }
126 if (what(variables::kPrecompiledSource) &&
127 !values.precompiled_source().is_null()) {
128 out->Set(variables::kPrecompiledSource,
129 RenderValue(values.precompiled_source()));
130 }
131 }
132
133 std::set<std::string> what_;
134 bool all_;
135 bool tree_;
136 bool blame_;
137 };
138
139 class ConfigDescBuilder : public BaseDescBuilder {
140 public:
141 ConfigDescBuilder(const Config* config, const std::set<std::string>& what)
142 : BaseDescBuilder(what, false, false, false), config_(config) {}
143
144 std::unique_ptr<base::DictionaryValue> BuildDescription() {
145 auto res = new base::DictionaryValue();
146 const ConfigValues& values = config_->resolved_values();
147
148 if (what_.empty()) {
149 res->SetString(
150 "toolchain",
151 config_->label().GetToolchainLabel().GetUserVisibleName(false));
152 }
153
154 if (what(variables::kConfigs) && !config_->configs().empty()) {
155 auto configs = new base::ListValue();
156 FillInConfigVector(configs, config_->configs().vector());
157 res->Set(variables::kConfigs, configs);
158 }
159
160 #define CONFIG_VALUE_ARRAY_HANDLER(name, type) \
161 if (what(#name)) { \
162 ValuePtr ptr = \
163 render_config_value_array<type>(values, &ConfigValues::name); \
164 if (ptr) { \
165 res->Set(#name, std::move(ptr)); \
166 } \
167 }
168 CONFIG_VALUE_ARRAY_HANDLER(arflags, std::string)
169 CONFIG_VALUE_ARRAY_HANDLER(asmflags, std::string)
170 CONFIG_VALUE_ARRAY_HANDLER(cflags, std::string)
171 CONFIG_VALUE_ARRAY_HANDLER(cflags_c, std::string)
172 CONFIG_VALUE_ARRAY_HANDLER(cflags_cc, std::string)
173 CONFIG_VALUE_ARRAY_HANDLER(cflags_objc, std::string)
174 CONFIG_VALUE_ARRAY_HANDLER(cflags_objcc, std::string)
175 CONFIG_VALUE_ARRAY_HANDLER(defines, std::string)
176 CONFIG_VALUE_ARRAY_HANDLER(include_dirs, SourceDir)
177 CONFIG_VALUE_ARRAY_HANDLER(ldflags, std::string)
178 CONFIG_VALUE_ARRAY_HANDLER(lib_dirs, SourceDir)
179 CONFIG_VALUE_ARRAY_HANDLER(libs, LibFile)
180
181 #undef CONFIG_VALUE_ARRAY_HANDLER
182
183 FillInPrecompiledHeader(res, values);
184
185 return base::WrapUnique(res);
186 }
187
188 protected:
189 Label GetToolchainLabel() const override {
190 return config_->label().GetToolchainLabel();
191 }
192
193 private:
194 template <typename T>
195 ValuePtr render_config_value_array(
196 const ConfigValues& values,
197 const std::vector<T>& (ConfigValues::*getter)() const) {
198 auto res = base::WrapUnique(new base::ListValue());
199
200 for (const T& cur : (values.*getter)()) {
201 res->Append(RenderValue(cur));
202 }
203
204 return res->empty() ? nullptr : std::move(res);
205 }
206
207 const Config* config_;
208 };
209
210 class TargetDescBuilder : public BaseDescBuilder {
211 public:
212 TargetDescBuilder(const Target* target,
213 const std::set<std::string>& what,
214 bool all,
215 bool tree,
216 bool blame)
217 : BaseDescBuilder(what, all, tree, blame), target_(target) {}
218
219 std::unique_ptr<base::DictionaryValue> BuildDescription() {
220 auto res = new base::DictionaryValue();
221 bool is_binary_output = target_->IsBinary();
222
223 if (what_.empty()) {
224 res->SetString(
225 "type", DescBuilder::GetStringForOutputType(target_->output_type()));
226 res->SetString(
227 "toolchain",
228 target_->label().GetToolchainLabel().GetUserVisibleName(false));
229 }
230
231 // General target meta variables.
232 if (what(variables::kVisibility)) {
233 res->Set(variables::kVisibility, target_->visibility().AsValue());
234 }
235 if (what(variables::kTestonly)) {
236 res->SetBoolean(variables::kTestonly, target_->testonly());
237 }
238
239 if (is_binary_output) {
240 if (what(variables::kCheckIncludes)) {
241 res->SetBoolean(variables::kCheckIncludes, target_->check_includes());
242 }
243 if (what(variables::kAllowCircularIncludesFrom)) {
244 auto labels = new base::ListValue();
245 for (const auto& cur : target_->allow_circular_includes_from()) {
246 labels->AppendString(cur.GetUserVisibleName(GetToolchainLabel()));
247 }
248 res->Set(variables::kAllowCircularIncludesFrom, labels);
249 }
250 }
251
252 if (what(variables::kSources) && !target_->sources().empty()) {
253 res->Set(variables::kSources, RenderValue(target_->sources()));
254 }
255
256 if (what(variables::kOutputName) && !target_->output_name().empty()) {
257 res->SetString(variables::kOutputName, target_->output_name());
258 }
259
260 if (what(variables::kOutputDir) && !target_->output_dir().is_null()) {
261 res->Set(variables::kOutputDir, RenderValue(target_->output_dir()));
262 }
263
264 if (what(variables::kOutputExtension) && target_->output_extension_set()) {
265 res->SetString(variables::kOutputExtension, target_->output_extension());
266 }
267
268 if (what(variables::kPublic)) {
269 if (target_->all_headers_public())
270 res->SetString(variables::kPublic, "*");
271 else
272 res->Set(variables::kPublic, RenderValue(target_->public_headers()));
273 }
274
275 if (what(variables::kInputs) && !target_->inputs().empty()) {
276 res->Set(variables::kInputs, RenderValue(target_->inputs()));
277 }
278
279 if (is_binary_output && what(variables::kConfigs) &&
280 !target_->configs().empty()) {
281 auto configs = new base::ListValue();
282 FillInConfigVector(configs, target_->configs().vector());
283 res->Set(variables::kConfigs, configs);
284 }
285
286 if (what(variables::kPublicConfigs) && !target_->public_configs().empty()) {
287 auto configs = new base::ListValue();
288 FillInConfigVector(configs, target_->public_configs());
289 res->Set(variables::kPublicConfigs, configs);
290 }
291
292 if (what(variables::kAllDependentConfigs) &&
293 !target_->all_dependent_configs().empty()) {
294 auto configs = new base::ListValue();
295 FillInConfigVector(configs, target_->all_dependent_configs());
296 res->Set(variables::kAllDependentConfigs, configs);
297 }
298
299 // Action
300 if (target_->output_type() == Target::ACTION ||
301 target_->output_type() == Target::ACTION_FOREACH) {
302 if (what(variables::kScript)) {
303 res->SetString(variables::kScript,
304 target_->action_values().script().value());
305 }
306 if (what(variables::kArgs)) {
307 auto args = new base::ListValue();
308 for (const auto& elem : target_->action_values().args().list()) {
309 args->AppendString(elem.AsString());
310 }
311 res->Set(variables::kArgs, args);
312 }
313 if (what(variables::kDepfile) &&
314 !target_->action_values().depfile().empty()) {
315 res->SetString(variables::kDepfile,
316 target_->action_values().depfile().AsString());
317 }
318 }
319
320 if (target_->output_type() != Target::SOURCE_SET &&
321 target_->output_type() != Target::GROUP) {
322 if (what(variables::kOutputs)) {
323 FillInOutputs(res);
324 }
325 }
326
327 // Source outputs are only included when specifically asked for it
328 if (what_.find("source_outputs") != what_.end()) {
329 FillInSourceOutputs(res);
330 }
331
332 if (target_->output_type() == Target::CREATE_BUNDLE &&
333 what("bundle_data")) {
334 FillInBundle(res);
335 }
336
337 if (is_binary_output) {
338 #define CONFIG_VALUE_ARRAY_HANDLER(name, type) \
339 if (what(#name)) { \
340 ValuePtr ptr = RenderConfigValues<type>(&ConfigValues::name); \
341 if (ptr) { \
342 res->Set(#name, std::move(ptr)); \
343 } \
344 }
345 CONFIG_VALUE_ARRAY_HANDLER(arflags, std::string)
346 CONFIG_VALUE_ARRAY_HANDLER(asmflags, std::string)
347 CONFIG_VALUE_ARRAY_HANDLER(cflags, std::string)
348 CONFIG_VALUE_ARRAY_HANDLER(cflags_c, std::string)
349 CONFIG_VALUE_ARRAY_HANDLER(cflags_cc, std::string)
350 CONFIG_VALUE_ARRAY_HANDLER(cflags_objc, std::string)
351 CONFIG_VALUE_ARRAY_HANDLER(cflags_objcc, std::string)
352 CONFIG_VALUE_ARRAY_HANDLER(defines, std::string)
353 CONFIG_VALUE_ARRAY_HANDLER(include_dirs, SourceDir)
354 CONFIG_VALUE_ARRAY_HANDLER(ldflags, std::string)
355 #undef CONFIG_VALUE_ARRAY_HANDLER
356
357 // Libs and lib_dirs are handled specially below.
358
359 FillInPrecompiledHeader(res, target_->config_values());
360 }
361
362 if (what(variables::kDeps)) {
363 res->Set(variables::kDeps, RenderDeps());
364 }
365
366 // Runtime deps are special, print only when explicitly asked for and not in
367 // overview mode.
368 if (what_.find("runtime_deps") != what_.end()) {
369 res->Set("runtime_deps", RenderRuntimeDeps());
370 }
371
372 // libs and lib_dirs are special in that they're inherited. We don't
373 // currently
374 // implement a blame feature for this since the bottom-up inheritance makes
375 // this difficult.
376
377 // Libs can be part of any target and get recursively pushed up the chain,
378 // so display them regardless of target type.
379 if (what(variables::kLibs)) {
380 const OrderedSet<LibFile>& all_libs = target_->all_libs();
381 if (!all_libs.empty()) {
382 auto libs = new base::ListValue();
383 for (size_t i = 0; i < all_libs.size(); i++)
384 libs->AppendString(all_libs[i].value());
385 res->Set(variables::kLibs, libs);
386 }
387 }
388
389 if (what(variables::kLibDirs)) {
390 const OrderedSet<SourceDir>& all_lib_dirs = target_->all_lib_dirs();
391 if (!all_lib_dirs.empty()) {
392 auto lib_dirs = new base::ListValue();
393 for (size_t i = 0; i < all_lib_dirs.size(); i++)
394 lib_dirs->AppendString(FormatSourceDir(all_lib_dirs[i]));
395 res->Set(variables::kLibDirs, lib_dirs);
396 }
397 }
398
399 return base::WrapUnique(res);
400 }
401
402 private:
403 // Prints dependencies of the given target (not the target itself). If the
404 // set is non-null, new targets encountered will be added to the set, and if
405 // a dependency is in the set already, it will not be recused into. When the
406 // set is null, all dependencies will be printed.
407 void RecursivePrintDeps(base::ListValue* out,
408 const Target* target,
409 std::set<const Target*>* seen_targets,
410 int indent_level) {
411 // Combine all deps into one sorted list.
412 std::vector<LabelTargetPair> sorted_deps;
413 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
414 sorted_deps.push_back(pair);
415 std::sort(sorted_deps.begin(), sorted_deps.end(),
416 LabelPtrLabelLess<Target>());
417
418 std::string indent(indent_level * 2, ' ');
419
420 for (const auto& pair : sorted_deps) {
421 const Target* cur_dep = pair.ptr;
422 std::string str =
423 indent + cur_dep->label().GetUserVisibleName(GetToolchainLabel());
424
425 bool print_children = true;
426 if (seen_targets) {
427 if (seen_targets->find(cur_dep) == seen_targets->end()) {
428 // New target, mark it visited.
429 seen_targets->insert(cur_dep);
430 } else {
431 // Already seen.
432 print_children = false;
433 // Only print "..." if something is actually elided, which means that
434 // the current target has children.
435 if (!cur_dep->public_deps().empty() ||
436 !cur_dep->private_deps().empty() || !cur_dep->data_deps().empty())
437 str += "...";
438 }
439 }
440
441 out->AppendString(str);
442
443 if (print_children) {
444 RecursivePrintDeps(out, cur_dep, seen_targets, indent_level + 1);
445 }
446 }
447 }
448
449 ValuePtr RenderDeps() {
450 auto res = new base::ListValue();
451
452 // Tree mode is separate.
453 if (tree_) {
454 if (all_) {
455 // Show all tree deps with no eliding.
456 RecursivePrintDeps(res, target_, nullptr, 0);
457 } else {
458 // Don't recurse into duplicates.
459 std::set<const Target*> seen_targets;
460 RecursivePrintDeps(res, target_, &seen_targets, 0);
461 }
462 } else { // not tree
463
464 // Collect the deps to display.
465 if (all_) {
466 // Show all dependencies.
467 std::set<const Target*> all_deps;
468 RecursiveCollectChildDeps(target_, &all_deps);
469 commands::FilterAndPrintTargetSet(all_deps, res);
470 } else {
471 // Show direct dependencies only.
472 std::vector<const Target*> deps;
473 for (const auto& pair : target_->GetDeps(Target::DEPS_ALL))
474 deps.push_back(pair.ptr);
475 std::sort(deps.begin(), deps.end());
476 commands::FilterAndPrintTargets(&deps, res);
477 }
478 }
479
480 return base::WrapUnique(res);
481 }
482
483 ValuePtr RenderRuntimeDeps() {
484 auto res = new base::ListValue();
485
486 const Target* previous_from = NULL;
487 for (const auto& pair : ComputeRuntimeDeps(target_)) {
488 std::string str;
489 if (blame_) {
490 // Generally a target's runtime deps will be listed sequentially, so
491 // group them and don't duplicate the "from" label for two in a row.
492 if (previous_from == pair.second) {
493 str = " ";
494 } else {
495 previous_from = pair.second;
496 res->AppendString(
497 str + "From " +
498 pair.second->label().GetUserVisibleName(GetToolchainLabel()));
499 str = " ";
500 }
501 }
502
503 res->AppendString(str + pair.first.value());
504 }
505
506 return base::WrapUnique(res);
507 }
508
509 void FillInSourceOutputs(base::DictionaryValue* res) {
510 base::DictionaryValue* dict = nullptr;
511 for (const auto& source : target_->sources()) {
512 std::vector<OutputFile> outputs;
513 Toolchain::ToolType tool_type = Toolchain::TYPE_NONE;
514 if (target_->GetOutputFilesForSource(source, &tool_type, &outputs)) {
515 if (!dict) {
516 dict = new base::DictionaryValue();
517 res->Set("source_outputs", dict);
518 }
519 auto list = new base::ListValue();
520 dict->SetWithoutPathExpansion(source.value(), list);
521 for (const auto& output : outputs) {
522 list->AppendString(output.value());
523 }
524 }
525 }
526 }
527
528 void FillInBundle(base::DictionaryValue* res) {
529 auto data = new base::DictionaryValue();
530 const BundleData& bundle_data = target_->bundle_data();
531 const Settings* settings = target_->settings();
532 BundleData::SourceFiles sources;
533 bundle_data.GetSourceFiles(&sources);
534 data->Set("source_files", RenderValue(sources));
535 data->SetString("root_dir_output",
536 bundle_data.GetBundleRootDirOutput(settings).value());
537 data->Set("root_dir", RenderValue(bundle_data.root_dir()));
538 data->Set("resources_dir", RenderValue(bundle_data.resources_dir()));
539 data->Set("executable_dir", RenderValue(bundle_data.executable_dir()));
540 data->Set("plugins_dir", RenderValue(bundle_data.plugins_dir()));
541 data->SetString("product_type", bundle_data.product_type());
542
543 auto deps = new base::ListValue();
544 for (const auto* dep : bundle_data.bundle_deps()) {
545 deps->AppendString(dep->label().GetUserVisibleName(GetToolchainLabel()));
546 }
547 data->Set("deps", deps);
548 res->Set("bundle_data", data);
549 }
550
551 void FillInOutputs(base::DictionaryValue* res) {
552 if (target_->output_type() == Target::ACTION) {
553 auto list = new base::ListValue();
554 for (const auto& elem : target_->action_values().outputs().list()) {
555 list->AppendString(elem.AsString());
556 }
557 res->Set(variables::kOutputs, list);
558 } else if (target_->output_type() == Target::CREATE_BUNDLE) {
559 std::vector<SourceFile> output_files;
560 target_->bundle_data().GetOutputsAsSourceFiles(target_->settings(),
561 &output_files);
562 res->Set(variables::kOutputs, RenderValue(output_files));
563 } else if (target_->output_type() == Target::ACTION_FOREACH) {
brettw 2016/07/06 22:19:26 When I tried your patch I got an assertion in the
matt.k 2016/07/08 00:39:07 Done.
564 const SubstitutionList& outputs = target_->action_values().outputs();
565 if (!outputs.required_types().empty()) {
566 auto patterns = new base::ListValue();
567 for (const auto& elem : outputs.list()) {
568 patterns->AppendString(elem.AsString());
569 }
570 res->Set("output_patterns", patterns);
571 }
572 std::vector<SourceFile> output_files;
573 SubstitutionWriter::ApplyListToSources(target_->settings(), outputs,
574 target_->sources(), &output_files);
575 res->Set(variables::kOutputs, RenderValue(output_files));
576 } else {
577 DCHECK(target_->IsBinary());
578 const Tool* tool =
579 target_->toolchain()->GetToolForTargetFinalOutput(target_);
580
581 std::vector<OutputFile> output_files;
582 SubstitutionWriter::ApplyListToLinkerAsOutputFile(
583 target_, tool, tool->outputs(), &output_files);
584 std::vector<SourceFile> output_files_as_source_file;
585 for (const OutputFile& output_file : output_files) {
586 output_files_as_source_file.push_back(
587 output_file.AsSourceFile(target_->settings()->build_settings()));
588 }
589 res->Set(variables::kOutputs, RenderValue(output_files_as_source_file));
590 }
591 }
592
593 // Writes a given config value type to the string, optionally with
594 // attribution.
595 // This should match RecursiveTargetConfigToStream in the order it traverses.
596 template <class T>
597 ValuePtr RenderConfigValues(const std::vector<T>& (ConfigValues::*getter)()
598 const) {
599 auto res = base::WrapUnique(new base::ListValue());
600 for (ConfigValuesIterator iter(target_); !iter.done(); iter.Next()) {
601 const std::vector<T>& vec = (iter.cur().*getter)();
602
603 if (vec.empty())
604 continue;
605
606 if (blame_) {
607 const Config* config = iter.GetCurrentConfig();
608 if (config) {
609 // Source of this value is a config.
610 std::string from =
611 "From " + config->label().GetUserVisibleName(false);
612 res->AppendString(from);
613 if (iter.origin()) {
614 Location location = iter.origin()->GetRange().begin();
615 from = " (Added by " + location.file()->name().value() + ":" +
616 base::IntToString(location.line_number()) + ")";
617 res->AppendString(from);
618 }
619 } else {
620 // Source of this value is the target itself.
621 std::string from =
622 "From " + target_->label().GetUserVisibleName(false);
623 res->AppendString(from);
624 }
625 }
626
627 for (const T& val : vec) {
628 ValuePtr rendered = RenderValue(val);
629 std::string str;
630 // Indent string values in blame mode
631 if (blame_ && rendered->GetAsString(&str)) {
632 str = " " + str;
633 rendered = base::WrapUnique(new base::StringValue(str));
634 }
635 res->Append(std::move(rendered));
636 }
637 }
638 return res->empty() ? nullptr : std::move(res);
639 }
640
641 Label GetToolchainLabel() const override {
642 return target_->label().GetToolchainLabel();
643 }
644
645 const Target* target_;
646 };
647
648 } // Namespace
brettw 2016/07/06 22:19:26 Normally we do lower-case "n" here.
matt.k 2016/07/08 00:39:07 Done.
649
650 const char* DescBuilder::GetStringForOutputType(Target::OutputType type) {
brettw 2016/07/06 22:19:26 Here (and in the following function) we're inventi
matt.k 2016/07/08 00:39:07 Done.
651 #define CASE(C) \
652 case Target::C: \
653 return #C
654 switch (type) {
655 CASE(UNKNOWN);
656 CASE(GROUP);
657 CASE(EXECUTABLE);
658 CASE(LOADABLE_MODULE);
659 CASE(SHARED_LIBRARY);
660 CASE(STATIC_LIBRARY);
661 CASE(SOURCE_SET);
662 CASE(COPY_FILES);
663 CASE(ACTION);
664 CASE(ACTION_FOREACH);
665 CASE(BUNDLE_DATA);
666 CASE(CREATE_BUNDLE);
667 }
668 #undef CASE
669 }
670
671 Target::OutputType DescBuilder::GetOutputTypeForString(
672 const std::string& type) {
673 #define CASE(C) \
674 if (type == #C) \
675 return Target::C
brettw 2016/07/06 22:19:26 If we keep this, can you indent this line one more
matt.k 2016/07/08 00:39:07 Done.
676 CASE(GROUP);
677 CASE(EXECUTABLE);
678 CASE(LOADABLE_MODULE);
679 CASE(SHARED_LIBRARY);
680 CASE(STATIC_LIBRARY);
681 CASE(SOURCE_SET);
682 CASE(COPY_FILES);
683 CASE(ACTION);
684 CASE(ACTION_FOREACH);
685 CASE(BUNDLE_DATA);
686 CASE(CREATE_BUNDLE);
687 return Target::UNKNOWN;
688 #undef CASE
689 }
690
691 std::unique_ptr<base::DictionaryValue> DescBuilder::DescriptionForTarget(
692 const Target* target,
693 const std::string& what,
694 bool all,
695 bool tree,
696 bool blame) {
697 std::set<std::string> w;
698 if (!what.empty())
699 w.insert(what);
700 TargetDescBuilder b(target, w, all, tree, blame);
701 return b.BuildDescription();
702 }
703
704 std::unique_ptr<base::DictionaryValue> DescBuilder::DescriptionForConfig(
705 const Config* config,
706 const std::string& what) {
707 std::set<std::string> w;
708 if (!what.empty())
709 w.insert(what);
710 ConfigDescBuilder b(config, w);
711 return b.BuildDescription();
712 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698