Class: Gym::PackageCommandGeneratorXcode7

Inherits:
Object
  • Object
show all
Defined in:
gym/lib/gym/generators/package_command_generator_xcode7.rb

Overview

Responsible for building the fully working xcodebuild command

Constant Summary collapse

DEFAULT_EXPORT_METHOD =
"app-store"

Class Method Summary collapse

Class Method Details

.app_thinning_pathObject

The path to the app-thinning plist file



99
100
101
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 99

def app_thinning_path
  Gym.cache[:app_thinning] ||= File.join(temporary_output_path, "app-thinning.plist")
end

.app_thinning_size_report_pathObject

The path to the App Thinning Size Report file



104
105
106
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 104

def app_thinning_size_report_path
  Gym.cache[:app_thinning_size_report] ||= File.join(temporary_output_path, "App Thinning Size Report.txt")
end

.apps_pathObject

The path to the Apps folder



109
110
111
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 109

def apps_path
  Gym.cache[:apps_path] ||= File.join(temporary_output_path, "Apps")
end

.config_pathObject

The path the config file we use to sign our app



88
89
90
91
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 88

def config_path
  Gym.cache[:config_path] ||= "#{Tempfile.new('gym_config').path}.plist"
  return Gym.cache[:config_path]
end

.dsym_pathObject

The path the the dsym file for this app. Might be nil



83
84
85
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 83

def dsym_path
  Dir[BuildCommandGenerator.archive_path + "/**/*.app.dSYM"].last
end

.generateObject



21
22
23
24
25
26
27
28
29
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 21

def generate
  parts = ["/usr/bin/xcrun #{wrap_xcodebuild.shellescape} -exportArchive"]
  parts += options
  parts += pipe

  File.write(config_path, config_content) # overwrite everytime. Could be optimized

  parts
end

.ipa_pathObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 60

def ipa_path
  unless Gym.cache[:ipa_path]
    path = Dir[File.join(temporary_output_path, "*.ipa")].last
    # We need to process generic IPA
    if path
      # Try to find IPA file in the output directory, used when app thinning was not set
      Gym.cache[:ipa_path] = File.join(temporary_output_path, "#{Gym.config[:output_name]}.ipa")
      FileUtils.mv(path, Gym.cache[:ipa_path]) unless File.expand_path(path).casecmp(File.expand_path(Gym.cache[:ipa_path]).downcase).zero?
    elsif Dir.exist?(apps_path)
      # Try to find "generic" IPA file inside "Apps" folder, used when app thinning was set
      files = Dir[File.join(apps_path, "*.ipa")]
      # Generic IPA file doesn't have suffix so its name is the shortest
      path = files.min_by(&:length)
      Gym.cache[:ipa_path] = File.join(temporary_output_path, "#{Gym.config[:output_name]}.ipa")
      FileUtils.cp(path, Gym.cache[:ipa_path]) unless File.expand_path(path).casecmp(File.expand_path(Gym.cache[:ipa_path]).downcase).zero?
    else
      ErrorHandler.handle_empty_archive unless path
    end
  end
  Gym.cache[:ipa_path]
end

.manifest_pathObject

The path to the manifest plist file



94
95
96
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 94

def manifest_path
  Gym.cache[:manifest_path] ||= File.join(temporary_output_path, "manifest.plist")
end

.optionsObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 31

def options
  config = Gym.config

  options = []
  options << "-exportOptionsPlist '#{config_path}'"
  options << "-archivePath #{BuildCommandGenerator.archive_path.shellescape}"
  options << "-exportPath '#{temporary_output_path}'"
  options << "-toolchain '#{config[:toolchain]}'" if config[:toolchain]
  options << config[:export_xcargs] if config[:export_xcargs]
  options << config[:xcargs] if config[:xcargs]

  options
end

.pipeObject



45
46
47
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 45

def pipe
  [""]
end

.temporary_output_pathObject

We export the ipa into this directory, as we can’t specify the ipa file directly



50
51
52
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 50

def temporary_output_path
  Gym.cache[:temporary_output_path] ||= Dir.mktmpdir('gym_output')
end

.wrap_xcodebuildObject

Wrap xcodebuild to work-around ipatool dependency to system ruby



55
56
57
58
# File 'gym/lib/gym/generators/package_command_generator_xcode7.rb', line 55

def wrap_xcodebuild
  require 'fileutils'
  @wrapped_xcodebuild_path ||= File.join(Gym::ROOT, "lib/assets/wrap_xcodebuild/xcbuild-safe.sh")
end