OLD | NEW |
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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // PBXTarget ------------------------------------------------------------------ | 310 // PBXTarget ------------------------------------------------------------------ |
311 | 311 |
312 PBXTarget::PBXTarget(const std::string& name, | 312 PBXTarget::PBXTarget(const std::string& name, |
313 const std::string& shell_script, | 313 const std::string& shell_script, |
314 const std::string& config_name, | 314 const std::string& config_name, |
315 const PBXAttributes& attributes) | 315 const PBXAttributes& attributes) |
316 : configurations_(new XCConfigurationList(config_name, attributes, this)), | 316 : configurations_(new XCConfigurationList(config_name, attributes, this)), |
317 name_(name) { | 317 name_(name) { |
318 if (!shell_script.empty()) { | 318 if (!shell_script.empty()) { |
319 build_phases_.push_back( | 319 build_phases_.push_back( |
320 base::WrapUnique(new PBXShellScriptBuildPhase(name, shell_script))); | 320 base::MakeUnique<PBXShellScriptBuildPhase>(name, shell_script)); |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 PBXTarget::~PBXTarget() {} | 324 PBXTarget::~PBXTarget() {} |
325 | 325 |
326 std::string PBXTarget::Name() const { | 326 std::string PBXTarget::Name() const { |
327 return name_; | 327 return name_; |
328 } | 328 } |
329 | 329 |
330 void PBXTarget::Visit(PBXObjectVisitor& visitor) { | 330 void PBXTarget::Visit(PBXObjectVisitor& visitor) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 PBXObject* PBXGroup::AddChild(std::unique_ptr<PBXObject> child) { | 468 PBXObject* PBXGroup::AddChild(std::unique_ptr<PBXObject> child) { |
469 DCHECK(child); | 469 DCHECK(child); |
470 children_.push_back(std::move(child)); | 470 children_.push_back(std::move(child)); |
471 return children_.back().get(); | 471 return children_.back().get(); |
472 } | 472 } |
473 | 473 |
474 PBXFileReference* PBXGroup::AddSourceFile(const std::string& source_path) { | 474 PBXFileReference* PBXGroup::AddSourceFile(const std::string& source_path) { |
475 DCHECK(!source_path.empty()); | 475 DCHECK(!source_path.empty()); |
476 std::string::size_type sep = source_path.find("/"); | 476 std::string::size_type sep = source_path.find("/"); |
477 if (sep == std::string::npos) { | 477 if (sep == std::string::npos) { |
478 children_.push_back(base::WrapUnique( | 478 children_.push_back(base::MakeUnique<PBXFileReference>( |
479 new PBXFileReference(std::string(), source_path, std::string()))); | 479 std::string(), source_path, std::string())); |
480 return static_cast<PBXFileReference*>(children_.back().get()); | 480 return static_cast<PBXFileReference*>(children_.back().get()); |
481 } | 481 } |
482 | 482 |
483 PBXGroup* group = nullptr; | 483 PBXGroup* group = nullptr; |
484 base::StringPiece component(source_path.data(), sep); | 484 base::StringPiece component(source_path.data(), sep); |
485 for (const auto& child : children_) { | 485 for (const auto& child : children_) { |
486 if (child->Class() != PBXGroupClass) | 486 if (child->Class() != PBXGroupClass) |
487 continue; | 487 continue; |
488 | 488 |
489 PBXGroup* child_as_group = static_cast<PBXGroup*>(child.get()); | 489 PBXGroup* child_as_group = static_cast<PBXGroup*>(child.get()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 556 |
557 build_phases_.push_back(base::WrapUnique(new PBXFrameworksBuildPhase)); | 557 build_phases_.push_back(base::WrapUnique(new PBXFrameworksBuildPhase)); |
558 } | 558 } |
559 | 559 |
560 PBXNativeTarget::~PBXNativeTarget() {} | 560 PBXNativeTarget::~PBXNativeTarget() {} |
561 | 561 |
562 void PBXNativeTarget::AddFileForIndexing( | 562 void PBXNativeTarget::AddFileForIndexing( |
563 const PBXFileReference* file_reference) { | 563 const PBXFileReference* file_reference) { |
564 DCHECK(file_reference); | 564 DCHECK(file_reference); |
565 source_build_phase_->AddBuildFile( | 565 source_build_phase_->AddBuildFile( |
566 base::WrapUnique(new PBXBuildFile(file_reference, source_build_phase_))); | 566 base::MakeUnique<PBXBuildFile>(file_reference, source_build_phase_)); |
567 } | 567 } |
568 | 568 |
569 PBXObjectClass PBXNativeTarget::Class() const { | 569 PBXObjectClass PBXNativeTarget::Class() const { |
570 return PBXNativeTargetClass; | 570 return PBXNativeTargetClass; |
571 } | 571 } |
572 | 572 |
573 void PBXNativeTarget::Print(std::ostream& out, unsigned indent) const { | 573 void PBXNativeTarget::Print(std::ostream& out, unsigned indent) const { |
574 const std::string indent_str(indent, '\t'); | 574 const std::string indent_str(indent, '\t'); |
575 const IndentRules rules = {false, indent + 1}; | 575 const IndentRules rules = {false, indent + 1}; |
576 out << indent_str << Reference() << " = {\n"; | 576 out << indent_str << Reference() << " = {\n"; |
(...skipping 12 matching lines...) Expand all Loading... |
589 // PBXProject ----------------------------------------------------------------- | 589 // PBXProject ----------------------------------------------------------------- |
590 | 590 |
591 PBXProject::PBXProject(const std::string& name, | 591 PBXProject::PBXProject(const std::string& name, |
592 const std::string& config_name, | 592 const std::string& config_name, |
593 const std::string& source_path, | 593 const std::string& source_path, |
594 const PBXAttributes& attributes) | 594 const PBXAttributes& attributes) |
595 : name_(name), config_name_(config_name), target_for_indexing_(nullptr) { | 595 : name_(name), config_name_(config_name), target_for_indexing_(nullptr) { |
596 attributes_["BuildIndependentTargetsInParallel"] = "YES"; | 596 attributes_["BuildIndependentTargetsInParallel"] = "YES"; |
597 | 597 |
598 main_group_.reset(new PBXGroup); | 598 main_group_.reset(new PBXGroup); |
599 sources_ = static_cast<PBXGroup*>(main_group_->AddChild( | 599 sources_ = static_cast<PBXGroup*>( |
600 base::WrapUnique(new PBXGroup(source_path, "Source")))); | 600 main_group_->AddChild(base::MakeUnique<PBXGroup>(source_path, "Source"))); |
601 products_ = static_cast<PBXGroup*>(main_group_->AddChild( | 601 products_ = static_cast<PBXGroup*>(main_group_->AddChild( |
602 base::WrapUnique(new PBXGroup(std::string(), "Product")))); | 602 base::MakeUnique<PBXGroup>(std::string(), "Product"))); |
603 main_group_->AddChild(base::WrapUnique(new PBXGroup(std::string(), "Build"))); | 603 main_group_->AddChild(base::MakeUnique<PBXGroup>(std::string(), "Build")); |
604 | 604 |
605 configurations_.reset(new XCConfigurationList(config_name, attributes, this)); | 605 configurations_.reset(new XCConfigurationList(config_name, attributes, this)); |
606 } | 606 } |
607 | 607 |
608 PBXProject::~PBXProject() {} | 608 PBXProject::~PBXProject() {} |
609 | 609 |
610 void PBXProject::AddSourceFile(const std::string& source_path) { | 610 void PBXProject::AddSourceFile(const std::string& source_path) { |
611 PBXFileReference* file_reference = sources_->AddSourceFile(source_path); | 611 PBXFileReference* file_reference = sources_->AddSourceFile(source_path); |
612 base::StringPiece ext = FindExtension(&source_path); | 612 base::StringPiece ext = FindExtension(&source_path); |
613 if (!IsSourceFileForIndexing(ext)) | 613 if (!IsSourceFileForIndexing(ext)) |
614 return; | 614 return; |
615 | 615 |
616 if (!target_for_indexing_) { | 616 if (!target_for_indexing_) { |
617 PBXAttributes attributes; | 617 PBXAttributes attributes; |
618 attributes["EXECUTABLE_PREFIX"] = ""; | 618 attributes["EXECUTABLE_PREFIX"] = ""; |
619 attributes["HEADER_SEARCH_PATHS"] = sources_->path(); | 619 attributes["HEADER_SEARCH_PATHS"] = sources_->path(); |
620 attributes["PRODUCT_NAME"] = name_; | 620 attributes["PRODUCT_NAME"] = name_; |
621 | 621 |
622 PBXFileReference* product_reference = static_cast<PBXFileReference*>( | 622 PBXFileReference* product_reference = static_cast<PBXFileReference*>( |
623 products_->AddChild(base::WrapUnique(new PBXFileReference( | 623 products_->AddChild(base::MakeUnique<PBXFileReference>( |
624 std::string(), name_, "compiled.mach-o.executable")))); | 624 std::string(), name_, "compiled.mach-o.executable"))); |
625 | 625 |
626 const char product_type[] = "com.apple.product-type.tool"; | 626 const char product_type[] = "com.apple.product-type.tool"; |
627 targets_.push_back(base::WrapUnique( | 627 targets_.push_back(base::MakeUnique<PBXNativeTarget>( |
628 new PBXNativeTarget(name_, std::string(), config_name_, attributes, | 628 name_, std::string(), config_name_, attributes, product_type, name_, |
629 product_type, name_, product_reference))); | 629 product_reference)); |
630 target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get()); | 630 target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get()); |
631 } | 631 } |
632 | 632 |
633 DCHECK(target_for_indexing_); | 633 DCHECK(target_for_indexing_); |
634 target_for_indexing_->AddFileForIndexing(file_reference); | 634 target_for_indexing_->AddFileForIndexing(file_reference); |
635 } | 635 } |
636 | 636 |
637 void PBXProject::AddAggregateTarget(const std::string& name, | 637 void PBXProject::AddAggregateTarget(const std::string& name, |
638 const std::string& shell_script) { | 638 const std::string& shell_script) { |
639 PBXAttributes attributes; | 639 PBXAttributes attributes; |
640 attributes["CODE_SIGNING_REQUIRED"] = "NO"; | 640 attributes["CODE_SIGNING_REQUIRED"] = "NO"; |
641 attributes["CONFIGURATION_BUILD_DIR"] = "."; | 641 attributes["CONFIGURATION_BUILD_DIR"] = "."; |
642 attributes["PRODUCT_NAME"] = name; | 642 attributes["PRODUCT_NAME"] = name; |
643 | 643 |
644 targets_.push_back(base::WrapUnique( | 644 targets_.push_back(base::MakeUnique<PBXAggregateTarget>( |
645 new PBXAggregateTarget(name, shell_script, config_name_, attributes))); | 645 name, shell_script, config_name_, attributes)); |
646 } | 646 } |
647 | 647 |
648 void PBXProject::AddNativeTarget(const std::string& name, | 648 void PBXProject::AddNativeTarget(const std::string& name, |
649 const std::string& type, | 649 const std::string& type, |
650 const std::string& output_name, | 650 const std::string& output_name, |
651 const std::string& output_type, | 651 const std::string& output_type, |
652 const std::string& shell_script) { | 652 const std::string& shell_script) { |
653 base::StringPiece ext = FindExtension(&output_name); | 653 base::StringPiece ext = FindExtension(&output_name); |
654 PBXFileReference* product = | 654 PBXFileReference* product = static_cast<PBXFileReference*>( |
655 static_cast<PBXFileReference*>(products_->AddChild(base::WrapUnique( | 655 products_->AddChild(base::MakeUnique<PBXFileReference>( |
656 new PBXFileReference(std::string(), output_name, | 656 std::string(), output_name, |
657 type.empty() ? GetSourceType(ext) : type)))); | 657 type.empty() ? GetSourceType(ext) : type))); |
658 | 658 |
659 size_t ext_offset = FindExtensionOffset(output_name); | 659 size_t ext_offset = FindExtensionOffset(output_name); |
660 std::string product_name = ext_offset != std::string::npos | 660 std::string product_name = ext_offset != std::string::npos |
661 ? output_name.substr(0, ext_offset - 1) | 661 ? output_name.substr(0, ext_offset - 1) |
662 : output_name; | 662 : output_name; |
663 | 663 |
664 PBXAttributes attributes; | 664 PBXAttributes attributes; |
665 attributes["CODE_SIGNING_REQUIRED"] = "NO"; | 665 attributes["CODE_SIGNING_REQUIRED"] = "NO"; |
666 attributes["CONFIGURATION_BUILD_DIR"] = "."; | 666 attributes["CONFIGURATION_BUILD_DIR"] = "."; |
667 attributes["PRODUCT_NAME"] = product_name; | 667 attributes["PRODUCT_NAME"] = product_name; |
668 | 668 |
669 targets_.push_back(base::WrapUnique( | 669 targets_.push_back(base::MakeUnique<PBXNativeTarget>( |
670 new PBXNativeTarget(name, shell_script, config_name_, attributes, | 670 name, shell_script, config_name_, attributes, output_type, product_name, |
671 output_type, product_name, product))); | 671 product)); |
672 } | 672 } |
673 | 673 |
674 void PBXProject::SetProjectDirPath(const std::string& project_dir_path) { | 674 void PBXProject::SetProjectDirPath(const std::string& project_dir_path) { |
675 DCHECK(!project_dir_path.empty()); | 675 DCHECK(!project_dir_path.empty()); |
676 project_dir_path_.assign(project_dir_path); | 676 project_dir_path_.assign(project_dir_path); |
677 } | 677 } |
678 | 678 |
679 void PBXProject::SetProjectRoot(const std::string& project_root) { | 679 void PBXProject::SetProjectRoot(const std::string& project_root) { |
680 DCHECK(!project_root.empty()); | 680 DCHECK(!project_root.empty()); |
681 project_root_.assign(project_root); | 681 project_root_.assign(project_root); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 } | 824 } |
825 | 825 |
826 // XCConfigurationList -------------------------------------------------------- | 826 // XCConfigurationList -------------------------------------------------------- |
827 | 827 |
828 XCConfigurationList::XCConfigurationList(const std::string& name, | 828 XCConfigurationList::XCConfigurationList(const std::string& name, |
829 const PBXAttributes& attributes, | 829 const PBXAttributes& attributes, |
830 const PBXObject* owner_reference) | 830 const PBXObject* owner_reference) |
831 : owner_reference_(owner_reference) { | 831 : owner_reference_(owner_reference) { |
832 DCHECK(owner_reference_); | 832 DCHECK(owner_reference_); |
833 configurations_.push_back( | 833 configurations_.push_back( |
834 base::WrapUnique(new XCBuildConfiguration(name, attributes))); | 834 base::MakeUnique<XCBuildConfiguration>(name, attributes)); |
835 } | 835 } |
836 | 836 |
837 XCConfigurationList::~XCConfigurationList() {} | 837 XCConfigurationList::~XCConfigurationList() {} |
838 | 838 |
839 PBXObjectClass XCConfigurationList::Class() const { | 839 PBXObjectClass XCConfigurationList::Class() const { |
840 return XCConfigurationListClass; | 840 return XCConfigurationListClass; |
841 } | 841 } |
842 | 842 |
843 std::string XCConfigurationList::Name() const { | 843 std::string XCConfigurationList::Name() const { |
844 std::stringstream buffer; | 844 std::stringstream buffer; |
(...skipping 14 matching lines...) Expand all Loading... |
859 const std::string indent_str(indent, '\t'); | 859 const std::string indent_str(indent, '\t'); |
860 const IndentRules rules = {false, indent + 1}; | 860 const IndentRules rules = {false, indent + 1}; |
861 out << indent_str << Reference() << " = {\n"; | 861 out << indent_str << Reference() << " = {\n"; |
862 PrintProperty(out, rules, "isa", ToString(Class())); | 862 PrintProperty(out, rules, "isa", ToString(Class())); |
863 PrintProperty(out, rules, "buildConfigurations", configurations_); | 863 PrintProperty(out, rules, "buildConfigurations", configurations_); |
864 PrintProperty(out, rules, "defaultConfigurationIsVisible", 1u); | 864 PrintProperty(out, rules, "defaultConfigurationIsVisible", 1u); |
865 PrintProperty(out, rules, "defaultConfigurationName", | 865 PrintProperty(out, rules, "defaultConfigurationName", |
866 configurations_[0]->Name()); | 866 configurations_[0]->Name()); |
867 out << indent_str << "};\n"; | 867 out << indent_str << "};\n"; |
868 } | 868 } |
OLD | NEW |