| 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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 } | 660 } |
| 661 return SourceDir(result_str); | 661 return SourceDir(result_str); |
| 662 } | 662 } |
| 663 | 663 |
| 664 SourceDir SourceDirForCurrentDirectory(const base::FilePath& source_root) { | 664 SourceDir SourceDirForCurrentDirectory(const base::FilePath& source_root) { |
| 665 base::FilePath cd; | 665 base::FilePath cd; |
| 666 base::GetCurrentDirectory(&cd); | 666 base::GetCurrentDirectory(&cd); |
| 667 return SourceDirForPath(source_root, cd); | 667 return SourceDirForPath(source_root, cd); |
| 668 } | 668 } |
| 669 | 669 |
| 670 std::string GetOutputSubdirName(const Label& toolchain_label, bool is_default) { |
| 671 // The default toolchain has no subdir. |
| 672 if (is_default) |
| 673 return std::string(); |
| 674 |
| 675 // For now just assume the toolchain name is always a valid dir name. We may |
| 676 // want to clean up the in the future. |
| 677 return toolchain_label.name() + "/"; |
| 678 } |
| 679 |
| 670 SourceDir GetToolchainOutputDir(const Settings* settings) { | 680 SourceDir GetToolchainOutputDir(const Settings* settings) { |
| 671 const OutputFile& toolchain_subdir = settings->toolchain_output_subdir(); | 681 const OutputFile& toolchain_subdir = settings->toolchain_output_subdir(); |
| 672 | 682 |
| 673 std::string result = settings->build_settings()->build_dir().value(); | 683 std::string result = settings->build_settings()->build_dir().value(); |
| 674 if (!toolchain_subdir.value().empty()) | 684 if (!toolchain_subdir.value().empty()) |
| 675 result.append(toolchain_subdir.value()); | 685 result.append(toolchain_subdir.value()); |
| 676 | 686 |
| 677 return SourceDir(SourceDir::SWAP_IN, &result); | 687 return SourceDir(SourceDir::SWAP_IN, &result); |
| 678 } | 688 } |
| 679 | 689 |
| 690 SourceDir GetToolchainOutputDir(const BuildSettings* build_settings, |
| 691 const Label& toolchain_label, bool is_default) { |
| 692 std::string result = build_settings->build_dir().value(); |
| 693 result.append(GetOutputSubdirName(toolchain_label, is_default)); |
| 694 return SourceDir(SourceDir::SWAP_IN, &result); |
| 695 } |
| 696 |
| 680 SourceDir GetToolchainGenDir(const Settings* settings) { | 697 SourceDir GetToolchainGenDir(const Settings* settings) { |
| 681 const OutputFile& toolchain_subdir = settings->toolchain_output_subdir(); | 698 const OutputFile& toolchain_subdir = settings->toolchain_output_subdir(); |
| 682 | 699 |
| 683 std::string result = settings->build_settings()->build_dir().value(); | 700 std::string result = settings->build_settings()->build_dir().value(); |
| 684 if (!toolchain_subdir.value().empty()) | 701 if (!toolchain_subdir.value().empty()) |
| 685 result.append(toolchain_subdir.value()); | 702 result.append(toolchain_subdir.value()); |
| 686 | 703 |
| 687 result.append("gen/"); | 704 result.append("gen/"); |
| 688 return SourceDir(SourceDir::SWAP_IN, &result); | 705 return SourceDir(SourceDir::SWAP_IN, &result); |
| 689 } | 706 } |
| 690 | 707 |
| 708 SourceDir GetToolchainGenDir(const BuildSettings* build_settings, |
| 709 const Label& toolchain_label, bool is_default) { |
| 710 std::string result = GetToolchainOutputDir( |
| 711 build_settings, toolchain_label, is_default).value(); |
| 712 result.append("gen/"); |
| 713 return SourceDir(SourceDir::SWAP_IN, &result); |
| 714 } |
| 715 |
| 691 SourceDir GetOutputDirForSourceDir(const Settings* settings, | 716 SourceDir GetOutputDirForSourceDir(const Settings* settings, |
| 692 const SourceDir& source_dir) { | 717 const SourceDir& source_dir) { |
| 693 SourceDir toolchain = GetToolchainOutputDir(settings); | 718 SourceDir toolchain = GetToolchainOutputDir(settings); |
| 694 | 719 |
| 695 std::string ret; | 720 std::string ret; |
| 696 toolchain.SwapValue(&ret); | 721 toolchain.SwapValue(&ret); |
| 697 ret.append("obj/"); | 722 ret.append("obj/"); |
| 698 | 723 |
| 699 // The source dir should be source-absolute, so we trim off the two leading | 724 // The source dir should be source-absolute, so we trim off the two leading |
| 700 // slashes to append to the toolchain object directory. | 725 // slashes to append to the toolchain object directory. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 727 return GetGenDirForSourceDir(target->settings(), target->label().dir()); | 752 return GetGenDirForSourceDir(target->settings(), target->label().dir()); |
| 728 } | 753 } |
| 729 | 754 |
| 730 SourceDir GetCurrentOutputDir(const Scope* scope) { | 755 SourceDir GetCurrentOutputDir(const Scope* scope) { |
| 731 return GetOutputDirForSourceDir(scope->settings(), scope->GetSourceDir()); | 756 return GetOutputDirForSourceDir(scope->settings(), scope->GetSourceDir()); |
| 732 } | 757 } |
| 733 | 758 |
| 734 SourceDir GetCurrentGenDir(const Scope* scope) { | 759 SourceDir GetCurrentGenDir(const Scope* scope) { |
| 735 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); | 760 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); |
| 736 } | 761 } |
| OLD | NEW |