Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastlane scan with --run_rosetta_simulator selects the wrong simulator #21293

Open
3 of 4 tasks
nevil opened this issue May 19, 2023 · 28 comments
Open
3 of 4 tasks

fastlane scan with --run_rosetta_simulator selects the wrong simulator #21293

nevil opened this issue May 19, 2023 · 28 comments

Comments

@nevil
Copy link

nevil commented May 19, 2023

New Issue Checklist

Issue Description

fastlane scan with --run_rosetta_simulator selects the wrong simulator when using --run_rosetta_simulator.

I'm using the changes from this PR #21284

gem "fastlane", :git => "https://github.com/fastlane/fastlane.git", :ref => "586b13f72ee21b5dcac26241435425614bde475c"

A special XCTestCase was added that fails with a text corresponding to the simulators iOS version.
When using --run_rosetta_simulator is specified, the selected simulator is the iPhone 11, iOS 16.4.
Not the iPhone 12, iOS 15.5

final class FastlaneTests: XCTestCase {
    func testFastlaneScan() {
        if #available(iOS 16, *) {
            XCTFail("iOS 16")
        } else if #available(iOS 15, *) {
            XCTFail("iOS 15")
        } else {
            XCTFail("Other iOS")
        }
    }
}
Command executed
bundle exec fastlane scan --clean --workspace  USDK.xcworkspace --scheme USDK --force_quit_simulator --skip_build --device "iPhone 12" --run_rosetta_simulator --only_testing USDKTests/FastlaneTests/testFastlaneScan
Complete output when running fastlane, including the stack trace and command used

Listed destinations

[21:25:32]: ▸ 2023-05-19 21:25:32.681 xcodebuild[70435:759037] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
[21:26:03]: ▸ --- xcodebuild: WARNING: Using the first of multiple matching destinations:
[21:26:03]: ▸ { platform:iOS Simulator, id:DA521529-88CC-4C71-960C-680FB6A23AAD, OS:16.4, name:iPhone 11 }
[21:26:03]: ▸ { platform:iOS Simulator, id:F5E604EC-BDD1-4AF3-BC7A-46B62A758232, OS:15.5, name:iPhone 12 }

XCTest result:

[21:27:46]: ▸ Selected tests
[21:27:46]: ▸ Test Suite UNextSDKTests.xctest started
[21:27:46]: ▸ FastlaneTests
[21:27:46]: ▸     ✗ testFastlaneScan, failed - iOS 16
[21:27:46]: ▸ UNextSDKTests.FastlaneTests
[21:27:46]: ▸   testFastlaneScan, failed - iOS 16
[21:27:46]: ▸   /Users/h-anders/Development/git-repos/iOS_repos/iOS4/iOS_SDK/UNextSDKTests/Model/AccountInfo/UNAccountInfoTests.swift:15
[21:27:46]: ▸   ```
[21:27:46]: ▸         if #available(iOS 16, *) {
[21:27:46]: ▸             XCTFail("iOS 16")
[21:27:46]: ▸         } else if #available(iOS 15, *) {
[21:27:46]: ▸   ```
[21:27:46]: ▸ 	 Executed 1 test, with 1 failure (0 unexpected) in 0.497 (0.502) seconds
[21:27:46]: ▸

As can be seen from the test result, the iPhone 11 simulator is selected even though iPhone 12 is specified.

Environment

✅ fastlane environment ✅

Stack

Key Value
OS 13.4
Ruby 2.6.10
Bundler? true
Git git version 2.40.1
Installation Source ~/Development/git-repos/iOS_repos/iOS4/iOS_SDK/vendor/bundle/ruby/2.6.0/bin/fastlane
Host macOS 13.4 (22F66)
Ruby Lib Dir /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib
OpenSSL Version LibreSSL 3.3.6
Is contained false
Is homebrew false
Is installed via Fabric.app false
Xcode Path /Applications/Xcode-14.3.1.app/Contents/Developer/
Xcode Version 14.3.1
Swift Version 5.8.1

System Locale

Variable Value
LANG en_US.UTF-8
LC_ALL en_US.UTF-8
LANGUAGE

fastlane files:

No Fastfile found

No Appfile found

fastlane gems

Gem Version Update-Status
fastlane 2.212.2 ✅ Up-To-Date

Loaded fastlane plugins:

