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 1420973003: Make sure abs-path gn labels have separate target_gen_dirs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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/function_get_path_info_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 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 return SourceDir(SourceDir::SWAP_IN, &result); 679 return SourceDir(SourceDir::SWAP_IN, &result);
680 } 680 }
681 681
682 SourceDir GetOutputDirForSourceDir(const Settings* settings, 682 SourceDir GetOutputDirForSourceDir(const Settings* settings,
683 const SourceDir& source_dir) { 683 const SourceDir& source_dir) {
684 return GetOutputDirForSourceDir( 684 return GetOutputDirForSourceDir(
685 settings->build_settings(), source_dir, 685 settings->build_settings(), source_dir,
686 settings->toolchain_label(), settings->is_default()); 686 settings->toolchain_label(), settings->is_default());
687 } 687 }
688 688
689 void AppendFixedAbsolutePathSuffix(const BuildSettings *build_settings,
brettw 2015/10/26 00:36:52 Nit: * next to type instead like your other ones.
690 const SourceDir& source_dir,
691 OutputFile* result) {
692 const std::string& build_dir = build_settings->build_dir().value();
693
694 if (base::StartsWith(source_dir.value(), build_dir,
695 base::CompareCase::SENSITIVE)) {
696 size_t build_dir_size = build_dir.size();
697 result->value().append(&source_dir.value()[build_dir_size],
698 source_dir.value().size() - build_dir_size);
699 } else {
700 result->value().append("ABS_PATH");
701 #if defined(OS_WIN)
702 // Windows absolute path contains ':' after drive letter. Remove it to
703 // avoid inserting ':' in the middle of path (eg. "ABS_PATH/C:/").
704 std::string src_dir_value = source_dir.value();
705 const auto colon_pos = src_dir_value.find(':');
706 if (colon_pos != std::string::npos)
707 src_dir_value.erase(src_dir_value.begin() + colon_pos);
708 #else
709 const std::string& src_dir_value = source_dir.value();
710 #endif
711 result->value().append(src_dir_value);
712 }
713 }
714
689 SourceDir GetOutputDirForSourceDir( 715 SourceDir GetOutputDirForSourceDir(
690 const BuildSettings* build_settings, 716 const BuildSettings* build_settings,
691 const SourceDir& source_dir, 717 const SourceDir& source_dir,
692 const Label& toolchain_label, 718 const Label& toolchain_label,
693 bool is_default_toolchain) { 719 bool is_default_toolchain) {
694 return GetOutputDirForSourceDirAsOutputFile( 720 return GetOutputDirForSourceDirAsOutputFile(
695 build_settings, source_dir, toolchain_label, is_default_toolchain) 721 build_settings, source_dir, toolchain_label, is_default_toolchain)
696 .AsSourceDir(build_settings); 722 .AsSourceDir(build_settings);
697 } 723 }
698 724
699 OutputFile GetOutputDirForSourceDirAsOutputFile( 725 OutputFile GetOutputDirForSourceDirAsOutputFile(
700 const BuildSettings* build_settings, 726 const BuildSettings* build_settings,
701 const SourceDir& source_dir, 727 const SourceDir& source_dir,
702 const Label& toolchain_label, 728 const Label& toolchain_label,
703 bool is_default_toolchain) { 729 bool is_default_toolchain) {
704 OutputFile result(GetOutputSubdirName(toolchain_label, is_default_toolchain)); 730 OutputFile result(GetOutputSubdirName(toolchain_label, is_default_toolchain));
705 result.value().append("obj/"); 731 result.value().append("obj/");
706 732
707 if (source_dir.is_source_absolute()) { 733 if (source_dir.is_source_absolute()) {
708 // The source dir is source-absolute, so we trim off the two leading 734 // The source dir is source-absolute, so we trim off the two leading
709 // slashes to append to the toolchain object directory. 735 // slashes to append to the toolchain object directory.
710 result.value().append(&source_dir.value()[2], 736 result.value().append(&source_dir.value()[2],
711 source_dir.value().size() - 2); 737 source_dir.value().size() - 2);
712 } else { 738 } else {
713 // System-absolute. 739 // System-absolute.
714 const std::string& build_dir = build_settings->build_dir().value(); 740 AppendFixedAbsolutePathSuffix(build_settings, source_dir, &result);
715
716 if (base::StartsWith(source_dir.value(), build_dir,
717 base::CompareCase::SENSITIVE)) {
718 size_t build_dir_size = build_dir.size();
719 result.value().append(&source_dir.value()[build_dir_size],
720 source_dir.value().size() - build_dir_size);
721 } else {
722 result.value().append("ABS_PATH");
723 #if defined(OS_WIN)
724 // Windows absolute path contains ':' after drive letter. Remove it to
725 // avoid inserting ':' in the middle of path (eg. "ABS_PATH/C:/").
726 std::string src_dir_value = source_dir.value();
727 const auto colon_pos = src_dir_value.find(':');
728 if (colon_pos != std::string::npos)
729 src_dir_value.erase(src_dir_value.begin() + colon_pos);
730 #else
731 const std::string& src_dir_value = source_dir.value();
732 #endif
733 result.value().append(src_dir_value);
734 }
735 } 741 }
736 return result; 742 return result;
737 } 743 }
738 744
739 OutputFile GetOutputDirForSourceDirAsOutputFile(const Settings* settings, 745 OutputFile GetOutputDirForSourceDirAsOutputFile(const Settings* settings,
740 const SourceDir& source_dir) { 746 const SourceDir& source_dir) {
741 return GetOutputDirForSourceDirAsOutputFile( 747 return GetOutputDirForSourceDirAsOutputFile(
742 settings->build_settings(), source_dir, 748 settings->build_settings(), source_dir,
743 settings->toolchain_label(), settings->is_default()); 749 settings->toolchain_label(), settings->is_default());
744 } 750 }
745 751
746 SourceDir GetGenDirForSourceDir(const Settings* settings, 752 SourceDir GetGenDirForSourceDir(const Settings* settings,
747 const SourceDir& source_dir) { 753 const SourceDir& source_dir) {
748 return GetGenDirForSourceDirAsOutputFile(settings, source_dir).AsSourceDir( 754 return GetGenDirForSourceDirAsOutputFile(settings, source_dir).AsSourceDir(
749 settings->build_settings()); 755 settings->build_settings());
750 } 756 }
751 757
752 OutputFile GetGenDirForSourceDirAsOutputFile(const Settings* settings, 758 OutputFile GetGenDirForSourceDirAsOutputFile(const Settings* settings,
753 const SourceDir& source_dir) { 759 const SourceDir& source_dir) {
754 OutputFile result = GetToolchainGenDirAsOutputFile(settings); 760 OutputFile result = GetToolchainGenDirAsOutputFile(settings);
755 761
756 if (source_dir.is_source_absolute()) { 762 if (source_dir.is_source_absolute()) {
757 // The source dir should be source-absolute, so we trim off the two leading 763 // The source dir should be source-absolute, so we trim off the two leading
758 // slashes to append to the toolchain object directory. 764 // slashes to append to the toolchain object directory.
759 DCHECK(source_dir.is_source_absolute()); 765 DCHECK(source_dir.is_source_absolute());
760 result.value().append(&source_dir.value()[2], 766 result.value().append(&source_dir.value()[2],
761 source_dir.value().size() - 2); 767 source_dir.value().size() - 2);
768 } else {
769 // System-absolute.
770 AppendFixedAbsolutePathSuffix(settings->build_settings(), source_dir,
771 &result);
762 } 772 }
763 return result; 773 return result;
764 } 774 }
765 775
766 SourceDir GetTargetOutputDir(const Target* target) { 776 SourceDir GetTargetOutputDir(const Target* target) {
767 return GetOutputDirForSourceDirAsOutputFile( 777 return GetOutputDirForSourceDirAsOutputFile(
768 target->settings(), target->label().dir()).AsSourceDir( 778 target->settings(), target->label().dir()).AsSourceDir(
769 target->settings()->build_settings()); 779 target->settings()->build_settings());
770 } 780 }
771 781
(...skipping 14 matching lines...) Expand all
786 796
787 SourceDir GetCurrentOutputDir(const Scope* scope) { 797 SourceDir GetCurrentOutputDir(const Scope* scope) {
788 return GetOutputDirForSourceDirAsOutputFile( 798 return GetOutputDirForSourceDirAsOutputFile(
789 scope->settings(), scope->GetSourceDir()).AsSourceDir( 799 scope->settings(), scope->GetSourceDir()).AsSourceDir(
790 scope->settings()->build_settings()); 800 scope->settings()->build_settings());
791 } 801 }
792 802
793 SourceDir GetCurrentGenDir(const Scope* scope) { 803 SourceDir GetCurrentGenDir(const Scope* scope) {
794 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); 804 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir());
795 } 805 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/function_get_path_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698