| 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/commands.h" | 5 #include "tools/gn/commands.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "tools/gn/builder.h" | 10 #include "tools/gn/builder.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // If the caller wants to default to the main toolchain only, set it | 49 // If the caller wants to default to the main toolchain only, set it |
| 50 // explicitly. | 50 // explicitly. |
| 51 if (pattern.toolchain().is_null()) { | 51 if (pattern.toolchain().is_null()) { |
| 52 // No explicit toolchain set. | 52 // No explicit toolchain set. |
| 53 pattern.set_toolchain(setup->loader()->default_toolchain_label()); | 53 pattern.set_toolchain(setup->loader()->default_toolchain_label()); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 std::vector<LabelPattern> pattern_vector; | 57 std::vector<LabelPattern> pattern_vector; |
| 58 pattern_vector.push_back(pattern); | 58 pattern_vector.push_back(pattern); |
| 59 FilterTargetsByPatterns(setup->builder()->GetAllResolvedTargets(), | 59 FilterTargetsByPatterns(setup->builder().GetAllResolvedTargets(), |
| 60 pattern_vector, matches); | 60 pattern_vector, matches); |
| 61 return true; | 61 return true; |
| 62 } | 62 } |
| 63 | 63 |
| 64 | 64 |
| 65 // If there's an error, it will be printed and false will be returned. | 65 // If there's an error, it will be printed and false will be returned. |
| 66 bool ResolveStringFromCommandLineInput( | 66 bool ResolveStringFromCommandLineInput( |
| 67 Setup* setup, | 67 Setup* setup, |
| 68 const SourceDir& current_dir, | 68 const SourceDir& current_dir, |
| 69 const std::string& input, | 69 const std::string& input, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 95 err = Err(); | 95 err = Err(); |
| 96 file_matches->push_back(current_dir.ResolveRelativeFile( | 96 file_matches->push_back(current_dir.ResolveRelativeFile( |
| 97 Value(nullptr, input), &err, setup->build_settings().root_path_utf8())); | 97 Value(nullptr, input), &err, setup->build_settings().root_path_utf8())); |
| 98 if (err.has_error()) { | 98 if (err.has_error()) { |
| 99 err.PrintToStdout(); | 99 err.PrintToStdout(); |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 const Item* item = setup->builder()->GetItem(label); | 105 const Item* item = setup->builder().GetItem(label); |
| 106 if (item) { | 106 if (item) { |
| 107 if (const Config* as_config = item->AsConfig()) | 107 if (const Config* as_config = item->AsConfig()) |
| 108 config_matches->push_back(as_config); | 108 config_matches->push_back(as_config); |
| 109 else if (const Target* as_target = item->AsTarget()) | 109 else if (const Target* as_target = item->AsTarget()) |
| 110 target_matches->push_back(as_target); | 110 target_matches->push_back(as_target); |
| 111 else if (const Toolchain* as_toolchain = item->AsToolchain()) | 111 else if (const Toolchain* as_toolchain = item->AsToolchain()) |
| 112 toolchain_matches->push_back(as_toolchain); | 112 toolchain_matches->push_back(as_toolchain); |
| 113 } else { | 113 } else { |
| 114 // Not an item, assume this must be a file. | 114 // Not an item, assume this must be a file. |
| 115 file_matches->push_back(current_dir.ResolveRelativeFile( | 115 file_matches->push_back(current_dir.ResolveRelativeFile( |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 Value arg_value(nullptr, label_string); | 384 Value arg_value(nullptr, label_string); |
| 385 Err err; | 385 Err err; |
| 386 Label label = Label::Resolve(SourceDirForCurrentDirectory( | 386 Label label = Label::Resolve(SourceDirForCurrentDirectory( |
| 387 setup->build_settings().root_path()), | 387 setup->build_settings().root_path()), |
| 388 default_toolchain, arg_value, &err); | 388 default_toolchain, arg_value, &err); |
| 389 if (err.has_error()) { | 389 if (err.has_error()) { |
| 390 err.PrintToStdout(); | 390 err.PrintToStdout(); |
| 391 return nullptr; | 391 return nullptr; |
| 392 } | 392 } |
| 393 | 393 |
| 394 const Item* item = setup->builder()->GetItem(label); | 394 const Item* item = setup->builder().GetItem(label); |
| 395 if (!item) { | 395 if (!item) { |
| 396 Err(Location(), "Label not found.", | 396 Err(Location(), "Label not found.", |
| 397 label.GetUserVisibleName(false) + " not found.").PrintToStdout(); | 397 label.GetUserVisibleName(false) + " not found.").PrintToStdout(); |
| 398 return nullptr; | 398 return nullptr; |
| 399 } | 399 } |
| 400 | 400 |
| 401 const Target* target = item->AsTarget(); | 401 const Target* target = item->AsTarget(); |
| 402 if (!target) { | 402 if (!target) { |
| 403 Err(Location(), "Not a target.", | 403 Err(Location(), "Not a target.", |
| 404 "The \"" + label.GetUserVisibleName(false) + "\" thing\n" | 404 "The \"" + label.GetUserVisibleName(false) + "\" thing\n" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 FilterAndPrintTargets(indent, &target_vector); | 528 FilterAndPrintTargets(indent, &target_vector); |
| 529 } | 529 } |
| 530 | 530 |
| 531 void FilterAndPrintTargetSet(const std::set<const Target*>& targets, | 531 void FilterAndPrintTargetSet(const std::set<const Target*>& targets, |
| 532 base::ListValue* out) { | 532 base::ListValue* out) { |
| 533 std::vector<const Target*> target_vector(targets.begin(), targets.end()); | 533 std::vector<const Target*> target_vector(targets.begin(), targets.end()); |
| 534 FilterAndPrintTargets(&target_vector, out); | 534 FilterAndPrintTargets(&target_vector, out); |
| 535 } | 535 } |
| 536 | 536 |
| 537 } // namespace commands | 537 } // namespace commands |
| OLD | NEW |