No plugins Loaded

Loaded gems
Gem Version
did_you_mean 1.3.0
bundler 2.1.4
rake 13.0.6
rexml 3.2.5
CFPropertyList 3.0.4
concurrent-ruby 1.2.2
i18n 1.13.0
minitest 5.18.0
tzinfo 2.0.6
zeitwerk 2.6.8
activesupport 6.1.7.3
public_suffix 4.0.6
addressable 2.8.0
httpclient 2.8.3
json 2.5.1
algoliasearch 1.27.5
artifactory 3.0.15
atomos 0.1.3
aws-eventstream 1.2.0
aws-partitions 1.766.0
aws-sigv4 1.5.2
jmespath 1.6.2
aws-sdk-core 3.173.0
aws-sdk-kms 1.64.0
aws-sdk-s3 1.122.0
babosa 1.0.4
claide 1.0.3
colored2 3.1.2
cork 0.3.0
nap 1.1.0
open4 1.3.4
claide-plugins 0.9.2
fuzzy_match 2.0.4
netrc 0.11.0
ffi 1.15.5
ethon 0.16.0
typhoeus 1.4.0
cocoapods-core 1.12.1
cocoapods-deintegrate 1.0.5
cocoapods-downloader 1.6.3
cocoapods-plugins 1.0.0
cocoapods-search 1.0.1
cocoapods-trunk 1.6.0
cocoapods-try 1.2.0
escape 0.0.4
fourflusher 2.3.1
gh_inspector 1.1.3
molinillo 0.8.0
ruby-macho 2.5.1
nanaimo 0.3.0
xcodeproj 1.21.0
cocoapods 1.12.1
colored 1.2
highline 2.0.3
commander 4.6.0
faraday-em_http 1.0.0
faraday-em_synchrony 1.0.0
faraday-excon 1.1.0
faraday-httpclient 1.0.1
faraday-net_http 1.0.1
faraday-net_http_persistent 1.2.0
faraday-patron 1.0.0
faraday-rack 1.0.0
multipart-post 2.0.0
ruby2_keywords 0.0.5
faraday 1.8.0
faraday-http-cache 2.2.0
rchardet 1.8.0
git 1.13.1
kramdown 2.3.1
kramdown-parser-gfm 1.1.0
no_proxy_fix 0.1.2
sawyer 0.8.2
octokit 4.21.0
unicode-display_width 1.8.0
terminal-table 1.8.0
danger 8.4.2
thor 0.20.3
danger-swiftlint 0.29.4
declarative 0.0.20
digest-crc 0.6.4
unf_ext 0.0.8.2
unf 0.1.4
domain_name 0.5.20190701
dotenv 2.8.1
emoji_regex 3.2.3
excon 0.99.0
http-cookie 1.0.5
faraday-cookie_jar 0.0.7
faraday_middleware 1.2.0
fastimage 2.2.6
jwt 2.7.0
memoist 0.16.2
multi_json 1.15.0
os 1.1.4
signet 0.17.0
googleauth 1.5.2
mini_mime 1.1.2
trailblazer-option 0.1.2
uber 0.1.0
representable 3.2.0
retriable 3.1.2
webrick 1.8.1
google-apis-core 0.11.0
google-apis-androidpublisher_v3 0.42.0
google-apis-playcustomapp_v1 0.13.0
google-apis-iamcredentials_v1 0.17.0
google-apis-storage_v1 0.19.0
google-cloud-env 1.6.0
google-cloud-errors 1.3.1
google-cloud-core 1.6.0
google-cloud-storage 1.44.0
mini_magick 4.12.0
naturally 2.2.1
optparse 0.1.1
plist 3.7.0
rubyzip 2.3.2
security 0.1.3
simctl 1.6.10
terminal-notifier 2.0.0
tty-screen 0.8.1
tty-cursor 0.7.1
tty-spinner 0.9.3
word_wrap 1.0.0
rouge 2.0.7
xcpretty 0.3.0
xcpretty-travis-formatter 1.0.1

generated on: 2023-05-19

@nevil
Copy link
Author

nevil commented May 20, 2023

@joshdholtz
@rogerluan
Sorry to directly mention you both.
I see that the 2.213.0 release is being prepared which relates to the above.

Is the destination selection working for you when arch=x86_64 is appended?

