Chromium Code Reviews| 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/gyp_binary_target_writer.h" | 5 #include "tools/gn/gyp_binary_target_writer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "tools/gn/config_values_extractors.h" | 10 #include "tools/gn/config_values_extractors.h" |
| 11 #include "tools/gn/err.h" | 11 #include "tools/gn/err.h" |
| 12 #include "tools/gn/escape.h" | 12 #include "tools/gn/escape.h" |
| 13 #include "tools/gn/filesystem_utils.h" | |
| 13 #include "tools/gn/settings.h" | 14 #include "tools/gn/settings.h" |
| 14 #include "tools/gn/target.h" | 15 #include "tools/gn/target.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // This functor is used to capture the output of RecursiveTargetConfigToStream | 19 // This functor is used to capture the output of RecursiveTargetConfigToStream |
| 19 // in an vector. | 20 // in an vector. |
| 20 template<typename T> | 21 template<typename T> |
| 21 struct Accumulator { | 22 struct Accumulator { |
| 22 Accumulator(std::vector<T>* result_in) : result(result_in) {} | 23 Accumulator(std::vector<T>* result_in) : result(result_in) {} |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 } | 126 } |
| 126 | 127 |
| 127 void GypBinaryTargetWriter::Run() { | 128 void GypBinaryTargetWriter::Run() { |
| 128 int indent = 4; | 129 int indent = 4; |
| 129 | 130 |
| 130 Indent(indent) << "{\n"; | 131 Indent(indent) << "{\n"; |
| 131 | 132 |
| 132 WriteName(indent + kExtraIndent); | 133 WriteName(indent + kExtraIndent); |
| 133 WriteType(indent + kExtraIndent); | 134 WriteType(indent + kExtraIndent); |
| 134 | 135 |
| 135 if (target_->settings()->IsLinux()) { | 136 if (target_->settings()->IsLinux()) |
| 136 WriteLinuxConfiguration(indent + kExtraIndent); | 137 WriteLinuxConfiguration(indent + kExtraIndent); |
| 137 } else if (target_->settings()->IsWin()) { | 138 else if (target_->settings()->IsWin()) |
| 138 WriteVCConfiguration(indent + kExtraIndent); | 139 WriteVCConfiguration(indent + kExtraIndent); |
| 139 } else if (target_->settings()->IsMac()) { | 140 else if (target_->settings()->IsMac()) |
| 140 // TODO(brettw) mac. | 141 WriteMacConfiguration(indent + kExtraIndent); |
| 141 NOTREACHED(); | |
| 142 //WriteMacConfiguration(); | |
| 143 } | |
| 144 WriteDirectDependentSettings(indent + kExtraIndent); | 142 WriteDirectDependentSettings(indent + kExtraIndent); |
| 145 WriteAllDependentSettings(indent + kExtraIndent); | 143 WriteAllDependentSettings(indent + kExtraIndent); |
| 146 | 144 |
| 147 Indent(indent) << "},\n"; | 145 Indent(indent) << "},\n"; |
| 148 } | 146 } |
| 149 | 147 |
| 150 std::ostream& GypBinaryTargetWriter::Indent(int spaces) { | 148 std::ostream& GypBinaryTargetWriter::Indent(int spaces) { |
| 151 return ::Indent(out_, spaces); | 149 return ::Indent(out_, spaces); |
| 152 } | 150 } |
| 153 | 151 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 | 247 |
| 250 WriteSources(target_, indent + kExtraIndent * 2); | 248 WriteSources(target_, indent + kExtraIndent * 2); |
| 251 | 249 |
| 252 Indent(indent + kExtraIndent) << "},],\n"; | 250 Indent(indent + kExtraIndent) << "},],\n"; |
| 253 Indent(indent) << "],\n"; | 251 Indent(indent) << "],\n"; |
| 254 | 252 |
| 255 // Deps in GYP can not vary based on the toolset. | 253 // Deps in GYP can not vary based on the toolset. |
| 256 WriteDeps(target_, indent); | 254 WriteDeps(target_, indent); |
| 257 } | 255 } |
| 258 | 256 |
| 257 void GypBinaryTargetWriter::WriteMacConfiguration(int indent) { | |
| 258 Indent(indent) << "'configurations': {\n"; | |
| 259 | |
| 260 Indent(indent + kExtraIndent) << "'Debug': {\n"; | |
| 261 Flags debug_flags(FlagsFromTarget(group_.debug)); | |
| 262 WriteMacFlags(debug_flags, indent + kExtraIndent * 2); | |
| 263 Indent(indent + kExtraIndent) << "},\n"; | |
| 264 | |
| 265 Indent(indent + kExtraIndent) << "'Release': {\n"; | |
| 266 Flags release_flags(FlagsFromTarget(group_.release)); | |
| 267 WriteMacFlags(release_flags, indent + kExtraIndent * 2); | |
| 268 Indent(indent + kExtraIndent) << "},\n"; | |
| 269 | |
| 270 Indent(indent) << "},\n"; | |
| 271 | |
| 272 WriteSources(target_, indent); | |
| 273 WriteDeps(target_, indent); | |
| 274 } | |
| 275 | |
| 259 void GypBinaryTargetWriter::WriteVCFlags(Flags& flags, int indent) { | 276 void GypBinaryTargetWriter::WriteVCFlags(Flags& flags, int indent) { |
| 260 // Defines and includes go outside of the msvs settings. | 277 // Defines and includes go outside of the msvs settings. |
| 261 WriteNamedArray(out_, "defines", flags.defines, indent); | 278 WriteNamedArray(out_, "defines", flags.defines, indent); |
| 262 WriteIncludeDirs(flags, indent); | 279 WriteIncludeDirs(flags, indent); |
| 263 | 280 |
| 264 // C flags. | 281 // C flags. |
| 265 Indent(indent) << "'msvs_settings': {\n"; | 282 Indent(indent) << "'msvs_settings': {\n"; |
| 266 Indent(indent + kExtraIndent) << "'VCCLCompilerTool': {\n"; | 283 Indent(indent + kExtraIndent) << "'VCCLCompilerTool': {\n"; |
| 267 | 284 |
| 268 // GYP always uses the VC optimization flag to add a /O? on Visual Studio. | 285 // GYP always uses the VC optimization flag to add a /O? on Visual Studio. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 299 indent + kExtraIndent * 2); | 316 indent + kExtraIndent * 2); |
| 300 | 317 |
| 301 // ...LD flags. | 318 // ...LD flags. |
| 302 // TODO(brettw) EnableUAC defaults to on and needs to be set. Also | 319 // TODO(brettw) EnableUAC defaults to on and needs to be set. Also |
| 303 // UACExecutionLevel and UACUIAccess depends on that and defaults to 0/false. | 320 // UACExecutionLevel and UACUIAccess depends on that and defaults to 0/false. |
| 304 WriteNamedArray(out_, "AdditionalOptions", flags.ldflags, 14); | 321 WriteNamedArray(out_, "AdditionalOptions", flags.ldflags, 14); |
| 305 Indent(indent + kExtraIndent) << "},\n"; | 322 Indent(indent + kExtraIndent) << "},\n"; |
| 306 Indent(indent) << "},\n"; | 323 Indent(indent) << "},\n"; |
| 307 } | 324 } |
| 308 | 325 |
| 326 void GypBinaryTargetWriter::WriteMacFlags(Flags& flags, int indent) { | |
| 327 WriteNamedArray(out_, "defines", flags.defines, indent); | |
| 328 WriteIncludeDirs(flags, indent); | |
| 329 | |
| 330 // Libraries and library directories. | |
| 331 EscapeOptions escape_options; | |
| 332 escape_options.mode = ESCAPE_JSON; | |
| 333 if (!flags.lib_dirs.empty()) { | |
| 334 Indent(indent + kExtraIndent) << "'library_dirs': ["; | |
| 335 for (size_t i = 0; i < flags.lib_dirs.size(); i++) { | |
| 336 out_ << " '"; | |
| 337 EscapeStringToStream(out_, | |
| 338 helper_.GetDirReference(flags.lib_dirs[i], false), | |
| 339 escape_options); | |
| 340 out_ << "',"; | |
| 341 } | |
| 342 out_ << " ],\n"; | |
| 343 } | |
| 344 if (!flags.libs.empty()) { | |
| 345 Indent(indent) << "'link_settings': {\n"; | |
| 346 Indent(indent + kExtraIndent) << "'libraries': ["; | |
| 347 for (size_t i = 0; i < flags.libs.size(); i++) { | |
| 348 out_ << " '-l"; | |
| 349 EscapeStringToStream(out_, flags.libs[i], escape_options); | |
| 350 out_ << "',"; | |
| 351 } | |
| 352 out_ << " ],\n"; | |
| 353 Indent(indent) << "},\n"; | |
| 354 } | |
| 355 | |
| 356 Indent(indent) << "'xcode_settings': {\n"; | |
| 357 | |
| 358 // C/C++ flags. | |
| 359 if (!flags.cflags.empty() || !flags.cflags_c.empty() || | |
| 360 !flags.cflags_objc.empty()) { | |
| 361 Indent(indent + kExtraIndent) << "'OTHER_CFLAGS': ["; | |
| 362 WriteArrayValues(out_, flags.cflags); | |
| 363 WriteArrayValues(out_, flags.cflags_c); | |
| 364 WriteArrayValues(out_, flags.cflags_objc); | |
|
Nico
2013/10/28 23:05:14
OTHER_CFLAGS is used for both C and Obj-C flags.
| |
| 365 out_ << " ],\n"; | |
| 366 } | |
| 367 if (!flags.cflags.empty() || !flags.cflags_cc.empty() || | |
| 368 !flags.cflags_objcc.empty()) { | |
| 369 Indent(indent + kExtraIndent) << "'OTHER_CPLUSPLUSFLAGS': ["; | |
| 370 WriteArrayValues(out_, flags.cflags); | |
| 371 WriteArrayValues(out_, flags.cflags_cc); | |
| 372 WriteArrayValues(out_, flags.cflags_objcc); | |
| 373 out_ << " ],\n"; | |
| 374 } | |
| 375 | |
| 376 // Ld flags. Don't write these for static libraries. Otherwise, they'll be | |
| 377 // passed to the library tool which doesn't expect it (the toolchain does | |
| 378 // not use ldflags so these are ignored in the normal build). | |
| 379 if (target_->output_type() != Target::STATIC_LIBRARY) { | |
| 380 WriteNamedArray(out_, "OTHER_LDFLAGS", flags.ldflags, | |
| 381 indent + kExtraIndent); | |
| 382 } | |
| 383 | |
| 384 base::FilePath clang_path = | |
| 385 target_->settings()->build_settings()->GetFullPath(SourceFile( | |
| 386 "//third_party/llvm-build/Release+Asserts/bin/clang")); | |
| 387 base::FilePath clang_pp_path = | |
| 388 target_->settings()->build_settings()->GetFullPath(SourceFile( | |
| 389 "//third_party/llvm-build/Release+Asserts/bin/clang++")); | |
| 390 | |
| 391 Indent(indent) << "'CC': '" << FilePathToUTF8(clang_path) << "',\n"; | |
| 392 Indent(indent) << "'LDPLUSPLUS': '" | |
| 393 << FilePathToUTF8(clang_pp_path) << "',\n"; | |
|
Nico
2013/10/28 23:05:14
gyp's ninja generator doesn't use CC and LDPLUSPLU
| |
| 394 | |
| 395 Indent(indent) << "},\n"; | |
| 396 } | |
| 397 | |
| 309 void GypBinaryTargetWriter::WriteLinuxFlagsForTarget(const Target* target, | 398 void GypBinaryTargetWriter::WriteLinuxFlagsForTarget(const Target* target, |
| 310 int indent) { | 399 int indent) { |
| 311 Flags flags(FlagsFromTarget(target)); | 400 Flags flags(FlagsFromTarget(target)); |
| 312 WriteLinuxFlags(flags, indent); | 401 WriteLinuxFlags(flags, indent); |
| 313 } | 402 } |
| 314 | 403 |
| 315 void GypBinaryTargetWriter::WriteLinuxFlags(const Flags& flags, int indent) { | 404 void GypBinaryTargetWriter::WriteLinuxFlags(const Flags& flags, int indent) { |
| 316 WriteIncludeDirs(flags, indent); | 405 WriteIncludeDirs(flags, indent); |
| 317 WriteNamedArray(out_, "defines", flags.defines, indent); | 406 WriteNamedArray(out_, "defines", flags.defines, indent); |
| 318 WriteNamedArray(out_, "cflags", flags.cflags, indent); | 407 WriteNamedArray(out_, "cflags", flags.cflags, indent); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 } | 480 } |
| 392 out_ << " ],\n"; | 481 out_ << " ],\n"; |
| 393 } | 482 } |
| 394 | 483 |
| 395 void GypBinaryTargetWriter::WriteDirectDependentSettings(int indent) { | 484 void GypBinaryTargetWriter::WriteDirectDependentSettings(int indent) { |
| 396 if (target_->direct_dependent_configs().empty()) | 485 if (target_->direct_dependent_configs().empty()) |
| 397 return; | 486 return; |
| 398 out_ << "'direct_dependent_settings': {\n"; | 487 out_ << "'direct_dependent_settings': {\n"; |
| 399 | 488 |
| 400 Flags flags(FlagsFromConfigList(target_->direct_dependent_configs())); | 489 Flags flags(FlagsFromConfigList(target_->direct_dependent_configs())); |
| 401 if (target_->settings()->IsLinux()) { | 490 if (target_->settings()->IsLinux()) |
| 402 WriteLinuxFlags(flags, indent + kExtraIndent); | 491 WriteLinuxFlags(flags, indent + kExtraIndent); |
| 403 } else if (target_->settings()->IsWin()) { | 492 else if (target_->settings()->IsWin()) |
| 404 WriteVCFlags(flags, indent + kExtraIndent); | 493 WriteVCFlags(flags, indent + kExtraIndent); |
| 405 } else if (target_->settings()->IsMac()) { | 494 else if (target_->settings()->IsMac()) |
| 406 // TODO(brettw) write mac. | 495 WriteMacFlags(flags, indent + kExtraIndent); |
| 407 NOTREACHED(); | |
| 408 } | |
| 409 Indent(indent) << "},\n"; | 496 Indent(indent) << "},\n"; |
| 410 } | 497 } |
| 411 | 498 |
| 412 void GypBinaryTargetWriter::WriteAllDependentSettings(int indent) { | 499 void GypBinaryTargetWriter::WriteAllDependentSettings(int indent) { |
| 413 if (target_->all_dependent_configs().empty()) | 500 if (target_->all_dependent_configs().empty()) |
| 414 return; | 501 return; |
| 415 Indent(indent) << "'all_dependent_settings': {\n"; | 502 Indent(indent) << "'all_dependent_settings': {\n"; |
| 416 | 503 |
| 417 Flags flags(FlagsFromConfigList(target_->all_dependent_configs())); | 504 Flags flags(FlagsFromConfigList(target_->all_dependent_configs())); |
| 418 if (target_->settings()->IsLinux()) { | 505 if (target_->settings()->IsLinux()) |
| 419 WriteLinuxFlags(flags, indent + kExtraIndent); | 506 WriteLinuxFlags(flags, indent + kExtraIndent); |
| 420 } else if (target_->settings()->IsWin()) { | 507 else if (target_->settings()->IsWin()) |
| 421 WriteVCFlags(flags, indent + kExtraIndent); | 508 WriteVCFlags(flags, indent + kExtraIndent); |
| 422 } else if (target_->settings()->IsMac()) { | 509 else if (target_->settings()->IsMac()) |
| 423 // TODO(brettw) write mac. | 510 WriteMacFlags(flags, indent + kExtraIndent); |
| 424 NOTREACHED(); | |
| 425 } | |
| 426 Indent(indent) << "},\n"; | 511 Indent(indent) << "},\n"; |
| 427 } | 512 } |
| 428 | 513 |
| 429 GypBinaryTargetWriter::Flags GypBinaryTargetWriter::FlagsFromTarget( | 514 GypBinaryTargetWriter::Flags GypBinaryTargetWriter::FlagsFromTarget( |
| 430 const Target* target) const { | 515 const Target* target) const { |
| 431 Flags ret; | 516 Flags ret; |
| 432 | 517 |
| 433 // Extracts a vector of the given type and name from the config values. | 518 // Extracts a vector of the given type and name from the config values. |
| 434 #define EXTRACT(type, name) \ | 519 #define EXTRACT(type, name) \ |
| 435 { \ | 520 { \ |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 EXTRACT(std::string, cflags_objc); | 560 EXTRACT(std::string, cflags_objc); |
| 476 EXTRACT(std::string, cflags_objcc); | 561 EXTRACT(std::string, cflags_objcc); |
| 477 EXTRACT(std::string, ldflags); | 562 EXTRACT(std::string, ldflags); |
| 478 EXTRACT(SourceDir, lib_dirs); | 563 EXTRACT(SourceDir, lib_dirs); |
| 479 EXTRACT(std::string, libs); | 564 EXTRACT(std::string, libs); |
| 480 | 565 |
| 481 #undef EXTRACT | 566 #undef EXTRACT |
| 482 | 567 |
| 483 return ret; | 568 return ret; |
| 484 } | 569 } |
| OLD | NEW |