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

Unified Diff: tools/gn/analyzer.cc

Issue 2940873002: Implement tracking of BUILD.gn files used to define target, toolchain or (Closed)
Patch Set: Use base::flat_set instead of std::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 side-by-side diff with in-line comments
Download patch
Index: tools/gn/analyzer.cc
diff --git a/tools/gn/analyzer.cc b/tools/gn/analyzer.cc
index aa0eca4d1c1c882fe8ede2bb00b81ef7cf8ebce9..c6eb0dc324e7a24e329e53fd8c991e42a1237d7d 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,10 @@ std::string OutputsToJSON(const Outputs& outputs,
} // namespace
-Analyzer::Analyzer(const Builder& builder)
+Analyzer::Analyzer(const BuildSettings& build_settings, const Builder& builder)
: all_targets_(builder.GetAllResolvedTargets()),
- default_toolchain_(builder.loader()->GetDefaultToolchain()) {
+ default_toolchain_(builder.loader()->GetDefaultToolchain()),
+ build_config_file_(build_settings.build_config_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 +252,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 +345,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;
@@ -410,3 +399,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->value() == "//.gn" || *file == build_config_file_)
brettw 2017/06/28 20:49:40 Somewhat annoyingly, the dotfile can be overridden
alex-ac 2017/06/29 10:26:57 Done.
+ return true;
+ }
+ return false;
+}
« no previous file with comments | « tools/gn/analyzer.h ('k') | tools/gn/analyzer_unittest.cc » ('j') | tools/gn/loader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698