For me it selects the first found simulator which is not what I expect.

Direct invocation of xcodebuild shows the same behavior.

@rogerluan
Copy link
Member

Hi @nevil 👋

Mine logs the same thing as yours (the warning):

[14:53:40]: ▸ --- xcodebuild: WARNING: Using the first of multiple matching destinations:
[14:53:40]: ▸ { platform:iOS Simulator, id:EEBA2B14-A40A-441D-90D9-41390EC54D83, OS:16.4, name:iPad (9th generation) }
[14:53:40]: ▸ { platform:iOS Simulator, id:FD80CBCC-8FEB-44A0-91F4-B586F2FF49C7, OS:16.4, name:iPad (10th generation) }
[14:53:40]: ▸ { platform:iOS Simulator, id:12B73B48-D1FB-4C69-A9DB-4DCE220009E1, OS:16.4, name:iPad Air (5th generation) }
[14:53:40]: ▸ { platform:iOS Simulator, id:DD5F756A-B55D-4A80-960C-E932D72169B1, OS:16.4, name:iPad Pro (11-inch) (3rd generation) }
[14:53:40]: ▸ { platform:iOS Simulator, id:7DE2E10B-8D04-4725-B4EF-8B3B4C2EE1D5, OS:16.4, name:iPad Pro (11-inch) (4th generation) }
[14:53:40]: ▸ { platform:iOS Simulator, id:535F54CB-D5CA-420D-AA3B-61E2505434CA, OS:16.4, name:iPad Pro (12.9-inch) (5th generation) }
[14:53:40]: ▸ { platform:iOS Simulator, id:F3993159-D7FB-4D3C-B7A0-3CD1DE189F42, OS:16.4, name:iPad Pro (12.9-inch) (6th generation) }
[14:53:40]: ▸ { platform:iOS Simulator, id:A2DDDDAD-8512-4152-8A6D-039D2D8B4D4B, OS:16.4, name:iPad mini (6th generation) }
[14:53:40]: ▸ { platform:iOS Simulator, id:2ABEB141-883B-4A44-89B6-D1799421D46E, OS:16.4, name:iPhone 14 }
[14:53:40]: ▸ { platform:iOS Simulator, id:420ECB26-D59E-4881-8153-FDF2A11976C1, OS:16.4, name:iPhone 14 Plus }
[14:53:40]: ▸ { platform:iOS Simulator, id:C633B788-70BB-49D8-B454-24B501FCFD41, OS:16.4, name:iPhone 14 Pro }
[14:53:40]: ▸ { platform:iOS Simulator, id:40962FE3-A17B-4E66-A426-A00C759B5198, OS:16.4, name:iPhone 14 Pro Max }
[14:53:40]: ▸ { platform:iOS Simulator, id:2C265EE3-6572-458F-BBD3-98C0285658B0, OS:16.4, name:iPhone SE (3rd generation) }

However, it correctly selects the device I chose (iPhone 14 Pro), C633B788-70BB-49D8-B454-24B501FCFD41 🤔

Can you check what is the output xcodebuild command that fastlane logs in your Terminal after you run your …fastlane scan… command? 🙏

Mine looks like this:

xcodebuild -workspace redacted.xcworkspace -scheme redacted -derivedDataPath /Users/redacted/Library/Developer/Xcode/DerivedData/redacted-csqhgnllwxkxbjaimhoulguqkjvn -destination 'platform=iOS Simulator,id=C633B788-70BB-49D8-B454-24B501FCFD41,arch=x86_64' clean test | tee '/Users/redacted/Library/Logs/scan/redacted-redacted.log' | xcbeautify

@nevil
Copy link
Author

nevil commented May 23, 2023

@rogerluan

Thanks for taking time to check 🙇

The issue I'm seeing isn't really fastlane scan's fault as the same happens when invoking xcodebuild directly.
I just feel like there will be a lot of confusion when people try to use --run_rosetta_simulator and it doesn't work the way they expect...

This is my test case:

import XCTest
@testable import RosettaTest

final class RosettaTestTests: XCTestCase {

    func testIOSVersion() {
        if #available(iOS 16, *) {
            // The iPhone 12 simulator is iOS 15.5 so this should not fail
            XCTFail("iOS 16")
        }
    }
}

Output from xcodebuild -workspace RosettaTest.xcworkspace -scheme RosettaTest -showdestinations

