| 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 toolchain_subdir = |
| 693 GetOutputSubdirName(toolchain_label, is_default); |
| 694 |
| 695 std::string result = build_settings->build_dir().value(); |
| 696 if (!toolchain_subdir.empty()) { |
| 697 result.append(toolchain_subdir); |
| 698 result.push_back('/'); |
| 699 } |
| 700 return SourceDir(SourceDir::SWAP_IN, &result); |
| 701 } |
| 702 |
| 680 SourceDir GetToolchainGenDir(const Settings* settings) { | 703 SourceDir GetToolchainGenDir(const Settings* settings) { |
| 681 const OutputFile& toolchain_subdir = settings->toolchain_output_subdir(); | 704 const OutputFile& toolchain_subdir = settings->toolchain_output_subdir(); |
| 682 | 705 |
| 683 std::string result = settings->build_settings()->build_dir().value(); | 706 std::string result = settings->build_settings()->build_dir().value(); |
| 684 if (!toolchain_subdir.value().empty()) | 707 if (!toolchain_subdir.value().empty()) |
| 685 result.append(toolchain_subdir.value()); | 708 result.append(toolchain_subdir.value()); |
| 686 | 709 |
| 687 result.append("gen/"); | 710 result.append("gen/"); |
| 688 return SourceDir(SourceDir::SWAP_IN, &result); | 711 return SourceDir(SourceDir::SWAP_IN, &result); |
| 689 } | 712 } |
| 690 | 713 |
| 714 SourceDir GetToolchainGenDir(const BuildSettings* build_settings, |
| 715 const Label& toolchain_label, bool is_default) { |
| 716 std::string result = GetToolchainOutputDir( |
| 717 build_settings, toolchain_label, is_default).value(); |
| 718 result.append("gen/"); |
| 719 return SourceDir(SourceDir::SWAP_IN, &result); |
| 720 } |
| 721 |
| 691 SourceDir GetOutputDirForSourceDir(const Settings* settings, | 722 SourceDir GetOutputDirForSourceDir(const Settings* settings, |
| 692 const SourceDir& source_dir) { | 723 const SourceDir& source_dir) { |
| 693 SourceDir toolchain = GetToolchainOutputDir(settings); | 724 SourceDir toolchain = GetToolchainOutputDir(settings); |
| 694 | 725 |
| 695 std::string ret; | 726 std::string ret; |
| 696 toolchain.SwapValue(&ret); | 727 toolchain.SwapValue(&ret); |
| 697 ret.append("obj/"); | 728 ret.append("obj/"); |
| 698 | 729 |
| 699 // The source dir should be source-absolute, so we trim off the two leading | 730 // The source dir should be source-absolute, so we trim off the two leading |
| 700 // slashes to append to the toolchain object directory. | 731 // slashes to append to the toolchain object directory. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 727 return GetGenDirForSourceDir(target->settings(), target->label().dir()); | 758 return GetGenDirForSourceDir(target->settings(), target->label().dir()); |
| 728 } | 759 } |
| 729 | 760 |
| 730 SourceDir GetCurrentOutputDir(const Scope* scope) { | 761 SourceDir GetCurrentOutputDir(const Scope* scope) { |
| 731 return GetOutputDirForSourceDir(scope->settings(), scope->GetSourceDir()); | 762 return GetOutputDirForSourceDir(scope->settings(), scope->GetSourceDir()); |
| 732 } | 763 } |
| 733 | 764 |
| 734 SourceDir GetCurrentGenDir(const Scope* scope) { | 765 SourceDir GetCurrentGenDir(const Scope* scope) { |
| 735 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); | 766 return GetGenDirForSourceDir(scope->settings(), scope->GetSourceDir()); |
| 736 } | 767 } |
| OLD | NEW |