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 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 main_group_->AddChild(base::MakeUnique<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::MakeUnique<PBXGroup>(std::string(), "Product"))); | 602 base::MakeUnique<PBXGroup>(std::string(), "Product"))); |
603 main_group_->AddChild(base::MakeUnique<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::AddSourceFileToIndexingTarget(const std::string& source_path) { |
| 611 if (!target_for_indexing_) { |
| 612 AddIndexingTarget(); |
| 613 } |
| 614 AddSourceFile(source_path, target_for_indexing_); |
| 615 } |
| 616 |
| 617 void PBXProject::AddSourceFile(const std::string& source_path, |
| 618 PBXNativeTarget* target) { |
611 PBXFileReference* file_reference = sources_->AddSourceFile(source_path); | 619 PBXFileReference* file_reference = sources_->AddSourceFile(source_path); |
612 base::StringPiece ext = FindExtension(&source_path); | 620 base::StringPiece ext = FindExtension(&source_path); |
613 if (!IsSourceFileForIndexing(ext)) | 621 if (!IsSourceFileForIndexing(ext)) |
614 return; | 622 return; |
615 | 623 |
616 if (!target_for_indexing_) { | 624 DCHECK(target); |
617 PBXAttributes attributes; | 625 target->AddFileForIndexing(file_reference); |
618 attributes["EXECUTABLE_PREFIX"] = ""; | |
619 attributes["HEADER_SEARCH_PATHS"] = sources_->path(); | |
620 attributes["PRODUCT_NAME"] = name_; | |
621 | |
622 PBXFileReference* product_reference = static_cast<PBXFileReference*>( | |
623 products_->AddChild(base::MakeUnique<PBXFileReference>( | |
624 std::string(), name_, "compiled.mach-o.executable"))); | |
625 | |
626 const char product_type[] = "com.apple.product-type.tool"; | |
627 targets_.push_back(base::MakeUnique<PBXNativeTarget>( | |
628 name_, std::string(), config_name_, attributes, product_type, name_, | |
629 product_reference)); | |
630 target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get()); | |
631 } | |
632 | |
633 DCHECK(target_for_indexing_); | |
634 target_for_indexing_->AddFileForIndexing(file_reference); | |
635 } | 626 } |
636 | 627 |
637 void PBXProject::AddAggregateTarget(const std::string& name, | 628 void PBXProject::AddAggregateTarget(const std::string& name, |
638 const std::string& shell_script) { | 629 const std::string& shell_script) { |
639 PBXAttributes attributes; | 630 PBXAttributes attributes; |
640 attributes["CODE_SIGNING_REQUIRED"] = "NO"; | 631 attributes["CODE_SIGNING_REQUIRED"] = "NO"; |
641 attributes["CONFIGURATION_BUILD_DIR"] = "."; | 632 attributes["CONFIGURATION_BUILD_DIR"] = "."; |
642 attributes["PRODUCT_NAME"] = name; | 633 attributes["PRODUCT_NAME"] = name; |
643 | 634 |
644 targets_.push_back(base::MakeUnique<PBXAggregateTarget>( | 635 targets_.push_back(base::MakeUnique<PBXAggregateTarget>( |
645 name, shell_script, config_name_, attributes)); | 636 name, shell_script, config_name_, attributes)); |
646 } | 637 } |
647 | 638 |
648 void PBXProject::AddNativeTarget(const std::string& name, | 639 void PBXProject::AddIndexingTarget() { |
649 const std::string& type, | 640 DCHECK(!target_for_indexing_); |
650 const std::string& output_name, | 641 PBXAttributes attributes; |
651 const std::string& output_type, | 642 attributes["EXECUTABLE_PREFIX"] = ""; |
652 const std::string& shell_script) { | 643 attributes["HEADER_SEARCH_PATHS"] = sources_->path(); |
| 644 attributes["PRODUCT_NAME"] = name_; |
| 645 |
| 646 PBXFileReference* product_reference = static_cast<PBXFileReference*>( |
| 647 products_->AddChild(base::MakeUnique<PBXFileReference>( |
| 648 std::string(), name_, "compiled.mach-o.executable"))); |
| 649 |
| 650 const char product_type[] = "com.apple.product-type.tool"; |
| 651 targets_.push_back(base::MakeUnique<PBXNativeTarget>( |
| 652 name_, std::string(), config_name_, attributes, product_type, name_, |
| 653 product_reference)); |
| 654 target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get()); |
| 655 } |
| 656 |
| 657 PBXNativeTarget* PBXProject::AddNativeTarget(const std::string& name, |
| 658 const std::string& type, |
| 659 const std::string& output_name, |
| 660 const std::string& output_type, |
| 661 const std::string& shell_script) { |
653 base::StringPiece ext = FindExtension(&output_name); | 662 base::StringPiece ext = FindExtension(&output_name); |
654 PBXFileReference* product = static_cast<PBXFileReference*>( | 663 PBXFileReference* product = static_cast<PBXFileReference*>( |
655 products_->AddChild(base::MakeUnique<PBXFileReference>( | 664 products_->AddChild(base::MakeUnique<PBXFileReference>( |
656 std::string(), output_name, | 665 std::string(), output_name, |
657 type.empty() ? GetSourceType(ext) : type))); | 666 type.empty() ? GetSourceType(ext) : type))); |
658 | 667 |
659 size_t ext_offset = FindExtensionOffset(output_name); | 668 size_t ext_offset = FindExtensionOffset(output_name); |
660 std::string product_name = ext_offset != std::string::npos | 669 std::string product_name = ext_offset != std::string::npos |
661 ? output_name.substr(0, ext_offset - 1) | 670 ? output_name.substr(0, ext_offset - 1) |
662 : output_name; | 671 : output_name; |
663 | 672 |
664 PBXAttributes attributes; | 673 PBXAttributes attributes; |
665 attributes["CODE_SIGNING_REQUIRED"] = "NO"; | 674 attributes["CODE_SIGNING_REQUIRED"] = "NO"; |
666 attributes["CONFIGURATION_BUILD_DIR"] = "."; | 675 attributes["CONFIGURATION_BUILD_DIR"] = "."; |
667 attributes["PRODUCT_NAME"] = product_name; | 676 attributes["PRODUCT_NAME"] = product_name; |
668 | 677 |
669 targets_.push_back(base::MakeUnique<PBXNativeTarget>( | 678 targets_.push_back(base::MakeUnique<PBXNativeTarget>( |
670 name, shell_script, config_name_, attributes, output_type, product_name, | 679 name, shell_script, config_name_, attributes, output_type, product_name, |
671 product)); | 680 product)); |
| 681 return static_cast<PBXNativeTarget*>(targets_.back().get()); |
672 } | 682 } |
673 | 683 |
674 void PBXProject::SetProjectDirPath(const std::string& project_dir_path) { | 684 void PBXProject::SetProjectDirPath(const std::string& project_dir_path) { |
675 DCHECK(!project_dir_path.empty()); | 685 DCHECK(!project_dir_path.empty()); |
676 project_dir_path_.assign(project_dir_path); | 686 project_dir_path_.assign(project_dir_path); |
677 } | 687 } |
678 | 688 |
679 void PBXProject::SetProjectRoot(const std::string& project_root) { | 689 void PBXProject::SetProjectRoot(const std::string& project_root) { |
680 DCHECK(!project_root.empty()); | 690 DCHECK(!project_root.empty()); |
681 project_root_.assign(project_root); | 691 project_root_.assign(project_root); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } |
OLD | NEW |