$ xcodebuild -workspace RosettaTest.xcworkspace -scheme RosettaTest -showdestinations
2023-05-23 15:01:06.607 xcodebuild[37640:2297730] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
Command line invocation:
    /Applications/Xcode-14.3.1.app/Contents/Developer/usr/bin/xcodebuild -workspace RosettaTest.xcworkspace -scheme RosettaTest -showdestinations

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES



	Available destinations for the "RosettaTest" scheme:
		{ platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00006000-001871841AE2801E }
		{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }
		{ platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }
		{ platform:iOS, id:d4fc2c1b042083c6e239e63f3ca140dba5d8910a, name:iPad Air2 SB }
		{ platform:iOS, id:c70f4cbbce058a5a18aa65d3a1ec538fbc1385d4, name:iPhone 8 Dev }
		{ platform:iOS Simulator, id:DA521529-88CC-4C71-960C-680FB6A23AAD, OS:16.4, name:iPhone 11 }
		{ platform:iOS Simulator, id:F5E604EC-BDD1-4AF3-BC7A-46B62A758232, OS:15.5, name:iPhone 12 }

Just specifying "iPhone 12" works as expected.

bundle exec fastlane scan --clean --workspace RosettaTest.xcworkspace --scheme RosettaTest --configuration Debug --device "iPhone 12"

Full output

set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace RosettaTest.xcworkspace -scheme RosettaTest -configuration Debug -derivedDataPath /Users/redacted/Library/Developer/Xcode/DerivedData/RosettaTest-ccxdbegzmhurzmdcixjidtmlpzfe -destination 'platform=iOS Simulator,id=F5E604EC-BDD1-4AF3-BC7A-46B62A758232' clean build test | tee '/Users/redacted/Library/Logs/scan/RosettaTest-RosettaTest.log' | xcpretty  --report html --output '/Users/redacted/temp/RosettaTest/RosettaTest/test_output/report.html' --report junit --output '/Users/redacted/temp/RosettaTest/RosettaTest/test_output/report.junit' --report junit --output '/var/folders/0l/kr96lmsd1wgbnq21nftllcwh0000gr/T/junit_report20230523-37298-6sq8nd'

Test result:

+--------------------+---+
|      Test Results      |
+--------------------+---+
| Number of tests    | 1 |
| Number of failures | 0 |
+--------------------+---+

Trying Rosetta

bundle exec fastlane scan --clean --workspace RosettaTest.xcworkspace --scheme RosettaTest --configuration Debug --device "iPhone 12" --run_rosetta_simulator

Full output

set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace RosettaTest.xcworkspace -scheme RosettaTest -configuration Debug -derivedDataPath /Users/redacted/Library/Developer/Xcode/DerivedData/RosettaTest-ccxdbegzmhurzmdcixjidtmlpzfe -destination 'platform=iOS Simulator,id=F5E604EC-BDD1-4AF3-BC7A-46B62A758232,arch=x86_64' clean build test | tee '/Users/redacted/Library/Logs/scan/RosettaTest-RosettaTest.log' | xcpretty  --report html --output '/Users/redacted/temp/RosettaTest/RosettaTest/test_output/report.html' --report junit --output '/Users/redacted/temp/RosettaTest/RosettaTest/test_output/report.junit' --report junit --output '/var/folders/0l/kr96lmsd1wgbnq21nftllcwh0000gr/T/junit_report20230523-37652-gb6xke'

The generated invocation is correct (id F5E604EC-BDD1-4AF3-BC7A-46B62A758232) but the test result shows that it is running on the iOS16 simulator and not on the iOS15.5/iPhone12 simulator.

Failing tests:
	RosettaTestTests.testIOSVersion()

** TEST FAILED **
+--------------------+---+
|      Test Results      |
+--------------------+---+
| Number of tests    | 1 |
| Number of failures | 1 |
+--------------------+---+

@bartlomiejswierad-vodeno

Same happens to us. When can we expect a fix for that?

@fousa
Copy link

fousa commented May 23, 2023

I'm having the same issue, and as a result my tests fail due to the following issue:

Signing for "ModuleTests" requires a development team. Select a development team in the Signing & Capabilities editor.

It looks like the Mac Catalyst simulator is selected although the correct id is passed.

