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

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

Issue 2940873002: Implement tracking of BUILD.gn files used to define target, toolchain or (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | tools/gn/analyzer_unittest.cc » ('j') | tools/gn/scope.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 (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 DotGNFileWasModified(const SourceFileSet& source_files) {
60 for (auto* file : source_files) { 60 for (auto* file : source_files) {
61 if (base::EndsWith(file->value(), ".gn", base::CompareCase::SENSITIVE) || 61 if (file->value() == "//.gn")
62 base::EndsWith(file->value(), ".gni", base::CompareCase::SENSITIVE) ||
63 base::EndsWith(file->value(), "build/vs_toolchain.py",
64 base::CompareCase::SENSITIVE))
65 return true; 62 return true;
66 } 63 }
67 return false; 64 return false;
68 } 65 }
69 66
70 TargetSet Intersect(const TargetSet& l, const TargetSet& r) { 67 TargetSet Intersect(const TargetSet& l, const TargetSet& r) {
71 TargetSet result; 68 TargetSet result;
72 std::set_intersection(l.begin(), l.end(), r.begin(), r.end(), 69 std::set_intersection(l.begin(), l.end(), r.begin(), r.end(),
73 std::inserter(result, result.begin())); 70 std::inserter(result, result.begin()));
74 return result; 71 return result;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 for (const auto& label : InvalidLabels(inputs.compile_labels)) 252 for (const auto& label : InvalidLabels(inputs.compile_labels))
256 invalid_labels.insert(label); 253 invalid_labels.insert(label);
257 for (const auto& label : InvalidLabels(inputs.test_labels)) 254 for (const auto& label : InvalidLabels(inputs.test_labels))
258 invalid_labels.insert(label); 255 invalid_labels.insert(label);
259 if (!invalid_labels.empty()) { 256 if (!invalid_labels.empty()) {
260 outputs.error = "Invalid targets"; 257 outputs.error = "Invalid targets";
261 outputs.invalid_labels = invalid_labels; 258 outputs.invalid_labels = invalid_labels;
262 return OutputsToJSON(outputs, default_toolchain_, err); 259 return OutputsToJSON(outputs, default_toolchain_, err);
263 } 260 }
264 261
265 // TODO(crbug.com/555273): We can do smarter things when we detect changes 262 if (DotGNFileWasModified(inputs.source_files)) {
266 // to build files. For example, if all of the ninja files are unchanged,
267 // we know that we can ignore changes to .gn* files. Also, for most .gn
268 // files, we can treat a change as simply affecting every target, config,
269 // or toolchain defined in that file.
270 if (AnyBuildFilesWereModified(inputs.source_files)) {
271 outputs.status = "Found dependency (all)"; 263 outputs.status = "Found dependency (all)";
272 if (inputs.compile_included_all) { 264 if (inputs.compile_included_all) {
273 outputs.compile_includes_all = true; 265 outputs.compile_includes_all = true;
274 } else { 266 } else {
275 outputs.compile_labels.insert(inputs.compile_labels.begin(), 267 outputs.compile_labels.insert(inputs.compile_labels.begin(),
276 inputs.compile_labels.end()); 268 inputs.compile_labels.end());
277 outputs.compile_labels.insert(inputs.test_labels.begin(), 269 outputs.compile_labels.insert(inputs.test_labels.begin(),
278 inputs.test_labels.end()); 270 inputs.test_labels.end());
279 } 271 }
280 outputs.test_labels = inputs.test_labels; 272 outputs.test_labels = inputs.test_labels;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 filtered->insert(target); 345 filtered->insert(target);
354 } else { 346 } else {
355 for (const auto& pair : target->GetDeps(Target::DEPS_ALL)) 347 for (const auto& pair : target->GetDeps(Target::DEPS_ALL))
356 FilterTarget(pair.ptr, seen, filtered); 348 FilterTarget(pair.ptr, seen, filtered);
357 } 349 }
358 } 350 }
359 } 351 }
360 352
361 bool Analyzer::TargetRefersToFile(const Target* target, 353 bool Analyzer::TargetRefersToFile(const Target* target,
362 const SourceFile* file) const { 354 const SourceFile* file) const {
355 const auto& source_files_hashes = target->source_files_hashes();
356 if (source_files_hashes.find(base::Hash(file->value())) !=
357 source_files_hashes.end())
358 return true;
363 for (const auto& cur_file : target->sources()) { 359 for (const auto& cur_file : target->sources()) {
364 if (cur_file == *file) 360 if (cur_file == *file)
365 return true; 361 return true;
366 } 362 }
367 for (const auto& cur_file : target->public_headers()) { 363 for (const auto& cur_file : target->public_headers()) {
368 if (cur_file == *file) 364 if (cur_file == *file)
369 return true; 365 return true;
370 } 366 }
371 for (const auto& cur_file : target->inputs()) { 367 for (const auto& cur_file : target->inputs()) {
372 if (cur_file == *file) 368 if (cur_file == *file)
(...skipping 30 matching lines...) Expand all
403 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const { 399 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const {
404 if (results->find(target) != results->end()) 400 if (results->find(target) != results->end())
405 return; // Already found this target. 401 return; // Already found this target.
406 results->insert(target); 402 results->insert(target);
407 403
408 auto dep_begin = dep_map_.lower_bound(target); 404 auto dep_begin = dep_map_.lower_bound(target);
409 auto dep_end = dep_map_.upper_bound(target); 405 auto dep_end = dep_map_.upper_bound(target);
410 for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++) 406 for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++)
411 AddAllRefsTo(cur_dep->second, results); 407 AddAllRefsTo(cur_dep->second, results);
412 } 408 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/analyzer_unittest.cc » ('j') | tools/gn/scope.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698