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

Side by Side Diff: tools/gn/filesystem_utils.cc

Issue 2265833002: Implement `gn analyze`. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: do not pretty print the written json; this gets around crlf issues Created 4 years, 3 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
« no previous file with comments | « tools/gn/filesystem_utils.h ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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 }
OLDNEW
« no previous file with comments | « tools/gn/filesystem_utils.h ('k') | tools/gn/gn.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698