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

Unified Diff: tools/gn/function_write_file.cc

Issue 1656253003: [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, 11 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/function_write_file.cc
diff --git a/tools/gn/function_write_file.cc b/tools/gn/function_write_file.cc
index 91599755a37e239ec3a4a155a8c46fb7459eda6b..eeba89a7f3d9a673cc98e181ca150a54322b266f 100644
--- a/tools/gn/function_write_file.cc
+++ b/tools/gn/function_write_file.cc
@@ -130,7 +130,7 @@ Value RunWriteFile(Scope* scope,
scope->settings()->build_settings()->GetFullPath(source_file));
// Compute output.
- std::ostringstream contents;
+ std::stringstream contents;
if (args[1].type() == Value::LIST) {
const std::vector<Value>& list = args[1].list_value();
for (const auto& cur : list)
@@ -138,14 +138,12 @@ Value RunWriteFile(Scope* scope,
} else {
contents << args[1].ToString(false);
}
- const std::string& new_contents = contents.str();
+
base::FilePath file_path =
scope->settings()->build_settings()->GetFullPath(source_file);
// Make sure we're not replacing the same contents.
- std::string existing_contents;
- if (base::ReadFileToString(file_path, &existing_contents) &&
- existing_contents == new_contents)
+ if (ContentsEqual(file_path, &contents))
return Value(); // Nothing to do.
// Write file, creating the directory if necessary.
brettw 2016/02/02 20:50:23 Can the rest of this function and DoWriteFile all
Tomasz Moniuszko 2016/02/03 10:20:30 Done.
@@ -155,6 +153,7 @@ Value RunWriteFile(Scope* scope,
return Value();
}
+ const std::string& new_contents = contents.str();
int int_size = static_cast<int>(new_contents.size());
if (DoWriteFile(file_path, new_contents.c_str(), int_size)
!= int_size) {

Powered by Google App Engine
This is Rietveld 408576698