Class: RunLoop::Xcode

Inherits:
Object
  • Object
show all
Includes:
Shell
Defined in:
lib/run_loop/xcode.rb

Overview

Note:

All command line tools are run in the context of ‘xcrun`.

A model of the active Xcode version.

Throughout this class’s documentation, there are references to the _active version of Xcode_. The active Xcode version is the one returned by ‘xcrun xcodebuild`. The current Xcode version can be set using `xcode-select` or overridden using the `DEVELOPER_DIR`.

Constant Summary

Constants included from Shell

Shell::DEFAULT_OPTIONS

Instance Method Summary collapse

Methods included from Shell

run_shell_command, #run_shell_command

Methods included from Encoding

#transliterate

Instance Method Details

#beta?Boolean

Note:

Relies on Xcode beta versions having and app bundle named Xcode-Beta.app

Is this a beta version of Xcode?

Returns:

  • (Boolean)

    True if the Xcode version is beta.



275
276
277
# File 'lib/run_loop/xcode.rb', line 275

def beta?
  developer_dir[/Xcode-[Bb]eta.app/, 0]
end

#core_simulator_dirObject



332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/run_loop/xcode.rb', line 332

def core_simulator_dir
  if version_gte_110?
    core_simulator_dir = File.join(developer_dir,
                                  'Platforms', 'iPhoneOS.platform', 'Library',
                                  'Developer', 'CoreSimulator')
  else
    core_simulator_dir = File.join(developer_dir,
                                  'Platforms', 'iPhoneOS.platform', 'Developer',
                                  'Library', 'CoreSimulator')
  end
  File.expand_path(core_simulator_dir)
end

#default_deviceObject



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/run_loop/xcode.rb', line 359

def default_device
  xcode_version = version

  # Xcode 13.
  if xcode_version.major == 13
    return "iPhone 13"
  end

  # Xcode 12.
  if xcode_version.major == 12 && xcode_version.minor >= 2
    return "iPhone 12"
  elsif xcode_version.major == 12 && xcode_version.minor < 2
    return "iPhone 11"
  end

  # Xcode 11.
  if xcode_version.major == 11
    return "iPhone 11"
  end

  # Xcode 10.
  if xcode_version.major == 10
    if xcode_version.minor >= 2
      return "iPhone Xs"
    else
      return "iPhone XS"
    end
  end

  # Xcode < 10.
  return "iPhone #{xcode_version.major - 1}"
end

#developer_dirString

Returns the path to the current developer directory.

From the man pages:

