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

Unified Diff: tools/gn/visual_studio_writer.cc

Issue 1704383002: [GN] Don't rewrite files with the same contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/ninja_target_writer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/visual_studio_writer.cc
diff --git a/tools/gn/visual_studio_writer.cc b/tools/gn/visual_studio_writer.cc
index 44a3f11449fd1efdd5be48a5e36d95bdf779f997..dec083753f79052cdc6a8a0ef80a75cfacf5d739 100644
--- a/tools/gn/visual_studio_writer.cc
+++ b/tools/gn/visual_studio_writer.cc
@@ -9,7 +9,6 @@
#include <set>
#include <string>
-#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_util.h"
@@ -153,26 +152,6 @@ base::StringPiece FindParentDir(const std::string* path) {
return base::StringPiece();
}
-bool HasSameContent(std::stringstream& data_1, const base::FilePath& data_2) {
- // Compare file sizes first. Quick and will save us some time if they are
- // different sizes.
- int64_t data_1_len = data_1.tellp();
-
- int64_t data_2_len;
- if (!base::GetFileSize(data_2, &data_2_len) || data_1_len != data_2_len)
- return false;
-
- std::string data_2_data;
- data_2_data.resize(data_2_len);
- if (!base::ReadFileToString(data_2, &data_2_data))
- return false;
-
- std::string data_1_data;
- data_1_data = data_1.str();
-
- return data_1_data == data_2_data;
-}
-
} // namespace
VisualStudioWriter::SolutionEntry::SolutionEntry(const std::string& _name,
@@ -289,32 +268,13 @@ bool VisualStudioWriter::WriteProjectFiles(const Target* target, Err* err) {
// Only write the content to the file if it's different. That is
// both a performance optimization and more importantly, prevents
// Visual Studio from reloading the projects.
- if (!HasSameContent(vcxproj_string_out, vcxproj_path)) {
- std::string content = vcxproj_string_out.str();
- int size = static_cast<int>(content.size());
- if (base::WriteFile(vcxproj_path, content.c_str(), size) != size) {
- *err = Err(Location(), "Couldn't open " + target->label().name() +
- ".vcxproj for writing");
- return false;
- }
- }
+ if (!WriteFileIfChanged(vcxproj_path, vcxproj_string_out.str(), err))
+ return false;
base::FilePath filters_path = UTF8ToFilePath(vcxproj_path_str + ".filters");
-
std::stringstream filters_string_out;
WriteFiltersFileContents(filters_string_out, target);
-
- if (!HasSameContent(filters_string_out, filters_path)) {
- std::string content = filters_string_out.str();
- int size = static_cast<int>(content.size());
- if (base::WriteFile(filters_path, content.c_str(), size) != size) {
- *err = Err(Location(), "Couldn't open " + target->label().name() +
- ".vcxproj.filters for writing");
- return false;
- }
- }
-
- return true;
+ return WriteFileIfChanged(filters_path, filters_string_out.str(), err);
}
bool VisualStudioWriter::WriteProjectFileContents(
@@ -612,17 +572,7 @@ bool VisualStudioWriter::WriteSolutionFile(Err* err) {
// Only write the content to the file if it's different. That is
// both a performance optimization and more importantly, prevents
// Visual Studio from reloading the projects.
- if (HasSameContent(string_out, sln_path))
- return true;
-
- std::string content = string_out.str();
- int size = static_cast<int>(content.size());
- if (base::WriteFile(sln_path, content.c_str(), size) != size) {
- *err = Err(Location(), "Couldn't open all.sln for writing");
- return false;
- }
-
- return true;
+ return WriteFileIfChanged(sln_path, string_out.str(), err);
}
void VisualStudioWriter::WriteSolutionFileContents(
« no previous file with comments | « tools/gn/ninja_target_writer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698