| 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 "base/strings/string_util.h" |
| 10 #include "tools/gn/builder_record.h" | 11 #include "tools/gn/builder_record.h" |
| 11 #include "tools/gn/config_values_extractors.h" | 12 #include "tools/gn/config_values_extractors.h" |
| 12 #include "tools/gn/err.h" | 13 #include "tools/gn/err.h" |
| 13 #include "tools/gn/escape.h" | 14 #include "tools/gn/escape.h" |
| 14 #include "tools/gn/filesystem_utils.h" | 15 #include "tools/gn/filesystem_utils.h" |
| 15 #include "tools/gn/settings.h" | 16 #include "tools/gn/settings.h" |
| 16 #include "tools/gn/target.h" | 17 #include "tools/gn/target.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 case '1': return "'1'"; | 60 case '1': return "'1'"; |
| 60 case '2': return "'2'"; | 61 case '2': return "'2'"; |
| 61 case 'x': return "'3'"; | 62 case 'x': return "'3'"; |
| 62 default: return "'2'"; | 63 default: return "'2'"; |
| 63 } | 64 } |
| 64 } | 65 } |
| 65 } | 66 } |
| 66 return "'2'"; // Default value. | 67 return "'2'"; // Default value. |
| 67 } | 68 } |
| 68 | 69 |
| 70 // Returns the value from the already-filled in cflags for the processor |
| 71 // architecture to set in the GYP file. Additionally, this removes the flag |
| 72 // from the given vector so we don't get duplicates. |
| 73 std::string GetMacArch(std::vector<std::string>* cflags) { |
| 74 // Searches for the "-arch" option and returns the corresponding GYP value. |
| 75 for (size_t i = 0; i < cflags->size(); i++) { |
| 76 const std::string& cur = (*cflags)[i]; |
| 77 if (cur == "-arch") { |
| 78 // This is the first part of a list with ["-arch", "i386"], return the |
| 79 // following item, and delete both of them. |
| 80 if (i < cflags->size() - 1) { |
| 81 std::string ret = (*cflags)[i + 1]; |
| 82 cflags->erase(cflags->begin() + i, cflags->begin() + i + 2); |
| 83 return ret; |
| 84 } |
| 85 } else if (StartsWithASCII(cur, "-arch ", true)) { |
| 86 // The arch was passed as one GN string value, e.g. "-arch i386". Return |
| 87 // the stuff following the space and delete the item. |
| 88 std::string ret = cur.substr(6); |
| 89 cflags->erase(cflags->begin() + i); |
| 90 return ret; |
| 91 } |
| 92 } |
| 93 return std::string(); |
| 94 } |
| 95 |
| 69 // Finds all values from the given getter from all configs in the given list, | 96 // Finds all values from the given getter from all configs in the given list, |
| 70 // and adds them to the given result vector. | 97 // and adds them to the given result vector. |
| 71 template<typename T> | 98 template<typename T> |
| 72 void FillConfigListValues( | 99 void FillConfigListValues( |
| 73 const LabelConfigVector& configs, | 100 const LabelConfigVector& configs, |
| 74 const std::vector<T>& (ConfigValues::* getter)() const, | 101 const std::vector<T>& (ConfigValues::* getter)() const, |
| 75 std::vector<T>* result) { | 102 std::vector<T>* result) { |
| 76 for (size_t config_i = 0; config_i < configs.size(); config_i++) { | 103 for (size_t config_i = 0; config_i < configs.size(); config_i++) { |
| 77 const std::vector<T>& values = | 104 const std::vector<T>& values = |
| 78 (configs[config_i].ptr->config_values().*getter)(); | 105 (configs[config_i].ptr->config_values().*getter)(); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 out_ << " '-l"; | 370 out_ << " '-l"; |
| 344 EscapeStringToStream(out_, flags.libs[i], escape_options); | 371 EscapeStringToStream(out_, flags.libs[i], escape_options); |
| 345 out_ << "',"; | 372 out_ << "',"; |
| 346 } | 373 } |
| 347 out_ << " ],\n"; | 374 out_ << " ],\n"; |
| 348 Indent(indent) << "},\n"; | 375 Indent(indent) << "},\n"; |
| 349 } | 376 } |
| 350 | 377 |
| 351 Indent(indent) << "'xcode_settings': {\n"; | 378 Indent(indent) << "'xcode_settings': {\n"; |
| 352 | 379 |
| 380 // Architecture. GYP uses this to write the -arch flag passed to the |
| 381 // compiler, it doesn't look at our -arch flag. So we need to specify it in |
| 382 // this special var and not in the cflags to avoid duplicates or conflicts. |
| 383 std::string arch = GetMacArch(&flags.cflags); |
| 384 if (arch == "i386") |
| 385 Indent(indent + kExtraIndent) << "'ARCHS': [ 'i386' ],\n"; |
| 386 else if (arch == "x86_64") |
| 387 Indent(indent + kExtraIndent) << "'ARCHS': [ 'x86_64' ],\n"; |
| 388 |
| 353 // C/C++ flags. | 389 // C/C++ flags. |
| 354 if (!flags.cflags.empty() || !flags.cflags_c.empty() || | 390 if (!flags.cflags.empty() || !flags.cflags_c.empty() || |
| 355 !flags.cflags_objc.empty()) { | 391 !flags.cflags_objc.empty()) { |
| 356 Indent(indent + kExtraIndent) << "'OTHER_CFLAGS': ["; | 392 Indent(indent + kExtraIndent) << "'OTHER_CFLAGS': ["; |
| 357 WriteArrayValues(out_, flags.cflags); | 393 WriteArrayValues(out_, flags.cflags); |
| 358 WriteArrayValues(out_, flags.cflags_c); | 394 WriteArrayValues(out_, flags.cflags_c); |
| 359 WriteArrayValues(out_, flags.cflags_objc); | 395 WriteArrayValues(out_, flags.cflags_objc); |
| 360 out_ << " ],\n"; | 396 out_ << " ],\n"; |
| 361 } | 397 } |
| 362 if (!flags.cflags.empty() || !flags.cflags_cc.empty() || | 398 if (!flags.cflags.empty() || !flags.cflags_cc.empty() || |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 return; | 617 return; |
| 582 | 618 |
| 583 EscapeOptions options; | 619 EscapeOptions options; |
| 584 options.mode = ESCAPE_JSON; | 620 options.mode = ESCAPE_JSON; |
| 585 | 621 |
| 586 Indent(indent) << "'" << name << "': ["; | 622 Indent(indent) << "'" << name << "': ["; |
| 587 WriteArrayValues(out_, values); | 623 WriteArrayValues(out_, values); |
| 588 out_ << " ],\n"; | 624 out_ << " ],\n"; |
| 589 } | 625 } |
| 590 | 626 |
| OLD | NEW |