Class: Snapshot::TestCommandGeneratorXcode8

Inherits:
TestCommandGeneratorBase show all
Defined in:
snapshot/lib/snapshot/test_command_generator_xcode_8.rb

Overview

Responsible for building the fully working xcodebuild command This TestCommandGenerator supports Xcode 8's `xcodebuild` requirements It is its own object, as the logic differs for how we want to handle creating `xcodebuild` commands for Xcode 9 (see test_command_generator.rb)

Class Method Summary collapse

Methods inherited from TestCommandGeneratorBase

actions, build_settings, derived_data_path, device_udid, find_device, initialize, options, prefix, project_path_array, resolve_result_bundle_path, suffix

Class Method Details

.destination(device_name) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'snapshot/lib/snapshot/test_command_generator_xcode_8.rb', line 30

def destination(device_name)
  # on Mac we will always run on host machine, so should specify only platform
  return ["-destination 'platform=macOS'"] if device_name =~ /^Mac/

  # if device_name is nil, use the config and get all devices
  os = device_name =~ /^Apple TV/ ? "tvOS" : "iOS"
  os_version = Snapshot.config[:ios_version] || Snapshot::LatestOsVersion.version(os)

  device = find_device(device_name, os_version)
  if device.nil?
    UI.user_error!("No device found named '#{device_name}' for version '#{os_version}'")
  elsif device.os_version != os_version
    UI.important("Using device named '#{device_name}' with version '#{device.os_version}' because no match was found for version '#{os_version}'")
  end
  value = "platform=#{os} Simulator,id=#{device.udid},OS=#{device.os_version}"

  return ["-destination '#{value}'"]
end

.generate(device_type: nil, language: nil, locale: nil) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
# File 'snapshot/lib/snapshot/test_command_generator_xcode_8.rb', line 12

def generate(device_type: nil, language: nil, locale: nil)
  parts = prefix
  parts << "xcodebuild"
  parts += options(language, locale)
  parts += destination(device_type)
  parts += build_settings
  parts += actions
  parts += suffix
  parts += pipe(device_type, language, locale)

  return parts
end

.pipe(device_type, language, locale) ⇒ Object


25
26
27
28
# File 'snapshot/lib/snapshot/test_command_generator_xcode_8.rb', line 25

def pipe(device_type, language, locale)
  log_path = xcodebuild_log_path(device_type: device_type, language: language, locale: locale)
  return ["| tee #{log_path.shellescape} | xcpretty #{Snapshot.config[:xcpretty_args]}"]
end

.xcodebuild_log_path(device_type: nil, language: nil, locale: nil) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'snapshot/lib/snapshot/test_command_generator_xcode_8.rb', line 49

def xcodebuild_log_path(device_type: nil, language: nil, locale: nil)
  name_components = [Snapshot.project.app_name, Snapshot.config[:scheme]]

  if Snapshot.config[:namespace_log_files]
    name_components << device_type if device_type
    name_components << language if language
    name_components << locale if locale
  end

  file_name = "#{name_components.join('-')}.log"

  containing = File.expand_path(Snapshot.config[:buildlog_path])
  FileUtils.mkdir_p(containing)

  return File.join(containing, file_name)
end