@rogerluan
Copy link
Member

rogerluan commented May 24, 2023

@nevil thanks for the detailed report 💪

@nevil @bartlomiejswierad-vodeno @fousa as far as I can tell, this looks like a bug on Xcode (xcodebuild) itself, outside of fastlane's capabilities 😢

fastlane is generating the right xcodebuild command, passing in the right arguments, the right Device ID, etc... but when xcodebuild executes it (alongside the arch arg), it causes the problems we're seeing.

Could you try passing the scan argument destination instead of device+run_rosetta_simulator? I know this is far from ideal, but it would at least work (probably). Delete device and run_rosetta_simulator and pass in a destination like platform=iOS Simulator,name=iPhone 12,arch=x86_64 or specify the OS version explicitly: platform=iOS Simulator,name=iPhone 12,OS=15.5,arch=x86_64

@bartlomiejswierad-vodeno
Copy link

bartlomiejswierad-vodeno commented May 24, 2023

@rogerluan I'd like to point out the error made in the PR.

Adding arch=x86_64 in the destination works only for xcodebuild build instruction but not for xcodebuild test. The problem with the arch for test command is that there's no simulator destination with property arch - this is only information for the compiler that this project should be built for arch x86_64-iOS Simulator - (e.g.) iPhone 14 Pro.

To resolve the issue, we can run xcodebuild test with destination as before the PR e.g. -destination 'platform=iOS Simulator,id=blahblahblah' but change the valid architecture of the project ARCHS to x86_64. Changing it in the project settings works but also we can do it by calling xcodebuild ARCHS=x86_64 test - that sets the architecture for the project.

TL;DR;
For quick solution run
xcodebuild ARCHS=x86_64 -workspace App.xcworkspace -scheme App -destination 'platform=iOS Simulator,name=iPhone 14 Pro' test

Edit:
If the command for testing doesn't work for you, probably you have set something in Architectures in Build Settings.

@nevil
Copy link
Author

nevil commented May 25, 2023

@bartlomiejswierad-vodeno
(I'm using Xcode 14.3.1)

Actually using ARCHS=x86_64 also doesn't work for me.
My sample project does not have any custom settings for Architectures. It's the default $(ARCHS_STANDARD).

xcodebuild ARCHS=x86_64 -workspace RosettaTest.xcworkspace -scheme RosettaTest -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 12' test
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00006000-001871841AE2801E }
{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }
{ platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }
{ platform:iOS, id:d4fc2c1b042083c6e239e63f3ca140dba5d8910a, name:iPad Air2 SB }
{ platform:iOS, id:c70f4cbbce058a5a18aa65d3a1ec538fbc1385d4, name:iPhone 8 Dev }
{ platform:iOS Simulator, id:DA521529-88CC-4C71-960C-680FB6A23AAD, OS:16.4, name:iPhone 11 }
{ platform:iOS Simulator, id:DA521529-88CC-4C71-960C-680FB6A23AAD, OS:16.4, name:iPhone 11 }
{ platform:iOS Simulator, id:F5E604EC-BDD1-4AF3-BC7A-46B62A758232, OS:15.5, name:iPhone 12 }
{ platform:iOS Simulator, id:F5E604EC-BDD1-4AF3-BC7A-46B62A758232, OS:15.5, name:iPhone 12 }
Prepare packages

Computing target dependency graph and provisioning inputs

Create build description

note: Building targets in dependency order
warning: None of the architectures in ARCHS (x86_64) are valid. Consider setting ARCHS to $(ARCHS_STANDARD) or updating it to include at least one value from VALID_ARCHS (arm64, arm64e, armv7, armv7s). (in target 'Pods-RosettaTest' from project 'Pods')
/Users/redacted/temp/RosettaTest/RosettaTest/RosettaTest.xcodeproj: error: Provisioning profile "iOS Team Provisioning Profile: *" doesn't include the currently selected device "redacted-m1-Pro" (identifier 00006000-001871841AE2801E). (in target 'RosettaTest' from project 'RosettaTest')
warning: None of the architectures in ARCHS (x86_64) are valid. Consider setting ARCHS to $(ARCHS_STANDARD) or updating it to include at least one value from VALID_ARCHS (arm64, arm64e, armv7, armv7s). (in target 'RosettaTest' from project 'RosettaTest')
warning: None of the architectures in ARCHS (x86_64) are valid. Consider setting ARCHS to $(ARCHS_STANDARD) or updating it to include at least one value from VALID_ARCHS (arm64, arm64e, armv7, armv7s). (in target 'Pods-RosettaTestTests' from project 'Pods')
warning: None of the architectures in ARCHS (x86_64) are valid. Consider setting ARCHS to $(ARCHS_STANDARD) or updating it to include at least one value from VALID_ARCHS (arm64, arm64e, armv7, armv7s). (in target 'RosettaTestTests' from project 'RosettaTest')

