|
10 | 10 | require_relative "./test_utils/InstallerMock.rb" |
11 | 11 | require_relative "./test_utils/EnvironmentMock.rb" |
12 | 12 | require_relative "./test_utils/SysctlCheckerMock.rb" |
| 13 | +require_relative "./test_utils/XcodebuildMock.rb" |
13 | 14 |
|
14 | 15 | class UtilsTests < Test::Unit::TestCase |
15 | 16 | def teardown |
16 | 17 | Pod::UI.reset() |
17 | 18 | SysctlChecker.reset() |
18 | 19 | Environment.reset() |
| 20 | + XcodebuildMock.reset() |
19 | 21 | ENV['RCT_NEW_ARCH_ENABLED'] = '0' |
20 | 22 | ENV['USE_HERMES'] = '1' |
21 | 23 | end |
@@ -477,9 +479,9 @@ def test_applyMacCatalystPatches_correctlyAppliesNecessaryPatches |
477 | 479 | # ================================= # |
478 | 480 | # Test - Apply Xcode 15 Patch # |
479 | 481 | # ================================= # |
480 | | - |
481 | | - def test_applyXcode15Patch_correctlyAppliesNecessaryPatch |
| 482 | + def test_applyXcode15Patch_whenXcodebuild14_correctlyAppliesNecessaryPatch |
482 | 483 | # Arrange |
| 484 | + XcodebuildMock.set_version = "Xcode 14.3" |
483 | 485 | first_target = prepare_target("FirstTarget") |
484 | 486 | second_target = prepare_target("SecondTarget") |
485 | 487 | third_target = TargetMock.new("ThirdTarget", [ |
@@ -508,24 +510,117 @@ def test_applyXcode15Patch_correctlyAppliesNecessaryPatch |
508 | 510 | ]) |
509 | 511 |
|
510 | 512 | # Act |
511 | | - ReactNativePodsUtils.apply_xcode_15_patch(installer) |
| 513 | + user_project_mock.build_configurations.each do |config| |
| 514 | + assert_nil(config.build_settings["OTHER_LDFLAGS"]) |
| 515 | + end |
| 516 | + |
| 517 | + ReactNativePodsUtils.apply_xcode_15_patch(installer, :xcodebuild_manager => XcodebuildMock) |
512 | 518 |
|
513 | 519 | # Assert |
514 | | - first_target.build_configurations.each do |config| |
515 | | - assert_equal(config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"].strip, |
516 | | - '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"' |
517 | | - ) |
| 520 | + user_project_mock.build_configurations.each do |config| |
| 521 | + assert_equal("$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION", config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"]) |
| 522 | + assert_equal("$(inherited) ", config.build_settings["OTHER_LDFLAGS"]) |
518 | 523 | end |
519 | | - second_target.build_configurations.each do |config| |
520 | | - assert_equal(config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"].strip, |
521 | | - '$(inherited) "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"' |
522 | | - ) |
| 524 | + |
| 525 | + # User project and Pods project |
| 526 | + assert_equal(2, XcodebuildMock.version_invocation_count) |
| 527 | + end |
| 528 | + |
| 529 | + def test_applyXcode15Patch_whenXcodebuild15_correctlyAppliesNecessaryPatch |
| 530 | + # Arrange |
| 531 | + XcodebuildMock.set_version = "Xcode 15.0" |
| 532 | + first_target = prepare_target("FirstTarget") |
| 533 | + second_target = prepare_target("SecondTarget") |
| 534 | + third_target = TargetMock.new("ThirdTarget", [ |
| 535 | + BuildConfigurationMock.new("Debug", { |
| 536 | + "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" ' |
| 537 | + }), |
| 538 | + BuildConfigurationMock.new("Release", { |
| 539 | + "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" ' |
| 540 | + }), |
| 541 | + ], nil) |
| 542 | + |
| 543 | + user_project_mock = UserProjectMock.new("/a/path", [ |
| 544 | + prepare_config("Debug"), |
| 545 | + prepare_config("Release"), |
| 546 | + ], |
| 547 | + :native_targets => [ |
| 548 | + first_target, |
| 549 | + second_target |
| 550 | + ] |
| 551 | + ) |
| 552 | + pods_projects_mock = PodsProjectMock.new([], {"hermes-engine" => {}}, :native_targets => [ |
| 553 | + third_target |
| 554 | + ]) |
| 555 | + installer = InstallerMock.new(pods_projects_mock, [ |
| 556 | + AggregatedProjectMock.new(user_project_mock) |
| 557 | + ]) |
| 558 | + |
| 559 | + # Act |
| 560 | + user_project_mock.build_configurations.each do |config| |
| 561 | + assert_nil(config.build_settings["OTHER_LDFLAGS"]) |
523 | 562 | end |
524 | | - third_target.build_configurations.each do |config| |
525 | | - assert_equal(config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"].strip, |
526 | | - '$(inherited) "SomeFlag=1" "_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION"' |
527 | | - ) |
| 563 | + |
| 564 | + ReactNativePodsUtils.apply_xcode_15_patch(installer, :xcodebuild_manager => XcodebuildMock) |
| 565 | + |
| 566 | + # Assert |
| 567 | + user_project_mock.build_configurations.each do |config| |
| 568 | + assert_equal("$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION", config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"]) |
| 569 | + assert_equal("$(inherited) -Wl -ld_classic ", config.build_settings["OTHER_LDFLAGS"]) |
| 570 | + end |
| 571 | + |
| 572 | + # User project and Pods project |
| 573 | + assert_equal(2, XcodebuildMock.version_invocation_count) |
| 574 | + end |
| 575 | + |
| 576 | + def test_applyXcode15Patch_whenXcodebuild14ButProjectHasSettings_correctlyRemovesNecessaryPatch |
| 577 | + # Arrange |
| 578 | + XcodebuildMock.set_version = "Xcode 14.3" |
| 579 | + first_target = prepare_target("FirstTarget") |
| 580 | + second_target = prepare_target("SecondTarget") |
| 581 | + third_target = TargetMock.new("ThirdTarget", [ |
| 582 | + BuildConfigurationMock.new("Debug", { |
| 583 | + "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" ' |
| 584 | + }), |
| 585 | + BuildConfigurationMock.new("Release", { |
| 586 | + "GCC_PREPROCESSOR_DEFINITIONS" => '$(inherited) "SomeFlag=1" ' |
| 587 | + }), |
| 588 | + ], nil) |
| 589 | + |
| 590 | + debug_config = prepare_config("Debug", {"OTHER_LDFLAGS" => "$(inherited) -Wl -ld_classic "}) |
| 591 | + release_config = prepare_config("Release", {"OTHER_LDFLAGS" => "$(inherited) -Wl -ld_classic "}) |
| 592 | + |
| 593 | + user_project_mock = UserProjectMock.new("/a/path", [ |
| 594 | + debug_config, |
| 595 | + release_config, |
| 596 | + ], |
| 597 | + :native_targets => [ |
| 598 | + first_target, |
| 599 | + second_target |
| 600 | + ] |
| 601 | + ) |
| 602 | + pods_projects_mock = PodsProjectMock.new([debug_config.clone, release_config.clone], {"hermes-engine" => {}}, :native_targets => [ |
| 603 | + third_target |
| 604 | + ]) |
| 605 | + installer = InstallerMock.new(pods_projects_mock, [ |
| 606 | + AggregatedProjectMock.new(user_project_mock) |
| 607 | + ]) |
| 608 | + |
| 609 | + # Act |
| 610 | + user_project_mock.build_configurations.each do |config| |
| 611 | + assert_equal("$(inherited) -Wl -ld_classic ", config.build_settings["OTHER_LDFLAGS"]) |
| 612 | + end |
| 613 | + |
| 614 | + ReactNativePodsUtils.apply_xcode_15_patch(installer, :xcodebuild_manager => XcodebuildMock) |
| 615 | + |
| 616 | + # Assert |
| 617 | + user_project_mock.build_configurations.each do |config| |
| 618 | + assert_equal("$(inherited) _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION", config.build_settings["GCC_PREPROCESSOR_DEFINITIONS"]) |
| 619 | + assert_equal("$(inherited) ", config.build_settings["OTHER_LDFLAGS"]) |
528 | 620 | end |
| 621 | + |
| 622 | + # User project and Pods project |
| 623 | + assert_equal(2, XcodebuildMock.version_invocation_count) |
529 | 624 | end |
530 | 625 |
|
531 | 626 | # ==================================== # |
@@ -562,12 +657,14 @@ def prepare_empty_user_project_mock |
562 | 657 | ]) |
563 | 658 | end |
564 | 659 |
|
565 | | -def prepare_config(config_name) |
566 | | - return BuildConfigurationMock.new(config_name, {"LIBRARY_SEARCH_PATHS" => [ |
| 660 | +def prepare_config(config_name, extra_config = {}) |
| 661 | + config = {"LIBRARY_SEARCH_PATHS" => [ |
567 | 662 | "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)", |
568 | 663 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"", |
569 | 664 | "another/path", |
570 | | - ]}) |
| 665 | + ]}.merge(extra_config) |
| 666 | + |
| 667 | + return BuildConfigurationMock.new(config_name, config) |
571 | 668 | end |
572 | 669 |
|
573 | 670 | def prepare_target(name, product_type = nil) |
|
0 commit comments