| 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 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 SourceDir GetToolchainGenDir(const BuildSettings* build_settings, | 722 SourceDir GetToolchainGenDir(const BuildSettings* build_settings, |
| 723 const Label& toolchain_label, bool is_default) { | 723 const Label& toolchain_label, bool is_default) { |
| 724 std::string result = GetToolchainOutputDir( | 724 std::string result = GetToolchainOutputDir( |
| 725 build_settings, toolchain_label, is_default).value(); | 725 build_settings, toolchain_label, is_default).value(); |
| 726 result.append("gen/"); | 726 result.append("gen/"); |
| 727 return SourceDir(SourceDir::SWAP_IN, &result); | 727 return SourceDir(SourceDir::SWAP_IN, &result); |
| 728 } | 728 } |
| 729 | 729 |
| 730 SourceDir GetOutputDirForSourceDir(const Settings* settings, | 730 SourceDir GetOutputDirForSourceDir(const Settings* settings, |
| 731 const SourceDir& source_dir) { | 731 const SourceDir& source_dir) { |
| 732 return GetOutputDirForSourceDirAsOutputFile(settings, source_dir).AsSourceDir( | 732 return GetOutputDirForSourceDir( |
| 733 settings->build_settings()); | 733 settings->build_settings(), source_dir, |
| 734 settings->toolchain_label(), settings->is_default()); |
| 734 } | 735 } |
| 735 | 736 |
| 736 OutputFile GetOutputDirForSourceDirAsOutputFile(const Settings* settings, | 737 SourceDir GetOutputDirForSourceDir( |
| 737 const SourceDir& source_dir) { | 738 const BuildSettings* build_settings, |
| 738 OutputFile result = settings->toolchain_output_subdir(); | 739 const SourceDir& source_dir, |
| 740 const Label& toolchain_label, |
| 741 bool is_default_toolchain) { |
| 742 return GetOutputDirForSourceDirAsOutputFile( |
| 743 build_settings, source_dir, toolchain_label, is_default_toolchain) |
| 744 .AsSourceDir(build_settings); |
| 745 } |
| 746 |
| 747 OutputFile GetOutputDirForSourceDirAsOutputFile( |
| 748 const BuildSettings* build_settings, |
| 749 const SourceDir& source_dir, |
| 750 const Label& toolchain_label, |
| 751 bool is_default_toolchain) { |
| 752 OutputFile result(GetOutputSubdirName(toolchain_label, is_default_toolchain)); |
| 739 result.value().append("obj/"); | 753 result.value().append("obj/"); |
| 740 | 754 |
| 741 if (source_dir.is_source_absolute()) { | 755 if (source_dir.is_source_absolute()) { |
| 742 // The source dir is source-absolute, so we trim off the two leading | 756 // The source dir is source-absolute, so we trim off the two leading |
| 743 // slashes to append to the toolchain object directory. | 757 // slashes to append to the toolchain object directory. |
| 744 result.value().append(&source_dir.value()[2], | 758 result.value().append(&source_dir.value()[2], |
| 745 source_dir.value().size() - 2); | 759 source_dir.value().size() - 2); |
| 746 } else { | 760 } else { |
| 747 // System-absolute. | 761 // System-absolute. |
| 748 const std::string& build_dir = | 762 const std::string& build_dir = build_settings->build_dir().value(); |
| 749 settings->build_settings()->build_dir().value(); | |
| 750 | 763 |
| 751 if (base::StartsWith(source_dir.value(), build_dir, | 764 if (base::StartsWith(source_dir.value(), build_dir, |
| 752 base::CompareCase::SENSITIVE)) { | 765 base::CompareCase::SENSITIVE)) { |
| 753 size_t build_dir_size = build_dir.size(); | 766 size_t build_dir_size = build_dir.size(); |
| 754 result.value().append(&source_dir.value()[build_dir_size], | 767 result.value().append(&source_dir.value()[build_dir_size], |
| 755 source_dir.value().size() - build_dir_size); | 768 source_dir.value().size() - build_dir_size); |
| 756 } else { | 769 } else { |
| 757 result.value().append("ABS_PATH"); | 770 result.value().append("ABS_PATH"); |
| 758 #if defined(OS_WIN) | 771 #if defined(OS_WIN) |
| 759 // Windows absolute path contains ':' after drive letter. Remove it to | 772 // Windows absolute path contains ':' after drive letter. Remove it to |
| 760 // avoid inserting ':' in the middle of path (eg. "ABS_PATH/C:/"). | 773 // avoid inserting ':' in the middle of path (eg. "ABS_PATH/C:/"). |
| 761 std::string src_dir_value = source_dir.value(); | 774 std::string src_dir_value = source_dir.value(); |
| 762 const auto colon_pos = src_dir_value.find(':'); | 775 const auto colon_pos = src_dir_value.find(':'); |
| 763 if (colon_pos != std::string::npos) | 776 if (colon_pos != std::string::npos) |
| 764 src_dir_value.erase(src_dir_value.begin() + colon_pos); | 777 src_dir_value.erase(src_dir_value.begin() + colon_pos); |
| 765 #else | 778 #else |
| 766 const std::string& src_dir_value = source_dir.value(); | 779 const std::string& src_dir_value = source_dir.value(); |
| 767 #endif | 780 #endif |
| 768 result.value().append(src_dir_value); | 781 result.value().append(src_dir_value); |
| 769 } | 782 } |
| 770 } | 783 } |
| 771 return result; | 784 return result; |
| 772 } | 785 } |
| 773 | 786 |
| 787 OutputFile GetOutputDirForSourceDirAsOutputFile(const Settings* settings, |
| 788 const SourceDir& source_dir) { |
| 789 return GetOutputDirForSourceDirAsOutputFile( |
| 790 settings->build_settings(), source_dir, |
| 791 settings->toolchain_label(), settings->is_default()); |
| 792 } |
| 793 |
| 774 SourceDir GetGenDirForSourceDir(const Settings* settings, | 794 SourceDir GetGenDirForSourceDir(const Settings* settings, |
| 775 const SourceDir& source_dir) { | 795 const SourceDir& source_dir) { |
| 776 return GetGenDirForSourceDirAsOutputFile(settings, source_dir).AsSourceDir( | 796 return GetGenDirForSourceDirAsOutputFile(settings, source_dir).AsSourceDir( |
| 777 settings->build_settings()); | 797 settings->build_settings()); |
| 778 } | 798 } |
| 779 | 799 |
| 780 OutputFile GetGenDirForSourceDirAsOutputFile(const Settings* settings, | 800 OutputFile GetGenDirForSourceDirAsOutputFile(const Settings* settings, |
| 781 const SourceDir& source_dir) { | 801 const SourceDir& source_dir) { |
| 782 OutputFile result = GetToolchainGenDirAsOutputFile(settings); | 802 OutputFile result = GetToolchainGenDirAsOutputFile(settings); |
| 783 | 803 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 814 | 834 |
| 815 SourceDir GetCurrentOutputDir(const Scope* scope) { | 835 SourceDir GetCurrentOutputDir(const Scope* scope) { |
| 816 return GetOutputDirForSourceDirAsOutputFile( | 836 return GetOutputDirForSourceDirAsOutputFile( |
| 817 scope->settings(), scope->GetSourceDir()).AsSourceDir( | 837 scope->settings(), scope->GetSourceDir()).AsSourceDir( |
| 818 scope->settings()->build_settings()); | 838 scope->settings()->build_settings()); |
| 819 } | 839 } |
| 820 | 840 |
| 821 SourceDir GetCurrentGenDir(const Scope* scope) { | 841 SourceDir GetCurrentGenDir(const Scope* scope) { |
| 822 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); | 842 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); |
| 823 } | 843 } |
| OLD | NEW |