| 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/scope_per_file_provider.h" | 5 #include "tools/gn/scope_per_file_provider.h" |
| 6 | 6 |
| 7 #include "tools/gn/filesystem_utils.h" | 7 #include "tools/gn/filesystem_utils.h" |
| 8 #include "tools/gn/settings.h" | 8 #include "tools/gn/settings.h" |
| 9 #include "tools/gn/source_file.h" | 9 #include "tools/gn/source_file.h" |
| 10 #include "tools/gn/value.h" | 10 #include "tools/gn/value.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 const Value* ScopePerFileProvider::GetPythonPath() { | 59 const Value* ScopePerFileProvider::GetPythonPath() { |
| 60 if (!python_path_) { | 60 if (!python_path_) { |
| 61 python_path_.reset(new Value(NULL, | 61 python_path_.reset(new Value(NULL, |
| 62 FilePathToUTF8(scope_->settings()->build_settings()->python_path()))); | 62 FilePathToUTF8(scope_->settings()->build_settings()->python_path()))); |
| 63 } | 63 } |
| 64 return python_path_.get(); | 64 return python_path_.get(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 const Value* ScopePerFileProvider::GetRootBuildDir() { | 67 const Value* ScopePerFileProvider::GetRootBuildDir() { |
| 68 if (!root_build_dir_) { | 68 if (!root_build_dir_) { |
| 69 root_build_dir_.reset(new Value(NULL, | 69 root_build_dir_.reset(new Value(NULL, DirectoryWithNoLastSlash( |
| 70 "/" + GetRootOutputDirWithNoLastSlash(scope_->settings()))); | 70 scope_->settings()->build_settings()->build_dir()))); |
| 71 } | 71 } |
| 72 return root_build_dir_.get(); | 72 return root_build_dir_.get(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 const Value* ScopePerFileProvider::GetRootGenDir() { | 75 const Value* ScopePerFileProvider::GetRootGenDir() { |
| 76 if (!root_gen_dir_) { | 76 if (!root_gen_dir_) { |
| 77 root_gen_dir_.reset(new Value(NULL, | 77 root_gen_dir_.reset(new Value(NULL, |
| 78 "/" + GetToolchainGenDirWithNoLastSlash(scope_->settings()))); | 78 DirectoryWithNoLastSlash(GetToolchainGenDir(scope_->settings())))); |
| 79 } | 79 } |
| 80 return root_gen_dir_.get(); | 80 return root_gen_dir_.get(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 const Value* ScopePerFileProvider::GetRootOutDir() { | 83 const Value* ScopePerFileProvider::GetRootOutDir() { |
| 84 if (!root_out_dir_) { | 84 if (!root_out_dir_) { |
| 85 root_out_dir_.reset(new Value(NULL, | 85 root_out_dir_.reset(new Value(NULL, |
| 86 "/" + GetToolchainOutputDirWithNoLastSlash(scope_->settings()))); | 86 DirectoryWithNoLastSlash(GetToolchainOutputDir(scope_->settings())))); |
| 87 } | 87 } |
| 88 return root_out_dir_.get(); | 88 return root_out_dir_.get(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 const Value* ScopePerFileProvider::GetTargetGenDir() { | 91 const Value* ScopePerFileProvider::GetTargetGenDir() { |
| 92 if (!target_gen_dir_) { | 92 if (!target_gen_dir_) { |
| 93 target_gen_dir_.reset(new Value(NULL, | 93 target_gen_dir_.reset(new Value(NULL, |
| 94 "/" + | 94 DirectoryWithNoLastSlash(GetCurrentGenDir(scope_)))); |
| 95 GetToolchainGenDirWithNoLastSlash(scope_->settings()) + | |
| 96 GetFileDirWithNoLastSlash())); | |
| 97 } | 95 } |
| 98 return target_gen_dir_.get(); | 96 return target_gen_dir_.get(); |
| 99 } | 97 } |
| 100 | 98 |
| 101 const Value* ScopePerFileProvider::GetTargetOutDir() { | 99 const Value* ScopePerFileProvider::GetTargetOutDir() { |
| 102 if (!target_out_dir_) { | 100 if (!target_out_dir_) { |
| 103 target_out_dir_.reset(new Value(NULL, | 101 target_out_dir_.reset(new Value(NULL, |
| 104 "/" + | 102 DirectoryWithNoLastSlash(GetCurrentOutputDir(scope_)))); |
| 105 GetToolchainOutputDirWithNoLastSlash(scope_->settings()) + "/obj" + | |
| 106 GetFileDirWithNoLastSlash())); | |
| 107 } | 103 } |
| 108 return target_out_dir_.get(); | 104 return target_out_dir_.get(); |
| 109 } | 105 } |
| 110 | |
| 111 // static | |
| 112 std::string ScopePerFileProvider::GetRootOutputDirWithNoLastSlash( | |
| 113 const Settings* settings) { | |
| 114 const std::string& output_dir = | |
| 115 settings->build_settings()->build_dir().value(); | |
| 116 | |
| 117 if (output_dir == "//") | |
| 118 return "//."; | |
| 119 | |
| 120 // Trim off a leading and trailing slash. So "//foo/bar/" -> /foo/bar". | |
| 121 DCHECK(output_dir.size() > 2 && output_dir[0] == '/' && | |
| 122 output_dir[output_dir.size() - 1] == '/'); | |
| 123 return output_dir.substr(1, output_dir.size() - 2); | |
| 124 } | |
| 125 | |
| 126 // static | |
| 127 std::string ScopePerFileProvider::GetToolchainOutputDirWithNoLastSlash( | |
| 128 const Settings* settings) { | |
| 129 const OutputFile& toolchain_subdir = settings->toolchain_output_subdir(); | |
| 130 | |
| 131 std::string result; | |
| 132 if (toolchain_subdir.value().empty()) { | |
| 133 result = GetRootOutputDirWithNoLastSlash(settings); | |
| 134 } else { | |
| 135 // The toolchain subdir ends in a slash, trim it. | |
| 136 result = GetRootOutputDirWithNoLastSlash(settings) + "/" + | |
| 137 toolchain_subdir.value(); | |
| 138 DCHECK(toolchain_subdir.value()[toolchain_subdir.value().size() - 1] == | |
| 139 '/'); | |
| 140 result.resize(result.size() - 1); | |
| 141 } | |
| 142 return result; | |
| 143 } | |
| 144 | |
| 145 // static | |
| 146 std::string ScopePerFileProvider::GetToolchainGenDirWithNoLastSlash( | |
| 147 const Settings* settings) { | |
| 148 return GetToolchainOutputDirWithNoLastSlash(settings) + "/gen"; | |
| 149 } | |
| 150 | |
| 151 std::string ScopePerFileProvider::GetFileDirWithNoLastSlash() const { | |
| 152 const std::string& dir_value = scope_->GetSourceDir().value(); | |
| 153 | |
| 154 if (dir_value == "//") | |
| 155 return "//."; | |
| 156 | |
| 157 // Trim off a leading and trailing slash. So "//foo/bar/" -> /foo/bar". | |
| 158 DCHECK(dir_value.size() > 2 && dir_value[0] == '/' && | |
| 159 dir_value[dir_value.size() - 1] == '/'); | |
| 160 return dir_value.substr(1, dir_value.size() - 2); | |
| 161 } | |
| OLD | NEW |