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

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

Issue 2779833002: [iOS] Add application target as dependency of xctest module target. (Closed)
Patch Set: Update comments Created 3 years, 8 months 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.cc ('k') | no next file » | 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_writer.h" 5 #include "tools/gn/xcode_writer.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 15 matching lines...) Expand all
26 #include "tools/gn/source_file.h" 26 #include "tools/gn/source_file.h"
27 #include "tools/gn/target.h" 27 #include "tools/gn/target.h"
28 #include "tools/gn/value.h" 28 #include "tools/gn/value.h"
29 #include "tools/gn/variables.h" 29 #include "tools/gn/variables.h"
30 #include "tools/gn/xcode_object.h" 30 #include "tools/gn/xcode_object.h"
31 31
32 namespace { 32 namespace {
33 33
34 using TargetToFileList = std::unordered_map<const Target*, Target::FileList>; 34 using TargetToFileList = std::unordered_map<const Target*, Target::FileList>;
35 using TargetToTarget = std::unordered_map<const Target*, const Target*>; 35 using TargetToTarget = std::unordered_map<const Target*, const Target*>;
36 using TargetToPBXTarget = std::unordered_map<const Target*, PBXTarget*>;
36 37
37 const char kEarlGreyFileNameIdentifier[] = "egtest.mm"; 38 const char kEarlGreyFileNameIdentifier[] = "egtest.mm";
38 const char kXCTestFileNameIdentifier[] = "xctest.mm"; 39 const char kXCTestFileNameIdentifier[] = "xctest.mm";
39 const char kXCTestModuleTargetNamePostfix[] = "_module"; 40 const char kXCTestModuleTargetNamePostfix[] = "_module";
40 41
41 struct SafeEnvironmentVariableInfo { 42 struct SafeEnvironmentVariableInfo {
42 const char* name; 43 const char* name;
43 bool capture_at_generation; 44 bool capture_at_generation;
44 }; 45 };
45 46
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 DCHECK_EQ(xctest_module_targets.size(), xctest_application_targets.size()); 454 DCHECK_EQ(xctest_module_targets.size(), xctest_application_targets.size());
454 DCHECK_EQ(xctest_module_targets.size(), 455 DCHECK_EQ(xctest_module_targets.size(),
455 xctest_module_to_application_target.size()); 456 xctest_module_to_application_target.size());
456 457
457 TargetToFileList xctest_files_per_application_target; 458 TargetToFileList xctest_files_per_application_target;
458 FindXCTestFilesForApplicationTargets(xctest_application_targets, 459 FindXCTestFilesForApplicationTargets(xctest_application_targets,
459 &xctest_files_per_application_target); 460 &xctest_files_per_application_target);
460 DCHECK_EQ(xctest_application_targets.size(), 461 DCHECK_EQ(xctest_application_targets.size(),
461 xctest_files_per_application_target.size()); 462 xctest_files_per_application_target.size());
462 463
464 TargetToPBXTarget bundle_target_to_pbxtarget;
465
463 std::string build_path; 466 std::string build_path;
464 std::unique_ptr<base::Environment> env(base::Environment::Create()); 467 std::unique_ptr<base::Environment> env(base::Environment::Create());
465 468
466 main_project->AddAggregateTarget( 469 main_project->AddAggregateTarget(
467 "All", GetBuildScript(root_target, ninja_extra_args, env.get())); 470 "All", GetBuildScript(root_target, ninja_extra_args, env.get()));
468 471
469 for (const Target* target : targets) { 472 for (const Target* target : targets) {
470 switch (target->output_type()) { 473 switch (target->output_type()) {
471 case Target::EXECUTABLE: 474 case Target::EXECUTABLE:
472 if (target_os == XcodeWriter::WRITER_TARGET_OS_IOS) 475 if (target_os == XcodeWriter::WRITER_TARGET_OS_IOS)
(...skipping 25 matching lines...) Expand all
498 501
499 PBXNativeTarget* native_target = main_project->AddNativeTarget( 502 PBXNativeTarget* native_target = main_project->AddNativeTarget(
500 target->label().name(), std::string(), 503 target->label().name(), std::string(),
501 RebasePath(target->bundle_data() 504 RebasePath(target->bundle_data()
502 .GetBundleRootDirOutput(target->settings()) 505 .GetBundleRootDirOutput(target->settings())
503 .value(), 506 .value(),
504 build_settings->build_dir()), 507 build_settings->build_dir()),
505 target->bundle_data().product_type(), 508 target->bundle_data().product_type(),
506 GetBuildScript(target->label().name(), ninja_extra_args, env.get()), 509 GetBuildScript(target->label().name(), ninja_extra_args, env.get()),
507 extra_attributes); 510 extra_attributes);
511 bundle_target_to_pbxtarget.insert(
512 std::make_pair(target, native_target));
508 513
509 if (!IsXCTestModuleTarget(target)) 514 if (!IsXCTestModuleTarget(target))
510 continue; 515 continue;
511 516
512 // Add xctest files to the "Compiler Sources" of corresponding xctest 517 // Add xctest files to the "Compiler Sources" of corresponding xctest
513 // native targets. 518 // native targets.
514 const Target::FileList& xctest_file_list = 519 const Target::FileList& xctest_file_list =
515 xctest_files_per_application_target 520 xctest_files_per_application_target
516 [xctest_module_to_application_target[target]]; 521 [xctest_module_to_application_target[target]];
517 522
(...skipping 10 matching lines...) Expand all
528 } 533 }
529 534
530 break; 535 break;
531 } 536 }
532 537
533 default: 538 default:
534 break; 539 break;
535 } 540 }
536 } 541 }
537 542
543 // Add corresponding application target as dependency of xctest module target
544 // so that application target is re-compiled when compiling xctest module
545 // target.
546 for (const Target* target : targets) {
547 if (target->output_type() != Target::CREATE_BUNDLE)
548 continue;
549 if (!IsXCTestModuleTarget(target))
550 continue;
551
552 const Target* application_target =
553 FindXCTestApplicationTarget(target, targets);
554 PBXTarget* application_pbxtarget =
555 bundle_target_to_pbxtarget[application_target];
556 DCHECK(application_pbxtarget);
557 PBXTarget* xctest_module_pbxtarget = bundle_target_to_pbxtarget[target];
558 DCHECK(xctest_module_pbxtarget);
559
560 std::unique_ptr<PBXContainerItemProxy> container_item_proxy(
561 new PBXContainerItemProxy(main_project.get(), application_pbxtarget));
562 std::unique_ptr<PBXTargetDependency> dependency(new PBXTargetDependency(
563 application_pbxtarget, std::move(container_item_proxy)));
564
565 xctest_module_pbxtarget->AddDependency(std::move(dependency));
566 }
567
538 projects_.push_back(std::move(main_project)); 568 projects_.push_back(std::move(main_project));
539 } 569 }
540 570
541 bool XcodeWriter::WriteFiles(const BuildSettings* build_settings, Err* err) { 571 bool XcodeWriter::WriteFiles(const BuildSettings* build_settings, Err* err) {
542 for (const auto& project : projects_) { 572 for (const auto& project : projects_) {
543 if (!WriteProjectFile(build_settings, project.get(), err)) 573 if (!WriteProjectFile(build_settings, project.get(), err))
544 return false; 574 return false;
545 } 575 }
546 576
547 SourceFile xcworkspacedata_file = 577 SourceFile xcworkspacedata_file =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 for (auto* object : pair.second) { 636 for (auto* object : pair.second) {
607 object->Print(out, 2); 637 object->Print(out, 2);
608 } 638 }
609 out << "/* End " << ToString(pair.first) << " section */\n"; 639 out << "/* End " << ToString(pair.first) << " section */\n";
610 } 640 }
611 641
612 out << "\t};\n" 642 out << "\t};\n"
613 << "\trootObject = " << project->Reference() << ";\n" 643 << "\trootObject = " << project->Reference() << ";\n"
614 << "}\n"; 644 << "}\n";
615 } 645 }
OLDNEW
« no previous file with comments | « tools/gn/xcode_object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698