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

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

Issue 857163002: Absolute path fixes for gn. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve error message Created 5 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
« no previous file with comments | « no previous file | tools/gn/filesystem_utils_unittest.cc » ('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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 #if defined(OS_WIN) 513 #if defined(OS_WIN)
514 for (size_t i = 0; i < path->size(); i++) { 514 for (size_t i = 0; i < path->size(); i++) {
515 if ((*path)[i] == '/') 515 if ((*path)[i] == '/')
516 (*path)[i] = '\\'; 516 (*path)[i] = '\\';
517 } 517 }
518 #endif 518 #endif
519 } 519 }
520 520
521 std::string MakeRelativePath(const std::string& input, 521 std::string MakeRelativePath(const std::string& input,
522 const std::string& dest) { 522 const std::string& dest) {
523 #if defined(OS_WIN)
524 // Make sure that absolute |input| path starts with a slash if |dest| path
525 // does. Otherwise skipping common prefixes won't work properly. Ensure the
526 // same for |dest| path too.
527 if (IsPathAbsolute(input) && !IsSlash(input[0]) && IsSlash(dest[0])) {
528 std::string corrected_input(1, dest[0]);
529 corrected_input.append(input);
530 return MakeRelativePath(corrected_input, dest);
531 }
532 if (IsPathAbsolute(dest) && !IsSlash(dest[0]) && IsSlash(input[0])) {
533 std::string corrected_dest(1, input[0]);
534 corrected_dest.append(dest);
535 return MakeRelativePath(input, corrected_dest);
536 }
537 #endif
538
523 std::string ret; 539 std::string ret;
524 540
525 // Skip the common prefixes of the source and dest as long as they end in 541 // Skip the common prefixes of the source and dest as long as they end in
526 // a [back]slash. 542 // a [back]slash.
527 size_t common_prefix_len = 0; 543 size_t common_prefix_len = 0;
528 size_t max_common_length = std::min(input.size(), dest.size()); 544 size_t max_common_length = std::min(input.size(), dest.size());
529 for (size_t i = common_prefix_len; i < max_common_length; i++) { 545 for (size_t i = common_prefix_len; i < max_common_length; i++) {
530 if (IsSlash(input[i]) && IsSlash(dest[i])) 546 if (IsSlash(input[i]) && IsSlash(dest[i]))
531 common_prefix_len = i + 1; 547 common_prefix_len = i + 1;
532 else if (input[i] != dest[i]) 548 else if (input[i] != dest[i])
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 source_dir.value().size() - 2); 741 source_dir.value().size() - 2);
726 } else { 742 } else {
727 // system-absolute 743 // system-absolute
728 const std::string& build_dir = 744 const std::string& build_dir =
729 settings->build_settings()->build_dir().value(); 745 settings->build_settings()->build_dir().value();
730 746
731 if (StartsWithASCII(source_dir.value(), build_dir, true)) { 747 if (StartsWithASCII(source_dir.value(), build_dir, true)) {
732 size_t build_dir_size = build_dir.size(); 748 size_t build_dir_size = build_dir.size();
733 result.value().append(&source_dir.value()[build_dir_size], 749 result.value().append(&source_dir.value()[build_dir_size],
734 source_dir.value().size() - build_dir_size); 750 source_dir.value().size() - build_dir_size);
751 } else {
752 result.value().append("ABS_PATH");
753 #if defined(OS_WIN)
754 // Windows absolute path contains ':' after drive letter. Remove it to
755 // avoid inserting ':' in the middle of path (eg. "ABS_PATH/C:/").
756 std::string src_dir_value = source_dir.value();
757 const auto colon_pos = src_dir_value.find(':');
758 if (colon_pos != std::string::npos)
759 src_dir_value.erase(src_dir_value.begin() + colon_pos);
760 #else
761 const std::string& src_dir_value = source_dir.value();
762 #endif
763 result.value().append(src_dir_value);
735 } 764 }
736 } 765 }
737 return result; 766 return result;
738 } 767 }
739 768
740 SourceDir GetGenDirForSourceDir(const Settings* settings, 769 SourceDir GetGenDirForSourceDir(const Settings* settings,
741 const SourceDir& source_dir) { 770 const SourceDir& source_dir) {
742 return GetGenDirForSourceDirAsOutputFile(settings, source_dir).AsSourceDir( 771 return GetGenDirForSourceDirAsOutputFile(settings, source_dir).AsSourceDir(
743 settings->build_settings()); 772 settings->build_settings());
744 } 773 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 809
781 SourceDir GetCurrentOutputDir(const Scope* scope) { 810 SourceDir GetCurrentOutputDir(const Scope* scope) {
782 return GetOutputDirForSourceDirAsOutputFile( 811 return GetOutputDirForSourceDirAsOutputFile(
783 scope->settings(), scope->GetSourceDir()).AsSourceDir( 812 scope->settings(), scope->GetSourceDir()).AsSourceDir(
784 scope->settings()->build_settings()); 813 scope->settings()->build_settings());
785 } 814 }
786 815
787 SourceDir GetCurrentGenDir(const Scope* scope) { 816 SourceDir GetCurrentGenDir(const Scope* scope) {
788 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); 817 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir());
789 } 818 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/filesystem_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698