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

Unified Diff: tools/gn/analyzer.cc

Issue 2940873002: Implement tracking of BUILD.gn files used to define target, toolchain or (Closed)
Patch Set: Fix compilation after rebase. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/gn/analyzer.h ('k') | tools/gn/analyzer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/analyzer.cc
diff --git a/tools/gn/analyzer.cc b/tools/gn/analyzer.cc
index d1f2d524264549f6df32935839887bd71e32301b..43cd1377c5add6b917845e93e642585787eabd5c 100644
--- a/tools/gn/analyzer.cc
+++ b/tools/gn/analyzer.cc
@@ -13,12 +13,12 @@
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
-#include "base/strings/string_util.h"
#include "base/values.h"
#include "tools/gn/builder.h"
#include "tools/gn/deps_iterator.h"
#include "tools/gn/err.h"
#include "tools/gn/filesystem_utils.h"
+#include "tools/gn/input_file.h"
#include "tools/gn/loader.h"
#include "tools/gn/location.h"
#include "tools/gn/source_file.h"
@@ -56,17 +56,6 @@ LabelSet LabelsFor(const TargetSet& targets) {
return labels;
}
-bool AnyBuildFilesWereModified(const SourceFileSet& source_files) {
- for (auto* file : source_files) {
- if (base::EndsWith(file->value(), ".gn", base::CompareCase::SENSITIVE) ||
- base::EndsWith(file->value(), ".gni", base::CompareCase::SENSITIVE) ||
- base::EndsWith(file->value(), "build/vs_toolchain.py",
- base::CompareCase::SENSITIVE))
- return true;
- }
- return false;
-}
-
TargetSet Intersect(const TargetSet& l, const TargetSet& r) {
TargetSet result;
std::set_intersection(l.begin(), l.end(), r.begin(), r.end(),
@@ -225,9 +214,13 @@ std::string OutputsToJSON(const Outputs& outputs,
} // namespace
-Analyzer::Analyzer(const Builder& builder)
+Analyzer::Analyzer(const Builder& builder,
+ const SourceFile& build_config_file,
+ const SourceFile& dotgn_file)
: all_targets_(builder.GetAllResolvedTargets()),
- default_toolchain_(builder.loader()->GetDefaultToolchain()) {
+ default_toolchain_(builder.loader()->GetDefaultToolchain()),
+ build_config_file_(build_config_file),
+ dotgn_file_(dotgn_file) {
for (const auto* target : all_targets_) {
labels_to_targets_[target->label()] = target;
for (const auto& dep_pair : target->GetDeps(Target::DEPS_ALL))
@@ -262,12 +255,7 @@ std::string Analyzer::Analyze(const std::string& input, Err* err) const {
return OutputsToJSON(outputs, default_toolchain_, err);
}
- // TODO(crbug.com/555273): We can do smarter things when we detect changes
- // to build files. For example, if all of the ninja files are unchanged,
- // we know that we can ignore changes to .gn* files. Also, for most .gn
- // files, we can treat a change as simply affecting every target, config,
- // or toolchain defined in that file.
- if (AnyBuildFilesWereModified(inputs.source_files)) {
+ if (WereMainGNFilesModified(inputs.source_files)) {
outputs.status = "Found dependency (all)";
if (inputs.compile_included_all) {
outputs.compile_includes_all = true;
@@ -360,6 +348,10 @@ void Analyzer::FilterTarget(const Target* target,
bool Analyzer::TargetRefersToFile(const Target* target,
const SourceFile* file) const {
+ for (const auto* cur_file : target->input_files()) {
+ if (cur_file->name() == *file)
+ return true;
+ }
for (const auto& cur_file : target->sources()) {
if (cur_file == *file)
return true;
@@ -412,3 +404,12 @@ void Analyzer::AddAllRefsTo(const Target* target, TargetSet* results) const {
for (auto cur_dep = dep_begin; cur_dep != dep_end; cur_dep++)
AddAllRefsTo(cur_dep->second, results);
}
+
+bool Analyzer::WereMainGNFilesModified(
+ const SourceFileSet& source_files) const {
+ for (auto* file : source_files) {
+ if (*file == dotgn_file_ || *file == build_config_file_)
+ return true;
+ }
+ return false;
+}
« no previous file with comments | « tools/gn/analyzer.h ('k') | tools/gn/analyzer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698