Test session results, code coverage, and logs:
	/Users/redacted/Library/Developer/Xcode/DerivedData/RosettaTest-ccxdbegzmhurzmdcixjidtmlpzfe/Logs/Test/Test-RosettaTest-2023.05.25_10-04-11-+0900.xcresult

Testing failed:
	Provisioning profile "iOS Team Provisioning Profile: *" doesn't include the currently selected device "redacted-m1-Pro" (identifier 00006000-001871841AE2801E).
	Testing cancelled because the build failed.

** TEST FAILED **

@rogerluan
Copy link
Member

Hey @bartlomiejswierad-vodeno, I appreciate the input, and although your rationale made sense to me, my tests work just fine 😬 ? Initially I thought you were right because I didn't experiment with skip_build:true, but even passing skip_build:true (which generates an xcodebuild command that has just test, no build), it still works fine for me. This is the generated command:

set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace redacted.xcworkspace -scheme redacted -derivedDataPath /Users/redacted/Library/Developer/Xcode/DerivedData/redacted-csqhgnllwxkxbjaimhoulguqkjvn -disableAutomaticPackageResolution -destination 'platform=iOS Simulator,id=C633B788-70BB-49D8-B454-24B501FCFD41,arch=x86_64' test

And tests run just fine, under the expected simulator. Also, the logs confirm that the app is in fact not being compiled.

@nevil
Copy link
Author

nevil commented May 25, 2023

@rogerluan
Do you have time to test with this project?

https://github.com/nevil/RosettaTest

It only has one unit test which I expect won't fail as I always specify to run on an iOS 15.5 simulator.
But it fails as an iOS16 simulator earlier in the list of destinations is always selected. (or macOS ...)

    func testIOSVersion() {
        if #available(iOS 16, *) {
            // The iPhone 12 simulator is iOS 15.5 so this should not fail
            XCTFail("iOS 16")
        }
    }

@rogerluan
Copy link
Member

I have tested your sample code and I get the same issue you're seeing: the first simulator is used. In my case specifically, though, the first simulator happens to be an iPad on iOS 15.5, so the test pass, but it's by mere luck. Also, I isolated this issue outside of fastlane, to show it's related to xcodebuild:

See last line of the log:

image

Also, I tested my suggestion here about using e.g. -destination 'platform=iOS Simulator,device=iPhone SE (3rd generation),OS=15.5,arch=x86_64' instead, but that didn't help either:

image

@rogerluan
Copy link
Member

Perhaps @bartlomiejswierad-vodeno can help us solve this? It seems like you have deeper knowledge around what's going on here 🙇

@bartlomiejswierad-vodeno
Copy link

bartlomiejswierad-vodeno commented May 25, 2023

@rogerluan Well, I fixed it locally by setting Architectures in the project setting to x86_64 for iOS Simulator. It works for my project.

Also, I just spent whole day on it yesterday, so I just tried everything to make it work because deadline for us to migrate CI build to M1 is close.

@nevil If you sent the logs from the demo project you created, then it work for me. I even added some validation code to be 100% sure. This would not compile for other architecture.

#if arch(x86_64) || !targetEnvironment(simulator)
    #warning("This is good")
#else
    #error("Not valid arch")
#endif

Also I realized that picking destination by name and OS doesn't work as expected. But when I picked it by id it worked well. (that is what fastlane does)

