| 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 children_.push_back(std::move(child)); | 480 children_.push_back(std::move(child)); |
| 481 return children_.back().get(); | 481 return children_.back().get(); |
| 482 } | 482 } |
| 483 | 483 |
| 484 PBXFileReference* PBXGroup::AddSourceFile(const std::string& navigator_path, | 484 PBXFileReference* PBXGroup::AddSourceFile(const std::string& navigator_path, |
| 485 const std::string& source_path) { | 485 const std::string& source_path) { |
| 486 DCHECK(!navigator_path.empty()); | 486 DCHECK(!navigator_path.empty()); |
| 487 DCHECK(!source_path.empty()); | 487 DCHECK(!source_path.empty()); |
| 488 std::string::size_type sep = navigator_path.find("/"); | 488 std::string::size_type sep = navigator_path.find("/"); |
| 489 if (sep == std::string::npos) { | 489 if (sep == std::string::npos) { |
| 490 // Prevent same file reference being created and added multiple times. |
| 491 for (const auto& child : children_) { |
| 492 if (child->Class() != PBXFileReferenceClass) |
| 493 continue; |
| 494 |
| 495 PBXFileReference* child_as_file_reference = |
| 496 static_cast<PBXFileReference*>(child.get()); |
| 497 if (child_as_file_reference->Name() == navigator_path && |
| 498 child_as_file_reference->path() == source_path) { |
| 499 return child_as_file_reference; |
| 500 } |
| 501 } |
| 502 |
| 490 children_.push_back(base::MakeUnique<PBXFileReference>( | 503 children_.push_back(base::MakeUnique<PBXFileReference>( |
| 491 navigator_path, source_path, std::string())); | 504 navigator_path, source_path, std::string())); |
| 492 return static_cast<PBXFileReference*>(children_.back().get()); | 505 return static_cast<PBXFileReference*>(children_.back().get()); |
| 493 } | 506 } |
| 494 | 507 |
| 495 PBXGroup* group = nullptr; | 508 PBXGroup* group = nullptr; |
| 496 base::StringPiece component(navigator_path.data(), sep); | 509 base::StringPiece component(navigator_path.data(), sep); |
| 497 for (const auto& child : children_) { | 510 for (const auto& child : children_) { |
| 498 if (child->Class() != PBXGroupClass) | 511 if (child->Class() != PBXGroupClass) |
| 499 continue; | 512 continue; |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 products_->AddChild(base::MakeUnique<PBXFileReference>( | 681 products_->AddChild(base::MakeUnique<PBXFileReference>( |
| 669 std::string(), name_, "compiled.mach-o.executable"))); | 682 std::string(), name_, "compiled.mach-o.executable"))); |
| 670 | 683 |
| 671 const char product_type[] = "com.apple.product-type.tool"; | 684 const char product_type[] = "com.apple.product-type.tool"; |
| 672 targets_.push_back(base::MakeUnique<PBXNativeTarget>( | 685 targets_.push_back(base::MakeUnique<PBXNativeTarget>( |
| 673 name_, std::string(), config_name_, attributes, product_type, name_, | 686 name_, std::string(), config_name_, attributes, product_type, name_, |
| 674 product_reference)); | 687 product_reference)); |
| 675 target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get()); | 688 target_for_indexing_ = static_cast<PBXNativeTarget*>(targets_.back().get()); |
| 676 } | 689 } |
| 677 | 690 |
| 678 void PBXProject::AddNativeTarget(const std::string& name, | 691 PBXNativeTarget* PBXProject::AddNativeTarget( |
| 679 const std::string& type, | 692 const std::string& name, |
| 680 const std::string& output_name, | 693 const std::string& type, |
| 681 const std::string& output_type, | 694 const std::string& output_name, |
| 682 const std::string& shell_script, | 695 const std::string& output_type, |
| 683 const PBXAttributes& extra_attributes) { | 696 const std::string& shell_script, |
| 697 const PBXAttributes& extra_attributes) { |
| 684 base::StringPiece ext = FindExtension(&output_name); | 698 base::StringPiece ext = FindExtension(&output_name); |
| 685 PBXFileReference* product = static_cast<PBXFileReference*>( | 699 PBXFileReference* product = static_cast<PBXFileReference*>( |
| 686 products_->AddChild(base::MakeUnique<PBXFileReference>( | 700 products_->AddChild(base::MakeUnique<PBXFileReference>( |
| 687 std::string(), output_name, | 701 std::string(), output_name, |
| 688 type.empty() ? GetSourceType(ext) : type))); | 702 type.empty() ? GetSourceType(ext) : type))); |
| 689 | 703 |
| 690 size_t ext_offset = FindExtensionOffset(output_name); | 704 size_t ext_offset = FindExtensionOffset(output_name); |
| 691 std::string product_name = ext_offset != std::string::npos | 705 std::string product_name = ext_offset != std::string::npos |
| 692 ? output_name.substr(0, ext_offset - 1) | 706 ? output_name.substr(0, ext_offset - 1) |
| 693 : output_name; | 707 : output_name; |
| 694 | 708 |
| 695 PBXAttributes attributes = extra_attributes; | 709 PBXAttributes attributes = extra_attributes; |
| 696 attributes["CODE_SIGNING_REQUIRED"] = "NO"; | 710 attributes["CODE_SIGNING_REQUIRED"] = "NO"; |
| 697 attributes["CONFIGURATION_BUILD_DIR"] = "."; | 711 attributes["CONFIGURATION_BUILD_DIR"] = "."; |
| 698 attributes["PRODUCT_NAME"] = product_name; | 712 attributes["PRODUCT_NAME"] = product_name; |
| 699 | 713 |
| 700 targets_.push_back(base::MakeUnique<PBXNativeTarget>( | 714 targets_.push_back(base::MakeUnique<PBXNativeTarget>( |
| 701 name, shell_script, config_name_, attributes, output_type, product_name, | 715 name, shell_script, config_name_, attributes, output_type, product_name, |
| 702 product)); | 716 product)); |
| 717 return static_cast<PBXNativeTarget*>(targets_.back().get()); |
| 703 } | 718 } |
| 704 | 719 |
| 705 void PBXProject::SetProjectDirPath(const std::string& project_dir_path) { | 720 void PBXProject::SetProjectDirPath(const std::string& project_dir_path) { |
| 706 DCHECK(!project_dir_path.empty()); | 721 DCHECK(!project_dir_path.empty()); |
| 707 project_dir_path_.assign(project_dir_path); | 722 project_dir_path_.assign(project_dir_path); |
| 708 } | 723 } |
| 709 | 724 |
| 710 void PBXProject::SetProjectRoot(const std::string& project_root) { | 725 void PBXProject::SetProjectRoot(const std::string& project_root) { |
| 711 DCHECK(!project_root.empty()); | 726 DCHECK(!project_root.empty()); |
| 712 project_root_.assign(project_root); | 727 project_root_.assign(project_root); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 const std::string indent_str(indent, '\t'); | 905 const std::string indent_str(indent, '\t'); |
| 891 const IndentRules rules = {false, indent + 1}; | 906 const IndentRules rules = {false, indent + 1}; |
| 892 out << indent_str << Reference() << " = {\n"; | 907 out << indent_str << Reference() << " = {\n"; |
| 893 PrintProperty(out, rules, "isa", ToString(Class())); | 908 PrintProperty(out, rules, "isa", ToString(Class())); |
| 894 PrintProperty(out, rules, "buildConfigurations", configurations_); | 909 PrintProperty(out, rules, "buildConfigurations", configurations_); |
| 895 PrintProperty(out, rules, "defaultConfigurationIsVisible", 1u); | 910 PrintProperty(out, rules, "defaultConfigurationIsVisible", 1u); |
| 896 PrintProperty(out, rules, "defaultConfigurationName", | 911 PrintProperty(out, rules, "defaultConfigurationName", |
| 897 configurations_[0]->Name()); | 912 configurations_[0]->Name()); |
| 898 out << indent_str << "};\n"; | 913 out << indent_str << "};\n"; |
| 899 } | 914 } |
| OLD | NEW |