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

Side by Side Diff: tools/gn/gyp_binary_target_writer.cc

Issue 149163005: Work on GN iOS build. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/gyp_binary_target_writer.h ('k') | tools/gn/gyp_target_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/strings/string_util.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 } // namespace 111 } // namespace
112 112
113 GypBinaryTargetWriter::Flags::Flags() {} 113 GypBinaryTargetWriter::Flags::Flags() {}
114 GypBinaryTargetWriter::Flags::~Flags() {} 114 GypBinaryTargetWriter::Flags::~Flags() {}
115 115
116 GypBinaryTargetWriter::GypBinaryTargetWriter(const TargetGroup& group, 116 GypBinaryTargetWriter::GypBinaryTargetWriter(const TargetGroup& group,
117 const Toolchain* debug_toolchain, 117 const Toolchain* debug_toolchain,
118 const SourceDir& gyp_dir, 118 const SourceDir& gyp_dir,
119 std::ostream& out) 119 std::ostream& out)
120 : GypTargetWriter(group.debug->item()->AsTarget(), debug_toolchain, 120 : GypTargetWriter(group.get()->item()->AsTarget(), debug_toolchain,
121 gyp_dir, out), 121 gyp_dir, out),
122 group_(group) { 122 group_(group) {
123 } 123 }
124 124
125 GypBinaryTargetWriter::~GypBinaryTargetWriter() { 125 GypBinaryTargetWriter::~GypBinaryTargetWriter() {
126 } 126 }
127 127
128 void GypBinaryTargetWriter::Run() { 128 void GypBinaryTargetWriter::Run() {
129 int indent = 4; 129 int indent = 4;
130 130
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 break; 176 break;
177 case Target::SOURCE_SET: 177 case Target::SOURCE_SET:
178 out_ << "'static_library',\n"; // TODO(brettw) fixme. 178 out_ << "'static_library',\n"; // TODO(brettw) fixme.
179 break; 179 break;
180 default: 180 default:
181 NOTREACHED(); 181 NOTREACHED();
182 } 182 }
183 183
184 if (target_->hard_dep()) 184 if (target_->hard_dep())
185 Indent(indent) << "'hard_dependency': 1,\n"; 185 Indent(indent) << "'hard_dependency': 1,\n";
186
187 // Write out the toolsets depending on whether there is a host build. If no
188 // toolset is specified, GYP assumes a target build.
189 if (group_.debug && group_.host_debug)
190 Indent(indent) << "'toolsets': ['target', 'host'],\n";
191 else if (group_.host_debug)
192 Indent(indent) << "'toolsets': ['host'],\n";
186 } 193 }
187 194
188 void GypBinaryTargetWriter::WriteVCConfiguration(int indent) { 195 void GypBinaryTargetWriter::WriteVCConfiguration(int indent) {
189 Indent(indent) << "'configurations': {\n"; 196 Indent(indent) << "'configurations': {\n";
190 197
191 Indent(indent + kExtraIndent) << "'Debug': {\n"; 198 Indent(indent + kExtraIndent) << "'Debug': {\n";
192 Indent(indent + kExtraIndent * 2) << 199 Indent(indent + kExtraIndent * 2) <<
193 "'msvs_configuration_platform': 'Win32',\n"; 200 "'msvs_configuration_platform': 'Win32',\n";
194 Flags debug_flags(FlagsFromTarget(group_.debug->item()->AsTarget())); 201 Flags debug_flags(FlagsFromTarget(group_.debug->item()->AsTarget()));
195 WriteVCFlags(debug_flags, indent + kExtraIndent * 2); 202 WriteVCFlags(debug_flags, indent + kExtraIndent * 2);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 WriteSources(target_, indent + kExtraIndent * 2); 278 WriteSources(target_, indent + kExtraIndent * 2);
272 279
273 Indent(indent + kExtraIndent) << "},],\n"; 280 Indent(indent + kExtraIndent) << "},],\n";
274 Indent(indent) << "],\n"; 281 Indent(indent) << "],\n";
275 282
276 // Deps in GYP can not vary based on the toolset. 283 // Deps in GYP can not vary based on the toolset.
277 WriteDeps(target_, indent); 284 WriteDeps(target_, indent);
278 } 285 }
279 286
280 void GypBinaryTargetWriter::WriteMacConfiguration(int indent) { 287 void GypBinaryTargetWriter::WriteMacConfiguration(int indent) {
288 // The Mac flags are parameterized by the GYP generator (Ninja vs. XCode).
289 const char kNinjaGeneratorCondition[] =
290 "'conditions': [['\"<(GENERATOR)\"==\"ninja\"', {\n";
291 const char kNinjaGeneratorElse[] = "}, {\n";
292 const char kNinjaGeneratorEnd[] = "}]],\n";
293
281 Indent(indent) << "'configurations': {\n"; 294 Indent(indent) << "'configurations': {\n";
282 295
296 // Debug.
283 Indent(indent + kExtraIndent) << "'Debug': {\n"; 297 Indent(indent + kExtraIndent) << "'Debug': {\n";
284 Flags debug_flags(FlagsFromTarget(group_.debug->item()->AsTarget())); 298 Indent(indent + kExtraIndent * 2) << kNinjaGeneratorCondition;
285 WriteMacFlags(debug_flags, indent + kExtraIndent * 2); 299 {
300 // Ninja generator.
301 WriteMacTargetAndHostFlags(group_.debug, group_.host_debug,
302 indent + kExtraIndent * 3);
303 }
304 Indent(indent + kExtraIndent * 2) << kNinjaGeneratorElse;
305 if (group_.xcode_debug) {
306 // XCode generator.
307 WriteMacTargetAndHostFlags(group_.xcode_debug, group_.xcode_host_debug,
308 indent + kExtraIndent * 3);
309 }
310 Indent(indent + kExtraIndent * 2) << kNinjaGeneratorEnd;
286 Indent(indent + kExtraIndent) << "},\n"; 311 Indent(indent + kExtraIndent) << "},\n";
287 312
313 // Release.
288 Indent(indent + kExtraIndent) << "'Release': {\n"; 314 Indent(indent + kExtraIndent) << "'Release': {\n";
289 Flags release_flags(FlagsFromTarget(group_.release->item()->AsTarget())); 315 Indent(indent + kExtraIndent * 2) << kNinjaGeneratorCondition;
290 WriteMacFlags(release_flags, indent + kExtraIndent * 2); 316 {
317 // Ninja generator.
318 WriteMacTargetAndHostFlags(group_.release, group_.host_release,
319 indent + kExtraIndent * 3);
320 }
321 Indent(indent + kExtraIndent * 2) << kNinjaGeneratorElse;
322 if (group_.xcode_release) {
323 // XCode generator.
324 WriteMacTargetAndHostFlags(group_.xcode_release, group_.xcode_host_release,
325 indent + kExtraIndent * 3);
326 }
327 Indent(indent + kExtraIndent * 2) << kNinjaGeneratorEnd;
291 Indent(indent + kExtraIndent) << "},\n"; 328 Indent(indent + kExtraIndent) << "},\n";
292 329
293 Indent(indent) << "},\n"; 330 Indent(indent) << "},\n";
294 331
295 WriteSources(target_, indent); 332 WriteSources(target_, indent);
296 WriteDeps(target_, indent); 333 WriteDeps(target_, indent);
297 } 334 }
298 335
299 void GypBinaryTargetWriter::WriteVCFlags(Flags& flags, int indent) { 336 void GypBinaryTargetWriter::WriteVCFlags(Flags& flags, int indent) {
300 // Defines and includes go outside of the msvs settings. 337 // Defines and includes go outside of the msvs settings.
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 target_->settings()->base_config()->GetValue("is_clang"); 458 target_->settings()->base_config()->GetValue("is_clang");
422 if (is_clang && is_clang->type() == Value::BOOLEAN && 459 if (is_clang && is_clang->type() == Value::BOOLEAN &&
423 is_clang->boolean_value()) { 460 is_clang->boolean_value()) {
424 base::FilePath clang_path = 461 base::FilePath clang_path =
425 target_->settings()->build_settings()->GetFullPath(SourceFile( 462 target_->settings()->build_settings()->GetFullPath(SourceFile(
426 "//third_party/llvm-build/Release+Asserts/bin/clang")); 463 "//third_party/llvm-build/Release+Asserts/bin/clang"));
427 base::FilePath clang_pp_path = 464 base::FilePath clang_pp_path =
428 target_->settings()->build_settings()->GetFullPath(SourceFile( 465 target_->settings()->build_settings()->GetFullPath(SourceFile(
429 "//third_party/llvm-build/Release+Asserts/bin/clang++")); 466 "//third_party/llvm-build/Release+Asserts/bin/clang++"));
430 467
431 Indent(indent) << "'CC': '" << FilePathToUTF8(clang_path) << "',\n"; 468 Indent(indent + kExtraIndent)
432 Indent(indent) << "'LDPLUSPLUS': '" 469 << "'CC': '" << FilePathToUTF8(clang_path) << "',\n";
433 << FilePathToUTF8(clang_pp_path) << "',\n"; 470 Indent(indent + kExtraIndent)
471 << "'LDPLUSPLUS': '" << FilePathToUTF8(clang_pp_path) << "',\n";
434 } 472 }
435 473
436 Indent(indent) << "},\n"; 474 Indent(indent) << "},\n";
437 } 475 }
438 476
439 void GypBinaryTargetWriter::WriteLinuxFlagsForTarget(const Target* target, 477 void GypBinaryTargetWriter::WriteLinuxFlagsForTarget(const Target* target,
440 int indent) { 478 int indent) {
441 Flags flags(FlagsFromTarget(target)); 479 Flags flags(FlagsFromTarget(target));
442 WriteLinuxFlags(flags, indent); 480 WriteLinuxFlags(flags, indent);
443 } 481 }
(...skipping 22 matching lines...) Expand all
466 } 504 }
467 505
468 for (size_t i = 0; i < flags.libs.size(); i++) { 506 for (size_t i = 0; i < flags.libs.size(); i++) {
469 out_ << " '-l"; 507 out_ << " '-l";
470 EscapeStringToStream(out_, flags.libs[i], escape_options); 508 EscapeStringToStream(out_, flags.libs[i], escape_options);
471 out_ << "',"; 509 out_ << "',";
472 } 510 }
473 out_ << " ],\n"; 511 out_ << " ],\n";
474 } 512 }
475 513
514 void GypBinaryTargetWriter::WriteMacTargetAndHostFlags(
515 const BuilderRecord* target,
516 const BuilderRecord* host,
517 int indent) {
518 // The Mac flags are sometimes (when cross-compiling) also parameterized on
519 // the toolset.
520 const char kToolsetTargetCondition[] =
521 "'target_conditions': [['_toolset==\"target\"', {\n";
522 const char kToolsetTargetElse[] = "}, {\n";
523 const char kToolsetTargetEnd[] = "}]],\n";
524
525 int extra_indent = 0;
526 if (host) {
527 // Write out the first part of the conditional.
528 Indent(indent) << kToolsetTargetCondition;
529 extra_indent = kExtraIndent;
530 }
531
532 // Always write the target flags (may or may not be inside a target
533 // conditional).
534 {
535 Flags flags(FlagsFromTarget(target->item()->AsTarget()));
536 WriteMacFlags(flags, indent + extra_indent);
537 }
538
539 // Now optionally write the host conditional arm.
540 if (host) {
541 Indent(indent) << kToolsetTargetElse;
542 Flags flags(FlagsFromTarget(host->item()->AsTarget()));
543 WriteMacFlags(flags, indent + kExtraIndent);
544 Indent(indent) << kToolsetTargetEnd;
545 }
546 }
547
476 void GypBinaryTargetWriter::WriteSources(const Target* target, int indent) { 548 void GypBinaryTargetWriter::WriteSources(const Target* target, int indent) {
477 Indent(indent) << "'sources': [\n"; 549 Indent(indent) << "'sources': [\n";
478 550
479 const Target::FileList& sources = target->sources(); 551 const Target::FileList& sources = target->sources();
480 for (size_t i = 0; i < sources.size(); i++) { 552 for (size_t i = 0; i < sources.size(); i++) {
481 const SourceFile& input_file = sources[i]; 553 const SourceFile& input_file = sources[i];
482 Indent(indent + kExtraIndent) << "'" << helper_.GetFileReference(input_file) 554 Indent(indent + kExtraIndent) << "'" << helper_.GetFileReference(input_file)
483 << "',\n"; 555 << "',\n";
484 } 556 }
485 557
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 return; 689 return;
618 690
619 EscapeOptions options; 691 EscapeOptions options;
620 options.mode = ESCAPE_JSON; 692 options.mode = ESCAPE_JSON;
621 693
622 Indent(indent) << "'" << name << "': ["; 694 Indent(indent) << "'" << name << "': [";
623 WriteArrayValues(out_, values); 695 WriteArrayValues(out_, values);
624 out_ << " ],\n"; 696 out_ << " ],\n";
625 } 697 }
626 698
OLDNEW
« no previous file with comments | « tools/gn/gyp_binary_target_writer.h ('k') | tools/gn/gyp_target_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698