Command (I don't have iPhone 12 configured, so I used 13 on purpose):

>  xcodebuild ARCHS=x86_64 -workspace RosettaTest.xcworkspace -scheme RosettaTest -destination 'platform=iOS Simulator,id=9BFDD8E5-C0D2-4884-AC09-897EA9AD125F' test

2023-05-25 08:09:56.209 xcodebuild[78441:22582151] DVTCoreDeviceEnabledState: DVTCoreDeviceEnabledState_Disabled set via user default (DVTEnableCoreDevice=disabled)
Command line invocation:
    /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild ARCHS=x86_64 -workspace RosettaTest.xcworkspace -scheme RosettaTest -destination "platform=iOS Simulator,id=9BFDD8E5-C0D2-4884-AC09-897EA9AD125F" test

User defaults from command line:
    IDEPackageSupportUseBuiltinSCM = YES

Build settings from command line:
    ARCHS = x86_64

--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:iOS Simulator, id:9BFDD8E5-C0D2-4884-AC09-897EA9AD125F, OS:15.5, name:iPhone 13 }
{ platform:iOS Simulator, id:9BFDD8E5-C0D2-4884-AC09-897EA9AD125F, OS:15.5, name:iPhone 13 }
Prepare packages

@nevil
Copy link
Author

nevil commented May 25, 2023

@bartlomiejswierad-vodeno

Also I realized that picking destination by name and OS doesn't work as expected. But when I picked it by id it worked well. (that is what fastlane does)

Thanks for the insights.
I hadn't realized that destination selection works if you only pass the ID.

In our projects we will always run unit tests only in an x86 simulator (looking at you Google Chromecast SDK) so we can just change our project to use:

ARCHS[sdk=iphonesimulator*] = x86_64

Not sure what to do for projects that need to support both arm and x86_64...

Anyway, I think that --run_rosetta_simulator does not work as intended and will be confusing to the users...
Because even though I hardcode the project to ARCHS[sdk=iphonesimulator*] = x86_64 as soon as you invoke fastlane scan with --run_rosetta_simulator the destination selection stops working...

@rogerluan
Copy link
Member

But when I picked it by id it worked well. (that is what fastlane does)

Yes, fastlane does this, but if you observe in the 1st screenshot I posted here, the selection is done via ID (as fastlane does), and it still does not work as expected: see the last line of the screenshot, where it says the simulator that was used to run the tests was an iPad, even though the ID I passed to xcodebuildbelongs to an iPhone SE (3rd generation) with OS 16.4.

Notice how I completely removed fastlane out of the equation 🤔 neither of the screenshots I posted have anything to do with fastlane, it's just purely an issue on xcodebuild itself 😬

@nevil
Copy link
Author

nevil commented May 26, 2023

@rogerluan
In your first screenshot the specified destination is -destination 'platform=iOS Simulator, id=2C265EE3-6572-458F-BBD3-98C0285658B0,arch=x86_64'.

If you remove the arch=x86_64. I think it works.

So what i did (as @bartlomiejswierad-vodeno pointed out) was to to change the Architectures in the project to have ARCHS[sdk=iphonesimulator*] = x86_64 and then invoke fastlane without --run_rosetta_simulator.

(or xcodebuild by specifying only id : -destination 'platform=iOS Simulator,id=2C265EE3-6572-458F-BBD3-98C0285658B0')


I noticed that 2.213.0 is now released...

@rogerluan
Copy link
Member

That's also a valid solution @nevil

@nevil
Copy link
Author

nevil commented May 30, 2023

I'm not sure what to do with this issue.
I think we have shown that the current behavior of --run_rosetta_simulator is confusing and maybe not what users would expect.

But if --run_rosetta_simulator doesn't promise to actually select the specified device then there is no issue :-)

And yes, the root issue is that xcodebuild don't have a "flag" for doing what --run_rosetta_simulator is trying to do...

@canhth
Copy link

canhth commented May 30, 2023

I'm having the same issue, and as a result my tests fail due to the following issue:

Signing for "ModuleTests" requires a development team. Select a development team in the Signing & Capabilities editor.

It looks like the Mac Catalyst simulator is selected although the correct id is passed.

Getting the same issue, hope we can have a solution for this soon.

@Kirikami
Copy link

Same issue with picking the wrong simulator even with the correct id. If it's not an issue with fastlane, do we have any issue opened for xcodebuild?

@rogerluan
Copy link
Member

@Kirikami xcodebuild is Xcode's CLI, thus owned by Apple, closed source. There's no public issue-tracking system for Xcode or xcodebuild, but anyone can open a radar with Apple directly

@rogerluan
Copy link
Member

