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

Side by Side Diff: tools/gn/filesystem_utils.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, 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/filesystem_utils.h" 5 #include "tools/gn/filesystem_utils.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 std::string GetOutputSubdirName(const Label& toolchain_label, bool is_default) { 680 std::string GetOutputSubdirName(const Label& toolchain_label, bool is_default) {
681 // The default toolchain has no subdir. 681 // The default toolchain has no subdir.
682 if (is_default) 682 if (is_default)
683 return std::string(); 683 return std::string();
684 684
685 // For now just assume the toolchain name is always a valid dir name. We may 685 // For now just assume the toolchain name is always a valid dir name. We may
686 // want to clean up the in the future. 686 // want to clean up the in the future.
687 return toolchain_label.name() + "/"; 687 return toolchain_label.name() + "/";
688 } 688 }
689 689
690 bool ContentsEqual(const base::FilePath& file_path, std::stringstream* data) {
brettw 2016/02/02 20:50:23 I'm thinking it might be better if this took a std
Tomasz Moniuszko 2016/02/03 10:20:30 Done.
691 // Compare file and stream sizes first. Quick and will save us some time if
692 // they are different sizes.
693 int64_t data_size = data->tellp();
694
695 int64_t file_size;
696 if (!base::GetFileSize(file_path, &file_size) || file_size != data_size)
697 return false;
698
699 std::string file_data;
700 file_data.resize(file_size);
701 if (!base::ReadFileToString(file_path, &file_data))
702 return false;
703
704 return file_data == data->str();
705 }
706
707 bool WriteFileIfChanged(const base::FilePath& file_path,
708 std::stringstream* data) {
709 if (ContentsEqual(file_path, data))
710 return true;
711
712 std::string data_str = data->str();
713 int size = static_cast<int>(data_str.size());
714 return base::WriteFile(file_path, data_str.c_str(), size) == size;
715 }
716
690 SourceDir GetToolchainOutputDir(const Settings* settings) { 717 SourceDir GetToolchainOutputDir(const Settings* settings) {
691 return settings->toolchain_output_subdir().AsSourceDir( 718 return settings->toolchain_output_subdir().AsSourceDir(
692 settings->build_settings()); 719 settings->build_settings());
693 } 720 }
694 721
695 SourceDir GetToolchainOutputDir(const BuildSettings* build_settings, 722 SourceDir GetToolchainOutputDir(const BuildSettings* build_settings,
696 const Label& toolchain_label, bool is_default) { 723 const Label& toolchain_label, bool is_default) {
697 std::string result = build_settings->build_dir().value(); 724 std::string result = build_settings->build_dir().value();
698 result.append(GetOutputSubdirName(toolchain_label, is_default)); 725 result.append(GetOutputSubdirName(toolchain_label, is_default));
699 return SourceDir(SourceDir::SWAP_IN, &result); 726 return SourceDir(SourceDir::SWAP_IN, &result);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 862
836 SourceDir GetCurrentOutputDir(const Scope* scope) { 863 SourceDir GetCurrentOutputDir(const Scope* scope) {
837 return GetOutputDirForSourceDirAsOutputFile( 864 return GetOutputDirForSourceDirAsOutputFile(
838 scope->settings(), scope->GetSourceDir()).AsSourceDir( 865 scope->settings(), scope->GetSourceDir()).AsSourceDir(
839 scope->settings()->build_settings()); 866 scope->settings()->build_settings());
840 } 867 }
841 868
842 SourceDir GetCurrentGenDir(const Scope* scope) { 869 SourceDir GetCurrentGenDir(const Scope* scope) {
843 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); 870 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir());
844 } 871 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698