| 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 "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "tools/gn/filesystem_utils.h" | 9 #include "tools/gn/filesystem_utils.h" |
| 10 #include "tools/gn/string_utils.h" | 10 #include "tools/gn/string_utils.h" |
| 11 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 const char kLibDirWithSlash[] = "lib/"; | |
| 16 const char kObjectDirNoSlash[] = "obj"; | 15 const char kObjectDirNoSlash[] = "obj"; |
| 17 | 16 |
| 18 } // namespace | 17 } // namespace |
| 19 | 18 |
| 20 NinjaHelper::NinjaHelper(const BuildSettings* build_settings) | 19 NinjaHelper::NinjaHelper(const BuildSettings* build_settings) |
| 21 : build_settings_(build_settings) { | 20 : build_settings_(build_settings) { |
| 22 build_to_src_no_last_slash_ = build_settings->build_to_source_dir_string(); | 21 build_to_src_no_last_slash_ = build_settings->build_to_source_dir_string(); |
| 23 if (!build_to_src_no_last_slash_.empty() && | 22 if (!build_to_src_no_last_slash_.empty() && |
| 24 build_to_src_no_last_slash_[build_to_src_no_last_slash_.size() - 1] == | 23 build_to_src_no_last_slash_[build_to_src_no_last_slash_.size() - 1] == |
| 25 '/') | 24 '/') |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 target->settings()->target_os()); | 170 target->settings()->target_os()); |
| 172 } | 171 } |
| 173 } else { | 172 } else { |
| 174 extension = target->output_extension().c_str(); | 173 extension = target->output_extension().c_str(); |
| 175 } | 174 } |
| 176 | 175 |
| 177 // Everything goes into the toolchain directory (which will be empty for the | 176 // Everything goes into the toolchain directory (which will be empty for the |
| 178 // default toolchain, and will end in a slash otherwise). | 177 // default toolchain, and will end in a slash otherwise). |
| 179 ret.value().append(target->settings()->toolchain_output_subdir().value()); | 178 ret.value().append(target->settings()->toolchain_output_subdir().value()); |
| 180 | 179 |
| 181 // Binaries and loadable libraries go into the toolchain root. | 180 // Binaries and shared libraries go into the toolchain root. |
| 182 if (target->output_type() == Target::EXECUTABLE || | 181 if (target->output_type() == Target::EXECUTABLE || |
| 183 ((target->settings()->IsMac() || target->settings()->IsWin()) && | 182 target->output_type() == Target::SHARED_LIBRARY) { |
| 184 target->output_type() == Target::SHARED_LIBRARY)) { | |
| 185 // Generate a name like "<toolchain>/<prefix><name>.<extension>". | 183 // Generate a name like "<toolchain>/<prefix><name>.<extension>". |
| 186 ret.value().append(prefix); | 184 ret.value().append(prefix); |
| 187 ret.value().append(name); | 185 ret.value().append(name); |
| 188 if (extension[0]) { | 186 if (extension[0]) { |
| 189 ret.value().push_back('.'); | 187 ret.value().push_back('.'); |
| 190 ret.value().append(extension); | 188 ret.value().append(extension); |
| 191 } | 189 } |
| 192 return ret; | 190 return ret; |
| 193 } | 191 } |
| 194 | 192 |
| 195 // Libraries go into the library subdirectory like | |
| 196 // "<toolchain>/lib/<prefix><name>.<extension>". | |
| 197 if (target->output_type() == Target::SHARED_LIBRARY) { | |
| 198 ret.value().append(kLibDirWithSlash); | |
| 199 ret.value().append(prefix); | |
| 200 ret.value().append(name); | |
| 201 if (extension[0]) { | |
| 202 ret.value().push_back('.'); | |
| 203 ret.value().append(extension); | |
| 204 } | |
| 205 return ret; | |
| 206 } | |
| 207 | |
| 208 // Everything else goes next to the target's .ninja file like | 193 // Everything else goes next to the target's .ninja file like |
| 209 // "<toolchain>/obj/<path>/<name>.<extension>". | 194 // "<toolchain>/obj/<path>/<name>.<extension>". |
| 210 ret.value().append(kObjectDirNoSlash); | 195 ret.value().append(kObjectDirNoSlash); |
| 211 AppendStringPiece(&ret.value(), | 196 AppendStringPiece(&ret.value(), |
| 212 target->label().dir().SourceAbsoluteWithOneSlash()); | 197 target->label().dir().SourceAbsoluteWithOneSlash()); |
| 213 ret.value().append(prefix); | 198 ret.value().append(prefix); |
| 214 ret.value().append(name); | 199 ret.value().append(name); |
| 215 if (extension[0]) { | 200 if (extension[0]) { |
| 216 ret.value().push_back('.'); | 201 ret.value().push_back('.'); |
| 217 ret.value().append(extension); | 202 ret.value().append(extension); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 246 return prefix + "rc"; | 231 return prefix + "rc"; |
| 247 if (type == SOURCE_S) | 232 if (type == SOURCE_S) |
| 248 return prefix + "cc"; // Assembly files just get compiled by CC. | 233 return prefix + "cc"; // Assembly files just get compiled by CC. |
| 249 | 234 |
| 250 // TODO(brettw) asm files. | 235 // TODO(brettw) asm files. |
| 251 | 236 |
| 252 // .obj files have no rules to make them (they're already built) so we return | 237 // .obj files have no rules to make them (they're already built) so we return |
| 253 // the enpty string for SOURCE_O. | 238 // the enpty string for SOURCE_O. |
| 254 return std::string(); | 239 return std::string(); |
| 255 } | 240 } |
| OLD | NEW |