@nevil not sure there's anything to be done, honestly. Perhaps it would make more sense, semantically, to name the fastlane flag something like "run_on_x86", because that is exactly what it does under the hood. And if when running under x86 xcodebuild doesn't work as expected, then that's an issue on xcodebuild and not fastlane (which is also what's happening). However, for the average joe, they'll be looking for "rosetta" in the API, docs, man, help menu, etc, and not "x86" 🤷‍♂️ so there's pros/cons to both options.

@nevil
Copy link
Author

nevil commented May 31, 2023

Same issue with picking the wrong simulator even with the correct id. If it's not an issue with fastlane, do we have any issue opened for xcodebuild?

I opened FB12195073 on May 20 but don't really expect to get any answers.

Maybe someone will have some luck in a WWDC lab or something.

@tonyxkendo
Copy link

tonyxkendo commented Oct 22, 2023

for me i have to remove mac support destination that automatically add when create framework
Screenshot 2023-10-22 at 11 12 20
and remove destination or device on fastfile

This is the part of result when scan is generate
set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace MyApp.xcworkspace -scheme MyScheme -sdk 'iphonesimulator' -destination 'platform=iOS Simulator,id=1364C4E1-2A29-49EA-B4E9-6C7E64C520A8,arch=x86_64'

it will automatically select simulator include x86_64 that added from param run_rosetta_simulator: true in fastfile

You can check how run_rosetta_simulator work at
scan -> lib -> scan -> detect_value.rb

        arch = ""
        if Scan.config[:run_rosetta_simulator]
          arch = ",arch=x86_64"
        end

        Scan.config[:destination] = Scan.devices.map { |d| "platform=#{d.os_type} Simulator,id=#{d.udid}" + arch }

@asendra
Copy link

asendra commented Dec 21, 2023

For us, the simplest solution seems to be to add ARCH=x86_64 in the xcargs field.

run_tests(
    ...
    device: "iPhone 15",
    xcargs: 'ARCHS=x86_64',
    ...
)

@rogerluan
Copy link
Member

I still couldn't reproduce the OP's issue locally, has anyone been able to? If so, could you perhaps provide steps to reproduce and maybe include a demo project?

I think there may be different solutions to the problem but without a way of verifying them, it's hard for me to work on this 😬

@abesmon
Copy link

abesmon commented Feb 28, 2024

Same problem here,

xcargs: 'ARCHS=x86_64' and removing runRosettaSimulator helps, but still console outputs

▸ --- xcodebuild: WARNING: Using the first of multiple matching destinations:
▸ { platform:iOS Simulator, id:3D6C0509-DEA9-41C8-B071-2C20014AD692, OS:17.0, name:iPhone 15 }
▸ { platform:iOS Simulator, id:3D6C0509-DEA9-41C8-B071-2C20014AD692, OS:17.0, name:iPhone 15 }

which I found strange =/


also, idk if it relates, but reinstallApp argument do nothing:
I see

 xcrun simctl uninstall 3D6C0509-DEA9-41C8-B071-2C20014AD692 {secret_bundle_id} &> /dev/null

in console, but it does nothing

@jaysoffian
Copy link
Contributor

jaysoffian commented Mar 13, 2024

The arch keyword seems to only work with macOS simulators. It seems it was originally intended for i386 vs x86_64. References:

As discovered in this thread, adding arch=x86_64 causes xcodebuild to treat the destination as invalid and fallback to using whatever simulator device it thinks is best. e.g. with SCAN_DESTINATION='platform=iOS Simulator,OS=17.2,name=iPhone 14:17.2,arch=x86_64':

▸ --- xcodebuild: WARNING: Using the first of multiple matching destinations:
▸ { platform:iOS Simulator, id:47D5435D-AC2E-486A-A7EE-9B8260692A3B, OS:17.4, name:iPad Pro (12.9-inch) (6th generation) }
▸ { platform:iOS Simulator, id:10390B45-7176-4903-947B-63474C184781, OS:17.2, name:iPhone 14:17.2 }
▸ { platform:iOS Simulator, id:6AE52D7F-E0E0-4A1C-824F-7A073E502310, OS:17.4, name:iPhone 15 Pro }

Same issue occurs when we allow scan to specify the destination by id. Adding the arch qualifier causes xcodebuild to ignore the destination and pick its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests