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

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

Issue 2576773002: [Refactor Xcode Objects] Enable navigator paths for file references. (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
« no previous file with comments | « tools/gn/xcode_object.h ('k') | tools/gn/xcode_writer.cc » ('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 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 const std::string& type) 397 const std::string& type)
398 : name_(name), path_(path), type_(type) {} 398 : name_(name), path_(path), type_(type) {}
399 399
400 PBXFileReference::~PBXFileReference() {} 400 PBXFileReference::~PBXFileReference() {}
401 401
402 PBXObjectClass PBXFileReference::Class() const { 402 PBXObjectClass PBXFileReference::Class() const {
403 return PBXFileReferenceClass; 403 return PBXFileReferenceClass;
404 } 404 }
405 405
406 std::string PBXFileReference::Name() const { 406 std::string PBXFileReference::Name() const {
407 return path_; 407 return name_;
408 } 408 }
409 409
410 void PBXFileReference::Print(std::ostream& out, unsigned indent) const { 410 void PBXFileReference::Print(std::ostream& out, unsigned indent) const {
411 const std::string indent_str(indent, '\t'); 411 const std::string indent_str(indent, '\t');
412 const IndentRules rules = {true, 0}; 412 const IndentRules rules = {true, 0};
413 out << indent_str << Reference() << " = {"; 413 out << indent_str << Reference() << " = {";
414 PrintProperty(out, rules, "isa", ToString(Class())); 414 PrintProperty(out, rules, "isa", ToString(Class()));
415 415
416 if (!type_.empty()) { 416 if (!type_.empty()) {
417 PrintProperty(out, rules, "explicitFileType", type_); 417 PrintProperty(out, rules, "explicitFileType", type_);
418 PrintProperty(out, rules, "includeInIndex", 0u); 418 PrintProperty(out, rules, "includeInIndex", 0u);
419 } else { 419 } else {
420 base::StringPiece ext = FindExtension(&path_); 420 base::StringPiece ext = FindExtension(&name_);
421 if (HasExplicitFileType(ext)) 421 if (HasExplicitFileType(ext))
422 PrintProperty(out, rules, "explicitFileType", GetSourceType(ext)); 422 PrintProperty(out, rules, "explicitFileType", GetSourceType(ext));
423 else 423 else
424 PrintProperty(out, rules, "lastKnownFileType", GetSourceType(ext)); 424 PrintProperty(out, rules, "lastKnownFileType", GetSourceType(ext));
425 } 425 }
426 426
427 if (name_ != path_ && !name_.empty()) 427 if (!name_.empty())
428 PrintProperty(out, rules, "name", name_); 428 PrintProperty(out, rules, "name", name_);
429 429
430 DCHECK(!path_.empty());
430 PrintProperty(out, rules, "path", path_); 431 PrintProperty(out, rules, "path", path_);
431 PrintProperty(out, rules, "sourceTree", 432 PrintProperty(out, rules, "sourceTree",
432 type_.empty() ? "<group>" : "BUILT_PRODUCTS_DIR"); 433 type_.empty() ? "<group>" : "BUILT_PRODUCTS_DIR");
433 out << "};\n"; 434 out << "};\n";
434 } 435 }
435 436
436 // PBXFrameworksBuildPhase ---------------------------------------------------- 437 // PBXFrameworksBuildPhase ----------------------------------------------------
437 438
438 PBXFrameworksBuildPhase::PBXFrameworksBuildPhase() {} 439 PBXFrameworksBuildPhase::PBXFrameworksBuildPhase() {}
439 440
(...skipping 24 matching lines...) Expand all
464 : name_(name), path_(path) {} 465 : name_(name), path_(path) {}
465 466
466 PBXGroup::~PBXGroup() {} 467 PBXGroup::~PBXGroup() {}
467 468
468 PBXObject* PBXGroup::AddChild(std::unique_ptr<PBXObject> child) { 469 PBXObject* PBXGroup::AddChild(std::unique_ptr<PBXObject> child) {
469 DCHECK(child); 470 DCHECK(child);
470 children_.push_back(std::move(child)); 471 children_.push_back(std::move(child));
471 return children_.back().get(); 472 return children_.back().get();
472 } 473 }
473 474
474 PBXFileReference* PBXGroup::AddSourceFile(const std::string& source_path) { 475 PBXFileReference* PBXGroup::AddSourceFile(const std::string& navigator_path,
476 const std::string& source_path) {
477 DCHECK(!navigator_path.empty());
475 DCHECK(!source_path.empty()); 478 DCHECK(!source_path.empty());
476 std::string::size_type sep = source_path.find("/"); 479 std::string::size_type sep = navigator_path.find("/");
477 if (sep == std::string::npos) { 480 if (sep == std::string::npos) {
478 children_.push_back(base::MakeUnique<PBXFileReference>( 481 children_.push_back(base::MakeUnique<PBXFileReference>(
479 std::string(), source_path, std::string())); 482 navigator_path, source_path, std::string()));
480 return static_cast<PBXFileReference*>(children_.back().get()); 483 return static_cast<PBXFileReference*>(children_.back().get());
481 } 484 }
482 485
483 PBXGroup* group = nullptr; 486 PBXGroup* group = nullptr;
484 base::StringPiece component(source_path.data(), sep); 487 base::StringPiece component(navigator_path.data(), sep);
485 for (const auto& child : children_) { 488 for (const auto& child : children_) {
486 if (child->Class() != PBXGroupClass) 489 if (child->Class() != PBXGroupClass)
487 continue; 490 continue;
488 491
489 PBXGroup* child_as_group = static_cast<PBXGroup*>(child.get()); 492 PBXGroup* child_as_group = static_cast<PBXGroup*>(child.get());
490 if (child_as_group->path_ == component) { 493 if (child_as_group->name_ == component) {
491 group = child_as_group; 494 group = child_as_group;
492 break; 495 break;
493 } 496 }
494 } 497 }
495 498
496 if (!group) { 499 if (!group) {
497 children_.push_back(base::WrapUnique(new PBXGroup(component.as_string()))); 500 children_.push_back(base::WrapUnique(
501 new PBXGroup(component.as_string(), component.as_string())));
498 group = static_cast<PBXGroup*>(children_.back().get()); 502 group = static_cast<PBXGroup*>(children_.back().get());
499 } 503 }
500 504
501 DCHECK(group); 505 DCHECK(group);
502 DCHECK(group->path_ == component); 506 DCHECK(group->name_ == component);
503 return group->AddSourceFile(source_path.substr(sep + 1)); 507 return group->AddSourceFile(navigator_path.substr(sep + 1), source_path);
504 } 508 }
505 509
506 PBXObjectClass PBXGroup::Class() const { 510 PBXObjectClass PBXGroup::Class() const {
507 return PBXGroupClass; 511 return PBXGroupClass;
508 } 512 }
509 513
510 std::string PBXGroup::Name() const { 514 std::string PBXGroup::Name() const {
511 if (!name_.empty()) 515 if (!name_.empty())
512 return name_; 516 return name_;
513 if (!path_.empty()) 517 if (!path_.empty())
514 return path_; 518 return path_;
515 return std::string(); 519 return std::string();
516 } 520 }
517 521
518 void PBXGroup::Visit(PBXObjectVisitor& visitor) { 522 void PBXGroup::Visit(PBXObjectVisitor& visitor) {
519 PBXObject::Visit(visitor); 523 PBXObject::Visit(visitor);
520 for (const auto& child : children_) { 524 for (const auto& child : children_) {
521 child->Visit(visitor); 525 child->Visit(visitor);
522 } 526 }
523 } 527 }
524 528
525 void PBXGroup::Print(std::ostream& out, unsigned indent) const { 529 void PBXGroup::Print(std::ostream& out, unsigned indent) const {
526 const std::string indent_str(indent, '\t'); 530 const std::string indent_str(indent, '\t');
527 const IndentRules rules = {false, indent + 1}; 531 const IndentRules rules = {false, indent + 1};
528 out << indent_str << Reference() << " = {\n"; 532 out << indent_str << Reference() << " = {\n";
529 PrintProperty(out, rules, "isa", ToString(Class())); 533 PrintProperty(out, rules, "isa", ToString(Class()));
530 PrintProperty(out, rules, "children", children_); 534 PrintProperty(out, rules, "children", children_);
531 if (!name_.empty()) 535 if (!name_.empty())
532 PrintProperty(out, rules, "name", name_); 536 PrintProperty(out, rules, "name", name_);
533 if (!path_.empty()) 537 if (is_source_ && !path_.empty())
534 PrintProperty(out, rules, "path", path_); 538 PrintProperty(out, rules, "path", path_);
535 PrintProperty(out, rules, "sourceTree", "<group>"); 539 PrintProperty(out, rules, "sourceTree", "<group>");
536 out << indent_str << "};\n"; 540 out << indent_str << "};\n";
537 } 541 }
538 542
539 // PBXNativeTarget ------------------------------------------------------------ 543 // PBXNativeTarget ------------------------------------------------------------
540 544
541 PBXNativeTarget::PBXNativeTarget(const std::string& name, 545 PBXNativeTarget::PBXNativeTarget(const std::string& name,
542 const std::string& shell_script, 546 const std::string& shell_script,
543 const std::string& config_name, 547 const std::string& config_name,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 PBXProject::PBXProject(const std::string& name, 595 PBXProject::PBXProject(const std::string& name,
592 const std::string& config_name, 596 const std::string& config_name,
593 const std::string& source_path, 597 const std::string& source_path,
594 const PBXAttributes& attributes) 598 const PBXAttributes& attributes)
595 : name_(name), config_name_(config_name), target_for_indexing_(nullptr) { 599 : name_(name), config_name_(config_name), target_for_indexing_(nullptr) {
596 attributes_["BuildIndependentTargetsInParallel"] = "YES"; 600 attributes_["BuildIndependentTargetsInParallel"] = "YES";
597 601
598 main_group_.reset(new PBXGroup); 602 main_group_.reset(new PBXGroup);
599 sources_ = static_cast<PBXGroup*>( 603 sources_ = static_cast<PBXGroup*>(
600 main_group_->AddChild(base::MakeUnique<PBXGroup>(source_path, "Source"))); 604 main_group_->AddChild(base::MakeUnique<PBXGroup>(source_path, "Source")));
605 sources_->set_is_source(true);
601 products_ = static_cast<PBXGroup*>(main_group_->AddChild( 606 products_ = static_cast<PBXGroup*>(main_group_->AddChild(
602 base::MakeUnique<PBXGroup>(std::string(), "Product"))); 607 base::MakeUnique<PBXGroup>(std::string(), "Product")));
603 main_group_->AddChild(base::MakeUnique<PBXGroup>(std::string(), "Build")); 608 main_group_->AddChild(base::MakeUnique<PBXGroup>(std::string(), "Build"));
604 609
605 configurations_.reset(new XCConfigurationList(config_name, attributes, this)); 610 configurations_.reset(new XCConfigurationList(config_name, attributes, this));
606 } 611 }
607 612
608 PBXProject::~PBXProject() {} 613 PBXProject::~PBXProject() {}
609 614
610 void PBXProject::AddSourceFile(const std::string& source_path) { 615 void PBXProject::AddSourceFile(const std::string& navigator_path,
611 PBXFileReference* file_reference = sources_->AddSourceFile(source_path); 616 const std::string& source_path) {
617 PBXFileReference* file_reference =
618 sources_->AddSourceFile(navigator_path, source_path);
612 base::StringPiece ext = FindExtension(&source_path); 619 base::StringPiece ext = FindExtension(&source_path);
613 if (!IsSourceFileForIndexing(ext)) 620 if (!IsSourceFileForIndexing(ext))
614 return; 621 return;
615 622
616 if (!target_for_indexing_) { 623 if (!target_for_indexing_) {
617 PBXAttributes attributes; 624 PBXAttributes attributes;
618 attributes["EXECUTABLE_PREFIX"] = ""; 625 attributes["EXECUTABLE_PREFIX"] = "";
619 attributes["HEADER_SEARCH_PATHS"] = sources_->path(); 626 attributes["HEADER_SEARCH_PATHS"] = sources_->path();
620 attributes["PRODUCT_NAME"] = name_; 627 attributes["PRODUCT_NAME"] = name_;
621 628
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 const std::string indent_str(indent, '\t'); 866 const std::string indent_str(indent, '\t');
860 const IndentRules rules = {false, indent + 1}; 867 const IndentRules rules = {false, indent + 1};
861 out << indent_str << Reference() << " = {\n"; 868 out << indent_str << Reference() << " = {\n";
862 PrintProperty(out, rules, "isa", ToString(Class())); 869 PrintProperty(out, rules, "isa", ToString(Class()));
863 PrintProperty(out, rules, "buildConfigurations", configurations_); 870 PrintProperty(out, rules, "buildConfigurations", configurations_);
864 PrintProperty(out, rules, "defaultConfigurationIsVisible", 1u); 871 PrintProperty(out, rules, "defaultConfigurationIsVisible", 1u);
865 PrintProperty(out, rules, "defaultConfigurationName", 872 PrintProperty(out, rules, "defaultConfigurationName",
866 configurations_[0]->Name()); 873 configurations_[0]->Name());
867 out << indent_str << "};\n"; 874 out << indent_str << "};\n";
868 } 875 }
OLDNEW
« no previous file with comments | « 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