Skip to content

--simulator with name not working as expected after updating to 0.70.1 #1707

Description

@DrChrispoper

Environment

System:
    OS: macOS 12.6
    CPU: (8) arm64 Apple M1 Pro
    Memory: 118.14 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.4.1 - ~/.nvm/versions/node/v16.13.1/bin/npm
    Watchman: 2022.02.21.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /Users/christopherhockley/.gem/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
    Android SDK:
      API Levels: 29, 30, 31, 32
      Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0, 32.0.0, 32.1.0, 33.0.0
      System Images: android-29 | Google Play ARM 64 v8a, android-32 | Google APIs ARM 64 v8a, android-33 | Google Play ARM 64 v8a
      Android NDK: Not Found
  IDEs:
    Android Studio: 2021.1 AI-211.7628.21.2111.8139111
    Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.11 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0 
    react-native: 0.70.1 => 0.70.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Description

Running react-native run-ios --simulator='iPhone 13' no longer runs on iPhone 13 but the iPhone 12 Pro (first one available)

$ bash deployment/copy-bundled-assets.sh && ENVFILE=.env.dev react-native run-ios --port=7777 --scheme "SecretSpaProApp.dev" --simulator='iPhone 13'
info Found Xcode workspace "SecretSpaProApp.xcworkspace"
info Building (using "xcodebuild -workspace SecretSpaProApp.xcworkspace -configuration Debug -scheme SecretSpaProApp.dev -destination id=2FF9B56D-3EE4-41D6-ABD7-ED0706B09938")
success Successfully built the app
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }
{ platform:iOS Simulator, id:2FF9B56D-3EE4-41D6-ABD7-ED0706B09938, OS:16.0, name:iPhone 12 Pro }
{ platform:iOS Simulator, id:6578DA40-C0B7-40C1-8557-A1E21AF20F4E, OS:16.0, name:iPhone 13 }
{ platform:iOS Simulator, id:C6CEF658-F252-44E4-B807-DD9E86571DC8, OS:16.0, name:iPhone 14 }
{ platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00006000-001239EA2121801E }
{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }
2022-10-04 10:11:02.006 xcodebuild[34333:1469186] Requested but did not find extension point with identifier Xcode.InterfaceBuilderBuildSupport.PlatformDefinition 

It is working on our previous version 0.69.1 with @react-native-community/cli@^8.0.0

Reproducible Demo

Activity

  1. alexfoxy commented on Oct 4, 2022

    @alexfoxy

    This looks like an issue related to a change in findMatchingSimulator.ts in this commit: f096553

    In the loop where it searches for a matching simulator the following was added:

    if (!!lastBootedAt && !match) {
        match = simulatorDescriptor;
    }
    

    This causes the first item in the list to always be found first, thus essentially exiting the loop.

  2. alexfoxy commented on Oct 4, 2022

    @alexfoxy

    The function should be more like:

    function findMatchingSimulator(simulators, findOptions) {
    
      if (!simulators.devices) {
        return null
      }
    
      const devices = simulators.devices
      let simulatorVersion
      let simulatorName = null
    
      if (findOptions && findOptions.simulator) {
        const parsedSimulatorName = findOptions.simulator.match(/(.*)? (?:\((\d+\.\d+)?\))$/)
    
        if (parsedSimulatorName && parsedSimulatorName[2] !== undefined) {
          simulatorVersion = parsedSimulatorName[2]
          simulatorName = parsedSimulatorName[1]
        } else {
          simulatorName = findOptions.simulator
        }
      }
    
      let match
      let defaultMatch // ADDED
    
      for (const versionDescriptor in devices) {
        const device = devices[versionDescriptor]
        let version = versionDescriptor
    
        if (/^com\.apple\.CoreSimulator\.SimRuntime\./g.test(version)) {
          // Transform "com.apple.CoreSimulator.SimRuntime.iOS-12-2" into "iOS 12.2"
          version = version.replace(/^com\.apple\.CoreSimulator\.SimRuntime\.([^-]+)-([^-]+)-([^-]+)$/g, '$1 $2.$3')
        } // Making sure the version of the simulator is an iOS or tvOS (Removes Apple Watch, etc)
    
    
        if (!version.includes('iOS') && !version.includes('tvOS')) {
          continue
        }
    
        if (simulatorVersion && !version.endsWith(simulatorVersion)) {
          continue
        }
    
        for (const i in device) {
          const simulator = device[i] // Skipping non-available simulator
    
          if (simulator.availability !== '(available)' && // @ts-ignore verify isAvailable parameter
            simulator.isAvailable !== 'YES' && simulator.isAvailable !== true) {
            continue
          }
    
          const booted = simulator.state === 'Booted'
          const lastBootedAt = simulator.lastBootedAt
          const simulatorDescriptor = {
            udid: simulator.udid,
            name: simulator.name,
            booted,
            version
          }
    
          if (findOptions && findOptions.udid) {
            if (simulator.udid === findOptions.udid) {
              return simulatorDescriptor
            }
          } else {
            if (booted && simulatorName === null) {
              return simulatorDescriptor
            }
    
            if (simulator.name === simulatorName && !match) {
              match = simulatorDescriptor 
            } // If no match found, use first available simulator that was booted before
    
    
            if (!!lastBootedAt && !match) {
              defaultMatch = simulatorDescriptor  // CHANGED
            } // Keeps track of the first available simulator for use if we can't find one above.
    
    
            if (simulatorName === null && !match) {
              match = simulatorDescriptor
            }
          }
        }
      }
    
      return match ?? defaultMatch ?? null  // ADDED
    }
    
  3. cortinico commented on Oct 14, 2022

    @cortinico
    Member

    @adamTrz can we ship a release with this change as multiple users are surfacing it:
    react/react-native#34866
    react/react-native#34912

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions