| OLD | NEW |
| 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Double forward slash at the beginning means source-relative (we don't | 331 // Double forward slash at the beginning means source-relative (we don't |
| 332 // allow backslashes for denoting this). | 332 // allow backslashes for denoting this). |
| 333 if (path.size() > 1 && path[1] == '/') | 333 if (path.size() > 1 && path[1] == '/') |
| 334 return false; | 334 return false; |
| 335 | 335 |
| 336 return true; | 336 return true; |
| 337 } | 337 } |
| 338 | 338 |
| 339 bool IsPathSourceAbsolute(const base::StringPiece& path) { |
| 340 return (path.size() >= 2 && path[0] == '/' && path[1] == '/'); |
| 341 } |
| 342 |
| 339 bool MakeAbsolutePathRelativeIfPossible(const base::StringPiece& source_root, | 343 bool MakeAbsolutePathRelativeIfPossible(const base::StringPiece& source_root, |
| 340 const base::StringPiece& path, | 344 const base::StringPiece& path, |
| 341 std::string* dest) { | 345 std::string* dest) { |
| 342 DCHECK(IsPathAbsolute(source_root)); | 346 DCHECK(IsPathAbsolute(source_root)); |
| 343 DCHECK(IsPathAbsolute(path)); | 347 DCHECK(IsPathAbsolute(path)); |
| 344 | 348 |
| 345 dest->clear(); | 349 dest->clear(); |
| 346 | 350 |
| 347 if (source_root.size() > path.size()) | 351 if (source_root.size() > path.size()) |
| 348 return false; // The source root is longer: the path can never be inside. | 352 return false; // The source root is longer: the path can never be inside. |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 | 751 |
| 748 return file_data == data; | 752 return file_data == data; |
| 749 } | 753 } |
| 750 | 754 |
| 751 bool WriteFileIfChanged(const base::FilePath& file_path, | 755 bool WriteFileIfChanged(const base::FilePath& file_path, |
| 752 const std::string& data, | 756 const std::string& data, |
| 753 Err* err) { | 757 Err* err) { |
| 754 if (ContentsEqual(file_path, data)) | 758 if (ContentsEqual(file_path, data)) |
| 755 return true; | 759 return true; |
| 756 | 760 |
| 761 return WriteFile(file_path, data, err); |
| 762 } |
| 763 |
| 764 bool WriteFile(const base::FilePath& file_path, const std::string& data, |
| 765 Err* err) { |
| 757 // Create the directory if necessary. | 766 // Create the directory if necessary. |
| 758 if (!base::CreateDirectory(file_path.DirName())) { | 767 if (!base::CreateDirectory(file_path.DirName())) { |
| 759 if (err) { | 768 if (err) { |
| 760 *err = | 769 *err = |
| 761 Err(Location(), "Unable to create directory.", | 770 Err(Location(), "Unable to create directory.", |
| 762 "I was using \"" + FilePathToUTF8(file_path.DirName()) + "\"."); | 771 "I was using \"" + FilePathToUTF8(file_path.DirName()) + "\"."); |
| 763 } | 772 } |
| 764 return false; | 773 return false; |
| 765 } | 774 } |
| 766 | 775 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 BuildDirContext(target), target->label().dir(), type); | 906 BuildDirContext(target), target->label().dir(), type); |
| 898 } | 907 } |
| 899 | 908 |
| 900 SourceDir GetScopeCurrentBuildDirAsSourceDir(const Scope* scope, | 909 SourceDir GetScopeCurrentBuildDirAsSourceDir(const Scope* scope, |
| 901 BuildDirType type) { | 910 BuildDirType type) { |
| 902 if (type == BuildDirType::TOOLCHAIN_ROOT) | 911 if (type == BuildDirType::TOOLCHAIN_ROOT) |
| 903 return GetBuildDirAsSourceDir(BuildDirContext(scope), type); | 912 return GetBuildDirAsSourceDir(BuildDirContext(scope), type); |
| 904 return GetSubBuildDirAsSourceDir( | 913 return GetSubBuildDirAsSourceDir( |
| 905 BuildDirContext(scope), scope->GetSourceDir(), type); | 914 BuildDirContext(scope), scope->GetSourceDir(), type); |
| 906 } | 915 } |
| OLD | NEW |