Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: tools/gn/gyp_binary_target_writer.cc

Issue 141433015: GN build fixes, mostly for Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: put back sha1 file Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« build/config/compiler/BUILD.gn ('K') | « third_party/re2/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/gyp_binary_target_writer.cc
diff --git a/tools/gn/gyp_binary_target_writer.cc b/tools/gn/gyp_binary_target_writer.cc
index e32c60bff5a5a05deaeeb6de89e00e9f4143c1c9..cb6b4e01b5ba33d3dfd3bd503663b08c81af8daa 100644
--- a/tools/gn/gyp_binary_target_writer.cc
+++ b/tools/gn/gyp_binary_target_writer.cc
@@ -7,6 +7,7 @@
#include <set>
#include "base/logging.h"
+#include "base/strings/string_util.h"
#include "tools/gn/builder_record.h"
#include "tools/gn/config_values_extractors.h"
#include "tools/gn/err.h"
@@ -66,6 +67,32 @@ std::string GetVCOptimization(std::vector<std::string>* cflags) {
return "'2'"; // Default value.
}
+// Returns the value from the already-filled in cflags for the processor
+// architecture to set in the GYP file. Additionally, this removes the flag
+// from the given vector so we don't get duplicates.
+std::string GetMacArch(std::vector<std::string>* cflags) {
+ // Searches for the "-arch" option and returns the corresponding GYP value.
+ for (size_t i = 0; i < cflags->size(); i++) {
+ const std::string& cur = (*cflags)[i];
+ if (cur == "-arch") {
+ // This is the first part of a list with ["-arch", "i386"], return the
+ // following item, and delete both of them.
+ if (i < cflags->size() - 1) {
+ std::string ret = (*cflags)[i + 1];
+ cflags->erase(cflags->begin() + i, cflags->begin() + i + 2);
+ return ret;
+ }
+ } else if (StartsWithASCII(cur, "-arch ", true)) {
+ // The arch was passed as one GN string value, e.g. "-arch i386". Return
+ // the stuff following the space and delete the item.
+ std::string ret = cur.substr(6);
+ cflags->erase(cflags->begin() + i);
+ return ret;
+ }
+ }
+ return std::string();
+}
+
// Finds all values from the given getter from all configs in the given list,
// and adds them to the given result vector.
template<typename T>
@@ -350,6 +377,15 @@ void GypBinaryTargetWriter::WriteMacFlags(Flags& flags, int indent) {
Indent(indent) << "'xcode_settings': {\n";
+ // Architecture. GYP uses this to write the -arch flag passed to the
+ // compiler, it doesn't look at our -arch flag. So we need to specify it in
+ // this special var and not in the cflags to avoid duplicates or conflicts.
+ std::string arch = GetMacArch(&flags.cflags);
+ if (arch == "i386")
+ Indent(indent + kExtraIndent) << "'ARCHS': [ 'i386' ],\n";
+ else if (arch == "x86_64")
+ Indent(indent + kExtraIndent) << "'ARCHS': [ 'x86_64' ],\n";
+
// C/C++ flags.
if (!flags.cflags.empty() || !flags.cflags_c.empty() ||
!flags.cflags_objc.empty()) {
« build/config/compiler/BUILD.gn ('K') | « third_party/re2/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698