OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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/analyzer.h" | 5 #include "tools/gn/analyzer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 std::string status; | 44 std::string status; |
45 std::string error; | 45 std::string error; |
46 bool compile_includes_all = false; | 46 bool compile_includes_all = false; |
47 LabelSet compile_labels; | 47 LabelSet compile_labels; |
48 LabelSet test_labels; | 48 LabelSet test_labels; |
49 LabelSet invalid_labels; | 49 LabelSet invalid_labels; |
50 }; | 50 }; |
51 | 51 |
52 LabelSet LabelsFor(const TargetSet& targets) { | 52 LabelSet LabelsFor(const TargetSet& targets) { |
53 LabelSet labels; | 53 LabelSet labels; |
54 for (const auto& target : targets) | 54 for (auto* target : targets) |
55 labels.insert(target->label()); | 55 labels.insert(target->label()); |
56 return labels; | 56 return labels; |
57 } | 57 } |
58 | 58 |
59 bool AnyBuildFilesWereModified(const SourceFileSet& source_files) { | 59 bool AnyBuildFilesWereModified(const SourceFileSet& source_files) { |
60 for (const auto& file : source_files) { | 60 for (auto* file : source_files) { |
61 if (base::EndsWith(file->value(), ".gn", base::CompareCase::SENSITIVE) || | 61 if (base::EndsWith(file->value(), ".gn", base::CompareCase::SENSITIVE) || |
62 base::EndsWith(file->value(), ".gni", base::CompareCase::SENSITIVE)) | 62 base::EndsWith(file->value(), ".gni", base::CompareCase::SENSITIVE)) |
63 return true; | 63 return true; |
64 } | 64 } |
65 return false; | 65 return false; |
66 } | 66 } |
67 | 67 |
68 TargetSet Intersect(const TargetSet& l, const TargetSet& r) { | 68 TargetSet Intersect(const TargetSet& l, const TargetSet& r) { |
69 TargetSet result; | 69 TargetSet result; |
70 std::set_intersection(l.begin(), l.end(), r.begin(), r.end(), | 70 std::set_intersection(l.begin(), l.end(), r.begin(), r.end(), |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 } | 280 } |
281 | 281 |
282 TargetSet affected_targets = AllAffectedTargets(inputs.source_files); | 282 TargetSet affected_targets = AllAffectedTargets(inputs.source_files); |
283 if (affected_targets.empty()) { | 283 if (affected_targets.empty()) { |
284 outputs.status = "No dependency"; | 284 outputs.status = "No dependency"; |
285 return OutputsToJSON(outputs, default_toolchain_, err); | 285 return OutputsToJSON(outputs, default_toolchain_, err); |
286 } | 286 } |
287 | 287 |
288 TargetSet compile_targets = TargetsFor(inputs.compile_labels); | 288 TargetSet compile_targets = TargetsFor(inputs.compile_labels); |
289 if (inputs.compile_included_all) { | 289 if (inputs.compile_included_all) { |
290 for (auto& root : roots_) | 290 for (auto* root : roots_) |
291 compile_targets.insert(root); | 291 compile_targets.insert(root); |
292 } | 292 } |
293 TargetSet filtered_targets = Filter(compile_targets); | 293 TargetSet filtered_targets = Filter(compile_targets); |
294 outputs.compile_labels = | 294 outputs.compile_labels = |
295 LabelsFor(Intersect(filtered_targets, affected_targets)); | 295 LabelsFor(Intersect(filtered_targets, affected_targets)); |
296 | 296 |
297 TargetSet test_targets = TargetsFor(inputs.test_labels); | 297 TargetSet test_targets = TargetsFor(inputs.test_labels); |
298 outputs.test_labels = LabelsFor(Intersect(test_targets, affected_targets)); | 298 outputs.test_labels = LabelsFor(Intersect(test_targets, affected_targets)); |
299 | 299 |
300 if (outputs.compile_labels.empty() && outputs.test_labels.empty()) | 300 if (outputs.compile_labels.empty() && outputs.test_labels.empty()) |
301 outputs.status = "No dependency"; | 301 outputs.status = "No dependency"; |
302 else | 302 else |
303 outputs.status = "Found dependency"; | 303 outputs.status = "Found dependency"; |
304 return OutputsToJSON(outputs, default_toolchain_, err); | 304 return OutputsToJSON(outputs, default_toolchain_, err); |
305 } | 305 } |
306 | 306 |
307 TargetSet Analyzer::AllAffectedTargets( | 307 TargetSet Analyzer::AllAffectedTargets( |
308 const SourceFileSet& source_files) const { | 308 const SourceFileSet& source_files) const { |
309 TargetSet direct_matches; | 309 TargetSet direct_matches; |
310 for (const auto& source_file : source_files) | 310 for (auto* source_file : source_files) |
311 AddTargetsDirectlyReferringToFileTo(source_file, &direct_matches); | 311 AddTargetsDirectlyReferringToFileTo(source_file, &direct_matches); |
312 TargetSet all_matches; | 312 TargetSet all_matches; |
313 for (const auto& match : direct_matches) | 313 for (auto* match : direct_matches) |
314 AddAllRefsTo(match, &all_matches); | 314 AddAllRefsTo(match, &all_matches); |
315 return all_matches; | 315 return all_matches; |
316 } | 316 } |
317 | 317 |
318 LabelSet Analyzer::InvalidLabels(const LabelSet& labels) const { | 318 LabelSet Analyzer::InvalidLabels(const LabelSet& labels) const { |
319 LabelSet invalid_labels; | 319 LabelSet invalid_labels; |
320 for (const Label& label : labels) { | 320 for (const Label& label : labels) { |
321 if (labels_to_targets_.find(label) == labels_to_targets_.end()) | 321 if (labels_to_targets_.find(label) == labels_to_targets_.end()) |
322 invalid_labels.insert(label); | 322 invalid_labels.insert(label); |
323 } | 323 } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 target->action_values().GetOutputsAsSourceFiles(target, &outputs); | 385 target->action_values().GetOutputsAsSourceFiles(target, &outputs); |
386 for (const auto& cur_file : outputs) { | 386 for (const auto& cur_file : outputs) { |
387 if (cur_file == *file) | 387 if (cur_file == *file) |
388 return true; | 388 return true; |
389 } | 389 } |
390 return false; | 390 return false; |
391 } | 391 } |
392 | 392 |
393 void Analyzer::AddTargetsDirectlyReferringToFileTo(const SourceFile* file, | 393 void Analyzer::AddTargetsDirectlyReferringToFileTo(const SourceFile* file, |
394 TargetSet* matches) const { | 394 TargetSet* matches) const { |
395 for (const auto& target : all_targets_) { | 395 for (auto* target : all_targets_) { |
396 // Only handles targets in the default toolchain. | 396 // Only handles targets in the default toolchain. |
397 if ((target->label().GetToolchainLabel() == default_toolchain_) && | 397 if ((target->label().GetToolchainLabel() == default_toolchain_) && |
398 TargetRefersToFile(target, file)) | 398 TargetRefersToFile(target, file)) |
399 matches->insert(target); | 399 matches->insert(target); |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const { | 403 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const { |
404 if (results->find(target) != results->end()) | 404 if (results->find(target) != results->end()) |
405 return; // Already found this target. | 405 return; // Already found this target. |
406 results->insert(target); | 406 results->insert(target); |
407 | 407 |
408 auto dep_begin = dep_map_.lower_bound(target); | 408 auto dep_begin = dep_map_.lower_bound(target); |
409 auto dep_end = dep_map_.upper_bound(target); | 409 auto dep_end = dep_map_.upper_bound(target); |
410 for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++) | 410 for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++) |
411 AddAllRefsTo(cur_dep->second, results); | 411 AddAllRefsTo(cur_dep->second, results); |
412 } | 412 } |
OLD | NEW |