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

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

Issue 2355713002: Fix a bug in `gn analyze` related to build-only changes. (Closed)
Patch Set: Created 4 years, 3 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') | no next file with comments »
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 for (const auto& label : InvalidLabels(inputs.compile_labels)) 245 for (const auto& label : InvalidLabels(inputs.compile_labels))
246 invalid_labels.insert(label); 246 invalid_labels.insert(label);
247 for (const auto& label : InvalidLabels(inputs.test_labels)) 247 for (const auto& label : InvalidLabels(inputs.test_labels))
248 invalid_labels.insert(label); 248 invalid_labels.insert(label);
249 if (!invalid_labels.empty()) { 249 if (!invalid_labels.empty()) {
250 outputs.error = "Invalid targets"; 250 outputs.error = "Invalid targets";
251 outputs.invalid_labels = invalid_labels; 251 outputs.invalid_labels = invalid_labels;
252 return OutputsToJSON(outputs, default_toolchain_, err); 252 return OutputsToJSON(outputs, default_toolchain_, err);
253 } 253 }
254 254
255 TargetSet affected_targets = AllAffectedTargets(inputs.source_files); 255 // TODO(crbug.com/555273): We can do smarter things when we detect changes
256 if (affected_targets.empty()) { 256 // to build files. For example, if all of the ninja files are unchanged,
257 outputs.status = "No dependency"; 257 // we know that we can ignore changes to these files. Also, for most .gn
258 return OutputsToJSON(outputs, default_toolchain_, err); 258 // files, we can treat a change as simply affecting every target, config,
259 } 259 // or toolchain defined in that file.
260
261 // TODO: We can do smarter things when we detect changes to build files.
262 // For example, if all of the ninja files are unchanged, we know that we
263 // can ignore changes to these files. Also, for most .gn files, we can
264 // treat a change as simply affecting every target, config, or toolchain
265 // defined in that file.
266 if (AnyBuildFilesWereModified(inputs.source_files)) { 260 if (AnyBuildFilesWereModified(inputs.source_files)) {
267 outputs.status = "Found dependency (all)"; 261 outputs.status = "Found dependency (all)";
268 outputs.compile_labels = inputs.compile_labels; 262 outputs.compile_labels = inputs.compile_labels;
269 outputs.test_labels = inputs.test_labels; 263 outputs.test_labels = inputs.test_labels;
270 return OutputsToJSON(outputs, default_toolchain_, err); 264 return OutputsToJSON(outputs, default_toolchain_, err);
271 } 265 }
272 266
267 TargetSet affected_targets = AllAffectedTargets(inputs.source_files);
268 if (affected_targets.empty()) {
269 outputs.status = "No dependency";
270 return OutputsToJSON(outputs, default_toolchain_, err);
271 }
272
273 TargetSet compile_targets = TargetsFor(inputs.compile_labels); 273 TargetSet compile_targets = TargetsFor(inputs.compile_labels);
274 if (inputs.compile_included_all) { 274 if (inputs.compile_included_all) {
275 for (auto& root : roots_) 275 for (auto& root : roots_)
276 compile_targets.insert(root); 276 compile_targets.insert(root);
277 } 277 }
278 TargetSet filtered_targets = Filter(compile_targets); 278 TargetSet filtered_targets = Filter(compile_targets);
279 outputs.compile_labels = 279 outputs.compile_labels =
280 LabelsFor(Intersect(filtered_targets, affected_targets)); 280 LabelsFor(Intersect(filtered_targets, affected_targets));
281 281
282 TargetSet test_targets = TargetsFor(inputs.test_labels); 282 TargetSet test_targets = TargetsFor(inputs.test_labels);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const { 388 void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const {
389 if (results->find(target) != results->end()) 389 if (results->find(target) != results->end())
390 return; // Already found this target. 390 return; // Already found this target.
391 results->insert(target); 391 results->insert(target);
392 392
393 auto dep_begin = dep_map_.lower_bound(target); 393 auto dep_begin = dep_map_.lower_bound(target);
394 auto dep_end = dep_map_.upper_bound(target); 394 auto dep_end = dep_map_.upper_bound(target);
395 for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++) 395 for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++)
396 AddAllRefsTo(cur_dep->second, results); 396 AddAllRefsTo(cur_dep->second, results);
397 } 397 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/analyzer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698