“‘ $ man xcode-select DEVELOPER_DIR Overrides the active developer directory. When DEVELOPER_DIR is set, its value will be used instead of the system-wide active developer directory. “`

Returns:

  • (String)

    path to current developer directory

Raises:

  • (RuntimeError)

    If path to Xcode.app/Contents/Developer cannot be determined.



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/run_loop/xcode.rb', line 295

def developer_dir
  @xcode_developer_dir ||= begin
    if RunLoop::Environment.developer_dir
      path = RunLoop::Environment.developer_dir
    else
      path = xcode_select_path
    end

    require 'pathname'
    path = Pathname.new(path).realpath.to_s

    if !File.directory?(path)
      raise RuntimeError,
%Q{Cannot determine the active Xcode.  Expected an Xcode here:

#{path}

Check the value of xcode-select:

# Does this resolve to a valid Xcode.app/Contents/Developer path?
$ xcode-select --print-path

Is the DEVELOPER_DIR variable set in your environment?  You would
only use this if you have multiple Xcode's installed.

$ echo $DEVELOPER_DIR

See the man pages for xcrun and xcode-select for details.

$ man xcrun
$ man xcode-select
}
    end
    path
  end
end

#inspectObject

Returns debug String representation



25
26
27
# File 'lib/run_loop/xcode.rb', line 25

def inspect
  to_s
end

#ios_versionObject



345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/run_loop/xcode.rb', line 345

def ios_version
  xcode_version = version
  sim_major = xcode_version.major + 2
  sim_minor = xcode_version.minor
  if xcode_version.major == 13
    sim_minor = 0
  end
  if xcode_version == v103
    sim_minor = 4
  end

  return RunLoop::Version.new("#{sim_major}.#{sim_minor}")
end

#to_sObject

Returns a String representation.



20
21
22
# File 'lib/run_loop/xcode.rb', line 20

def to_s
  "#<Xcode #{version.to_s}>"
end

#v100RunLoop::Version

Returns a version instance for Xcode 10.0; used to check for the availability of features and paths to various items on the filesystem

Returns:



65
66
67
# File 'lib/run_loop/xcode.rb', line 65

def v100
  fetch_version(:v100)
end

#v102RunLoop::Version

Returns a version instance for Xcode 10.2; used to check for the availability of features and paths to various items on the filesystem

Returns:



57
58
59
# File 'lib/run_loop/xcode.rb', line 57

def v102
  fetch_version(:v102)
end

#v103RunLoop::Version

availability of features and paths to various items on the filesystem

Returns:



49
50
51
# File 'lib/run_loop/xcode.rb', line 49

def v103
  fetch_version(:v103)
end

#v110RunLoop::Version

Returns a version instance for Xcode 11.0; used to check for the availability of features and paths to various items on the filesystem

Returns:



41
42
43
# File 'lib/run_loop/xcode.rb', line 41

def v110
  fetch_version(:v110)
end

#v120RunLoop::Version

Returns a version instance for Xcode 12.0; used to check for the availability of features and paths to various items on the filesystem

Returns:



33
34
35
# File 'lib/run_loop/xcode.rb', line 33

def v120
  fetch_version(:v120)
end

#v80RunLoop::Version

Returns a version instance for ‘Xcode 8.0`; used to check for the availability of features and paths to various items on the filesystem.

Returns:



137
138
139
# File 'lib/run_loop/xcode.rb', line 137

def v80
  fetch_version(:v80)
end

#v81RunLoop::Version

Returns a version instance for ‘Xcode 8.1`; used to check for the availability of features and paths to various items on the filesystem.

Returns:



129
130
131
# File 'lib/run_loop/xcode.rb', line 129

def v81
  fetch_version(:v81)
end

#v82RunLoop::Version

Returns a version instance for Xcode 8.2; used to check for the availability of features and paths to various items on the filesystem

Returns:



121
122
123
# File 'lib/run_loop/xcode.rb', line 121

def v82
  fetch_version(:v82)
end

#v83RunLoop::Version

Returns a version instance for Xcode 8.3; used to check for the availability of features and paths to various items on the filesystem

Returns:



113
114
115
# File 'lib/run_loop/xcode.rb', line 113

def v83
  fetch_version(:v83)
end

#v90RunLoop::Version

Returns a version instance for Xcode 9.0; used to check for the availability of features and paths to various items on the filesystem

Returns:



105
106
107
# File 'lib/run_loop/xcode.rb', line 105

def v90
  fetch_version(:v90)
end

#v91RunLoop::Version

Returns a version instance for Xcode 9.1; used to check for the availability of features and paths to various items on the filesystem

Returns:



97
98
99
# File 'lib/run_loop/xcode.rb', line 97

def v91
  fetch_version(:v91)
end

#v92RunLoop::Version

Returns a version instance for Xcode 9.2; used to check for the availability of features and paths to various items on the filesystem

Returns:



89
90
91
# File 'lib/run_loop/xcode.rb', line 89

def v92
  fetch_version(:v92)
end

#v93RunLoop::Version

Returns a version instance for Xcode 9.3; used to check for the availability of features and paths to various items on the filesystem

Returns:



81
82
83
# File 'lib/run_loop/xcode.rb', line 81

def v93
  fetch_version(:v93)
end

#v94RunLoop::Version

Returns a version instance for Xcode 9.4; used to check for the availability of features and paths to various items on the filesystem

Returns:



73
74
75
# File 'lib/run_loop/xcode.rb', line 73

def v94
  fetch_version(:v94)
end

#versionRunLoop::Version

Returns the current version of Xcode.

Returns:

  • (RunLoop::Version)

    The current version of Xcode as reported by ‘xcrun xcodebuild -version`.



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/run_loop/xcode.rb', line 243

