| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "tools/gn/commands.h" | 7 #include "tools/gn/commands.h" |
| 8 #include "tools/gn/header_checker.h" | 8 #include "tools/gn/header_checker.h" |
| 9 #include "tools/gn/setup.h" | 9 #include "tools/gn/setup.h" |
| 10 #include "tools/gn/standard_out.h" | 10 #include "tools/gn/standard_out.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (!setup->DoSetup(args[0], false)) | 63 if (!setup->DoSetup(args[0], false)) |
| 64 return 1; | 64 return 1; |
| 65 if (!setup->Run()) | 65 if (!setup->Run()) |
| 66 return 1; | 66 return 1; |
| 67 | 67 |
| 68 std::vector<const Target*> all_targets = | 68 std::vector<const Target*> all_targets = |
| 69 setup->builder()->GetAllResolvedTargets(); | 69 setup->builder()->GetAllResolvedTargets(); |
| 70 | 70 |
| 71 bool filtered_by_build_config = false; | 71 bool filtered_by_build_config = false; |
| 72 std::vector<const Target*> targets_to_check; | 72 std::vector<const Target*> targets_to_check; |
| 73 if (args.size() == 2) { | 73 if (args.size() > 1) { |
| 74 // Compute the target to check. | 74 // Compute the targets to check. |
| 75 if (!ResolveTargetsFromCommandLinePattern(setup, args[1], false, | 75 std::vector<std::string> inputs(args.begin() + 1, args.end()); |
| 76 &targets_to_check)) | 76 UniqueVector<const Target*> target_matches; |
| 77 UniqueVector<const Config*> config_matches; |
| 78 UniqueVector<const Toolchain*> toolchain_matches; |
| 79 UniqueVector<SourceFile> file_matches; |
| 80 if (!ResolveFromCommandLineInput(setup, inputs, false, |
| 81 &target_matches, &config_matches, |
| 82 &toolchain_matches, &file_matches)) |
| 77 return 1; | 83 return 1; |
| 78 if (targets_to_check.size() == 0) { | 84 |
| 85 if (target_matches.size() == 0) { |
| 79 OutputString("No matching targets.\n"); | 86 OutputString("No matching targets.\n"); |
| 80 return 1; | 87 return 1; |
| 81 } | 88 } |
| 89 targets_to_check.insert(targets_to_check.begin(), |
| 90 target_matches.begin(), target_matches.end()); |
| 82 } else { | 91 } else { |
| 83 // No argument means to check everything allowed by the filter in | 92 // No argument means to check everything allowed by the filter in |
| 84 // the build config file. | 93 // the build config file. |
| 85 if (setup->check_patterns()) { | 94 if (setup->check_patterns()) { |
| 86 FilterTargetsByPatterns(all_targets, *setup->check_patterns(), | 95 FilterTargetsByPatterns(all_targets, *setup->check_patterns(), |
| 87 &targets_to_check); | 96 &targets_to_check); |
| 88 filtered_by_build_config = targets_to_check.size() != all_targets.size(); | 97 filtered_by_build_config = targets_to_check.size() != all_targets.size(); |
| 89 } else { | 98 } else { |
| 90 // No global filter, check everything. | 99 // No global filter, check everything. |
| 91 targets_to_check = all_targets; | 100 targets_to_check = all_targets; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 std::vector<Err> header_errors; | 134 std::vector<Err> header_errors; |
| 126 header_checker->Run(to_check, force_check, &header_errors); | 135 header_checker->Run(to_check, force_check, &header_errors); |
| 127 for (size_t i = 0; i < header_errors.size(); i++) { | 136 for (size_t i = 0; i < header_errors.size(); i++) { |
| 128 if (i > 0) | 137 if (i > 0) |
| 129 OutputString("___________________\n", DECORATION_YELLOW); | 138 OutputString("___________________\n", DECORATION_YELLOW); |
| 130 header_errors[i].PrintToStdout(); | 139 header_errors[i].PrintToStdout(); |
| 131 } | 140 } |
| 132 return header_errors.empty(); | 141 return header_errors.empty(); |
| 133 } | 142 } |
| 134 | 143 |
| 135 void FilterTargetsByPatterns(const std::vector<const Target*>& input, | |
| 136 const std::vector<LabelPattern>& filter, | |
| 137 std::vector<const Target*>* output) { | |
| 138 for (const auto& target : input) { | |
| 139 for (const auto& pattern : filter) { | |
| 140 if (pattern.Matches(target->label())) { | |
| 141 output->push_back(target); | |
| 142 break; | |
| 143 } | |
| 144 } | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 } // namespace commands | 144 } // namespace commands |
| OLD | NEW |