| 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/ninja_helper.h" | 5 #include "tools/gn/ninja_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "tools/gn/filesystem_utils.h" | 8 #include "tools/gn/filesystem_utils.h" |
| 9 #include "tools/gn/string_utils.h" | 9 #include "tools/gn/string_utils.h" |
| 10 #include "tools/gn/target.h" | 10 #include "tools/gn/target.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 target->label().dir().SourceAbsoluteWithOneSlash()); | 182 target->label().dir().SourceAbsoluteWithOneSlash()); |
| 183 ret.value().append(prefix); | 183 ret.value().append(prefix); |
| 184 ret.value().append(name); | 184 ret.value().append(name); |
| 185 if (extension[0]) { | 185 if (extension[0]) { |
| 186 ret.value().push_back('.'); | 186 ret.value().push_back('.'); |
| 187 ret.value().append(extension); | 187 ret.value().append(extension); |
| 188 } | 188 } |
| 189 return ret; | 189 return ret; |
| 190 } | 190 } |
| 191 | 191 |
| 192 std::string NinjaHelper::GetRulePrefix(const Settings* settings) const { | 192 std::string NinjaHelper::GetRulePrefix(const Toolchain* toolchain) const { |
| 193 // Don't prefix the default toolchain so it looks prettier, prefix everything | 193 // This code doesn't prefix the default toolchain commands. This is disabled |
| 194 // else. | 194 // so we can coexist with GYP's commands (which aren't prefixed). If we don't |
| 195 if (settings->is_default()) | 195 // need to coexist with GYP anymore, we can uncomment this to make things a |
| 196 return std::string(); // Default toolchain has no prefix. | 196 // bit prettier. |
| 197 return settings->toolchain_label().name() + "_"; | 197 //if (toolchain->is_default()) |
| 198 // return std::string(); // Default toolchain has no prefix. |
| 199 return toolchain->label().name() + "_"; |
| 198 } | 200 } |
| 199 | 201 |
| 200 std::string NinjaHelper::GetRuleForSourceType(const Settings* settings, | 202 std::string NinjaHelper::GetRuleForSourceType(const Settings* settings, |
| 203 const Toolchain* toolchain, |
| 201 SourceFileType type) const { | 204 SourceFileType type) const { |
| 202 // This function may be hot since it will be called for every source file | 205 // This function may be hot since it will be called for every source file |
| 203 // in the tree. We could cache the results to avoid making a string for | 206 // in the tree. We could cache the results to avoid making a string for |
| 204 // every invocation. | 207 // every invocation. |
| 205 std::string prefix = GetRulePrefix(settings); | 208 std::string prefix = GetRulePrefix(toolchain); |
| 206 | 209 |
| 207 if (type == SOURCE_C) | 210 if (type == SOURCE_C) |
| 208 return prefix + "cc"; | 211 return prefix + "cc"; |
| 209 if (type == SOURCE_CC) | 212 if (type == SOURCE_CC) |
| 210 return prefix + "cxx"; | 213 return prefix + "cxx"; |
| 211 | 214 |
| 212 // TODO(brettw) asm files. | 215 // TODO(brettw) asm files. |
| 213 | 216 |
| 214 if (settings->IsMac()) { | 217 if (settings->IsMac()) { |
| 215 if (type == SOURCE_M) | 218 if (type == SOURCE_M) |
| 216 return prefix + "objc"; | 219 return prefix + "objc"; |
| 217 if (type == SOURCE_MM) | 220 if (type == SOURCE_MM) |
| 218 return prefix + "objcxx"; | 221 return prefix + "objcxx"; |
| 219 } | 222 } |
| 220 | 223 |
| 221 if (settings->IsWin()) { | 224 if (settings->IsWin()) { |
| 222 if (type == SOURCE_RC) | 225 if (type == SOURCE_RC) |
| 223 return prefix + "rc"; | 226 return prefix + "rc"; |
| 224 } else { | 227 } else { |
| 225 if (type == SOURCE_S) | 228 if (type == SOURCE_S) |
| 226 return prefix + "cc"; // Assembly files just get compiled by CC. | 229 return prefix + "cc"; // Assembly files just get compiled by CC. |
| 227 } | 230 } |
| 228 | 231 |
| 229 return std::string(); | 232 return std::string(); |
| 230 } | 233 } |
| OLD | NEW |