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

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

Issue 2574333002: [Refactor Xcode Objects] Enable generating per file '--help' compiler flag (Closed)
Patch Set: Addressed feedback Created 4 years 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/xcode_object.h" 5 #include "tools/gn/xcode_object.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 #include <sstream> 8 #include <sstream>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 PrintProperty(out, rules, "buildPhases", build_phases_); 358 PrintProperty(out, rules, "buildPhases", build_phases_);
359 PrintProperty(out, rules, "dependencies", EmptyPBXObjectVector()); 359 PrintProperty(out, rules, "dependencies", EmptyPBXObjectVector());
360 PrintProperty(out, rules, "name", name_); 360 PrintProperty(out, rules, "name", name_);
361 PrintProperty(out, rules, "productName", name_); 361 PrintProperty(out, rules, "productName", name_);
362 out << indent_str << "};\n"; 362 out << indent_str << "};\n";
363 } 363 }
364 364
365 // PBXBuildFile --------------------------------------------------------------- 365 // PBXBuildFile ---------------------------------------------------------------
366 366
367 PBXBuildFile::PBXBuildFile(const PBXFileReference* file_reference, 367 PBXBuildFile::PBXBuildFile(const PBXFileReference* file_reference,
368 const PBXSourcesBuildPhase* build_phase) 368 const PBXSourcesBuildPhase* build_phase,
369 : file_reference_(file_reference), build_phase_(build_phase) { 369 const CompilerFlags compiler_flag)
370 : file_reference_(file_reference),
371 build_phase_(build_phase),
372 compiler_flag_(compiler_flag) {
370 DCHECK(file_reference_); 373 DCHECK(file_reference_);
371 DCHECK(build_phase_); 374 DCHECK(build_phase_);
372 } 375 }
373 376
374 PBXBuildFile::~PBXBuildFile() {} 377 PBXBuildFile::~PBXBuildFile() {}
375 378
376 PBXObjectClass PBXBuildFile::Class() const { 379 PBXObjectClass PBXBuildFile::Class() const {
377 return PBXBuildFileClass; 380 return PBXBuildFileClass;
378 } 381 }
379 382
380 std::string PBXBuildFile::Name() const { 383 std::string PBXBuildFile::Name() const {
381 return file_reference_->Name() + " in " + build_phase_->Name(); 384 return file_reference_->Name() + " in " + build_phase_->Name();
382 } 385 }
383 386
384 void PBXBuildFile::Print(std::ostream& out, unsigned indent) const { 387 void PBXBuildFile::Print(std::ostream& out, unsigned indent) const {
385 const std::string indent_str(indent, '\t'); 388 const std::string indent_str(indent, '\t');
386 const IndentRules rules = {true, 0}; 389 const IndentRules rules = {true, 0};
387 out << indent_str << Reference() << " = {"; 390 out << indent_str << Reference() << " = {";
388 PrintProperty(out, rules, "isa", ToString(Class())); 391 PrintProperty(out, rules, "isa", ToString(Class()));
389 PrintProperty(out, rules, "fileRef", file_reference_); 392 PrintProperty(out, rules, "fileRef", file_reference_);
393 if (compiler_flag_ == CompilerFlags::HELP) {
394 std::map<std::string, std::string> settings = {
395 {"COMPILER_FLAGS", "--help"},
396 };
397 PrintProperty(out, rules, "settings", settings);
398 }
390 out << "};\n"; 399 out << "};\n";
391 } 400 }
392 401
393 // PBXFileReference ----------------------------------------------------------- 402 // PBXFileReference -----------------------------------------------------------
394 403
395 PBXFileReference::PBXFileReference(const std::string& name, 404 PBXFileReference::PBXFileReference(const std::string& name,
396 const std::string& path, 405 const std::string& path,
397 const std::string& type) 406 const std::string& type)
398 : name_(name), path_(path), type_(type) {} 407 : name_(name), path_(path), type_(type) {}
399 408
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 DCHECK(product_reference_); 561 DCHECK(product_reference_);
553 build_phases_.push_back(base::WrapUnique(new PBXSourcesBuildPhase)); 562 build_phases_.push_back(base::WrapUnique(new PBXSourcesBuildPhase));
554 source_build_phase_ = 563 source_build_phase_ =
555 static_cast<PBXSourcesBuildPhase*>(build_phases_.back().get()); 564 static_cast<PBXSourcesBuildPhase*>(build_phases_.back().get());
556 565
557 build_phases_.push_back(base::WrapUnique(new PBXFrameworksBuildPhase)); 566 build_phases_.push_back(base::WrapUnique(new PBXFrameworksBuildPhase));
558 } 567 }
559 568
560 PBXNativeTarget::~PBXNativeTarget() {} 569 PBXNativeTarget::~PBXNativeTarget() {}
561 570
562 void PBXNativeTarget::AddFileForIndexing( 571 void PBXNativeTarget::AddFileForIndexing(const PBXFileReference* file_reference,
563 const PBXFileReference* file_reference) { 572 const CompilerFlags compiler_flag) {
564 DCHECK(file_reference); 573 DCHECK(file_reference);
565 source_build_phase_->AddBuildFile( 574 source_build_phase_->AddBuildFile(base::MakeUnique<PBXBuildFile>(
566 base::MakeUnique<PBXBuildFile>(file_reference, source_build_phase_)); 575 file_reference, source_build_phase_, compiler_flag));
567 } 576 }
568 577
569 PBXObjectClass PBXNativeTarget::Class() const { 578 PBXObjectClass PBXNativeTarget::Class() const {
570 return PBXNativeTargetClass; 579 return PBXNativeTargetClass;
571 } 580 }
572 581
573 void PBXNativeTarget::Print(std::ostream& out, unsigned indent) const { 582 void PBXNativeTarget::Print(std::ostream& out, unsigned indent) const {
574 const std::string indent_str(indent, '\t'); 583 const std::string indent_str(indent, '\t');
575 const IndentRules rules = {false, indent + 1}; 584 const IndentRules rules = {false, indent + 1};
576 out << indent_str << Reference() << " = {\n"; 585 out << indent_str << Reference() << " = {\n";
(...skipping 23 matching lines...) Expand all
600 main_group_->AddChild(base::MakeUnique<PBXGroup>(source_path, "Source"))); 609 main_group_->AddChild(base::MakeUnique<PBXGroup>(source_path, "Source")));
601 products_ = static_cast<PBXGroup*>(main_group_->AddChild( 610 products_ = static_cast<PBXGroup*>(main_group_->AddChild(
602 base::MakeUnique<PBXGroup>(std::string(), "Product"))); 611 base::MakeUnique<PBXGroup>(std::string(), "Product")));
603 main_group_->AddChild(base::MakeUnique<PBXGroup>(std::string(), "Build")); 612 main_group_->AddChild(base::MakeUnique<PBXGroup>(std::string(), "Build"));
604 613
605 configurations_.reset(new XCConfigurationList(config_name, attributes, this)); 614 configurations_.reset(new XCConfigurationList(config_name, attributes, this));
606 } 615 }
607 616
608 PBXProject::~PBXProject() {} 617 PBXProject::~PBXProject() {}
609 618
610 void PBXProject::AddSourceFile(const std::string& source_path) { 619 void PBXProject::AddSourceFile(const std::string& source_path,
620 const CompilerFlags compiler_flag) {
611 PBXFileReference* file_reference = sources_->AddSourceFile(source_path); 621 PBXFileReference* file_reference = sources_->AddSourceFile(source_path);
612 base::StringPiece ext = FindExtension(&source_path); 622 base::StringPiece ext = FindExtension(&source_path);
613 if (!IsSourceFileForIndexing(ext)) 623 if (!IsSourceFileForIndexing(ext))
614 return; 624 return;
615 625
616 if (!target_for_indexing_) { 626 if (!target_for_indexing_) {
617 PBXAttributes attributes; 627 PBXAttributes attributes;
618 attributes["EXECUTABLE_PREFIX"] = ""; 628 attributes["EXECUTABLE_PREFIX"] = "";
619 attributes["HEADER_SEARCH_PATHS"] = sources_->path(); 629 attributes["HEADER_SEARCH_PATHS"] = sources_->path();
620 attributes["PRODUCT_NAME"] = name_; 630 attributes["PRODUCT_NAME"] = name_;
621 631
622 PBXFileReference* product_reference = static_cast<PBXFileReference*>( 632 PBXFileReference* product_reference = static_cast<PBXFileReference*>(
623 products_->AddChild(base::MakeUnique<PBXFileReference>( 633 products_->AddChild(base::MakeUnique<PBXFileReference>(
624 std::string(), name_, "compiled.mach-o.executable"))); 634 std::string(), name_, "compiled.mach-o.executable")));
625 635
626 const char product_type[] = "com.apple.product-type.tool"; 636 const char product_type[] = "com.apple.product-type.tool";
627 targets_.push_back(base::MakeUnique<PBXNativeTarget>( 637 targets_.push_back(base::MakeUnique<PBXNativeTarget>(
628 name_, std::string(), config_name_, attributes, product_type, name_, 638 name_, std::string(), config_name_, attributes, product_type, name_,
629 product_reference)); 639 product_reference));
630 target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get()); 640 target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get());
631 } 641 }
632 642
633 DCHECK(target_for_indexing_); 643 DCHECK(target_for_indexing_);
634 target_for_indexing_->AddFileForIndexing(file_reference); 644 target_for_indexing_->AddFileForIndexing(file_reference, compiler_flag);
635 } 645 }
636 646
637 void PBXProject::AddAggregateTarget(const std::string& name, 647 void PBXProject::AddAggregateTarget(const std::string& name,
638 const std::string& shell_script) { 648 const std::string& shell_script) {
639 PBXAttributes attributes; 649 PBXAttributes attributes;
640 attributes["CODE_SIGNING_REQUIRED"] = "NO"; 650 attributes["CODE_SIGNING_REQUIRED"] = "NO";
641 attributes["CONFIGURATION_BUILD_DIR"] = "."; 651 attributes["CONFIGURATION_BUILD_DIR"] = ".";
642 attributes["PRODUCT_NAME"] = name; 652 attributes["PRODUCT_NAME"] = name;
643 653
644 targets_.push_back(base::MakeUnique<PBXAggregateTarget>( 654 targets_.push_back(base::MakeUnique<PBXAggregateTarget>(
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 const std::string indent_str(indent, '\t'); 869 const std::string indent_str(indent, '\t');
860 const IndentRules rules = {false, indent + 1}; 870 const IndentRules rules = {false, indent + 1};
861 out << indent_str << Reference() << " = {\n"; 871 out << indent_str << Reference() << " = {\n";
862 PrintProperty(out, rules, "isa", ToString(Class())); 872 PrintProperty(out, rules, "isa", ToString(Class()));
863 PrintProperty(out, rules, "buildConfigurations", configurations_); 873 PrintProperty(out, rules, "buildConfigurations", configurations_);
864 PrintProperty(out, rules, "defaultConfigurationIsVisible", 1u); 874 PrintProperty(out, rules, "defaultConfigurationIsVisible", 1u);
865 PrintProperty(out, rules, "defaultConfigurationName", 875 PrintProperty(out, rules, "defaultConfigurationName",
866 configurations_[0]->Name()); 876 configurations_[0]->Name());
867 out << indent_str << "};\n"; 877 out << indent_str << "};\n";
868 } 878 }
OLDNEW
« tools/gn/xcode_object.h ('K') | « tools/gn/xcode_object.h ('k') | tools/gn/xcode_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698