def version
  @xcode_version ||= begin
    if RunLoop::Environment.xtc?
      RunLoop::Version.new("0.0.0")
    else
      version = RunLoop::Version.new("0.0.0")
      begin
        args = ["xcrun", "xcodebuild", "-version"]
        hash = run_shell_command(args)
        if hash[:exit_status] != 0
          RunLoop.log_error("xcrun xcodebuild -version exited non-zero")
        else
          out = hash[:out]
          version_string = out.chomp[VERSION_REGEX, 0]
          version = RunLoop::Version.new(version_string)
        end
      rescue RuntimeError => e
        RunLoop.log_error(%Q[
Could not find Xcode version:

  #{e.class}: #{e.message}
])
      end
      version
    end
  end
end

#version_gte_100?Boolean

Is the active Xcode version 10.0 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 10.0



172
173
174
# File 'lib/run_loop/xcode.rb', line 172

def version_gte_100?
  version >= v100
end

#version_gte_102?Boolean

Is the active Xcode version 10.2 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 10.2



165
166
167
# File 'lib/run_loop/xcode.rb', line 165

def version_gte_102?
  version >= v102
end

#version_gte_103?Boolean

Is the active Xcode version 10.3 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 10.3



158
159
160
# File 'lib/run_loop/xcode.rb', line 158

def version_gte_103?
  version >= v103
end

#version_gte_110?Boolean

Is the active Xcode version 11.0 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 11.0



151
152
153
# File 'lib/run_loop/xcode.rb', line 151

def version_gte_110?
  version >= v110
end

#version_gte_120?Boolean

Is the active Xcode version 12.0 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 12.0



144
145
146
# File 'lib/run_loop/xcode.rb', line 144

def version_gte_120?
  version >= v120
end

#version_gte_81?Boolean

Is the active Xcode version 8.1 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 8.1



228
229
230
# File 'lib/run_loop/xcode.rb', line 228

def version_gte_81?
  version >= v81
end

#version_gte_82?Boolean

Is the active Xcode version 8.2 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 8.2



221
222
223
# File 'lib/run_loop/xcode.rb', line 221

def version_gte_82?
  version >= v82
end

#version_gte_83?Boolean

Is the active Xcode version 8.3 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 8.3



214
215
216
# File 'lib/run_loop/xcode.rb', line 214

def version_gte_83?
  version >= v83
end

#version_gte_8?Boolean

Is the active Xcode version 8.0 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 8.0



235
236
237
# File 'lib/run_loop/xcode.rb', line 235

def version_gte_8?
  version >= v80
end

#version_gte_90?Boolean

Is the active Xcode version 9.0 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 9.0



207
208
209
# File 'lib/run_loop/xcode.rb', line 207

def version_gte_90?
  version >= v90
end

#version_gte_91?Boolean

Is the active Xcode version 9.1 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 9.1



200
201
202
# File 'lib/run_loop/xcode.rb', line 200

def version_gte_91?
  version >= v91
end

#version_gte_92?Boolean

Is the active Xcode version 9.2 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 9.2



193
194
195
# File 'lib/run_loop/xcode.rb', line 193

def version_gte_92?
  version >= v92
end

#version_gte_93?Boolean

Is the active Xcode version 9.3 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 9.3



186
187
188
# File 'lib/run_loop/xcode.rb', line 186

def version_gte_93?
  version >= v93
end

#version_gte_94?Boolean

Is the active Xcode version 9.4 or above?

Returns:

  • (Boolean)

    ‘true` if the current Xcode version is >= 9.4



179
180
181
# File 'lib/run_loop/xcode.rb', line 179

def version_gte_94?
  version >= v94
end