Class: Commands::XcodeBuild

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/xcode_build.rb

Instance Method Summary collapse

Instance Method Details

#do_build(build, archivePath) ⇒ Object

prepare a single repo and create a local and tracking branch if it should have one if the repo specifies a branch then we will do the initial fetch from that branch if the create_dev_branch flag is set, we will create a local and tracking branch with the developer initials prepended



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/commands/xcode_build.rb', line 43

def do_build(build, archivePath)
 workspace = build[:workspace]
 scheme = build[:scheme]
 xcconfig = build[:xcconfig]
 archiveName = build[:archiveName]
 exportName = build[:exportName]
 configuration = build[:configuration]
 extra_configs = build[:extra_configs]
 provisioning_file = build[:provisioning_file]

 if !archivePath.empty? then
   archive = 'archive'
 else
   archive = ''
 end

 cmd = "xcodebuild #{archive} -workspace #{workspace} -scheme #{scheme} -xcconfig '#{xcconfig}' -configuration #{configuration} -derivedDataPath build -archivePath '#{archivePath}/#{archiveName}' #{extra_configs}"
 if EcbSharedLib::CL.do_cmd_result(cmd, '.') != 0
   raise "Xcode Build failed."
 end
 
 if !archivePath.empty? then
   cmd = "xcodebuild -exportArchive -exportFormat IPA -archivePath '#{archivePath}/#{archiveName}' -exportPath '#{archivePath}/#{exportName}'  -exportProvisioningProfile '#{provisioning_file}'"
   if EcbSharedLib::CL.do_cmd_result(cmd, '.') != 0
     raise "Xcode Export Archive failed."
   end
   cmd = "ditto -c -k --norsrc #{archiveName} #{archiveName}.zip"
   EcbSharedLib::CL.do_cmd(cmd, "#{archivePath}")
 end
end

#optionsObject

holds the options that were passed you can set any initial defaults here



13
14
15
16
# File 'lib/commands/xcode_build.rb', line 13

def options
  @options ||= {
  }
end

#register(opts, global_options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/commands/xcode_build.rb', line 25

def register(opts, global_options)
  opts.banner = "Usage: xcode_archive [options]"
  opts.description = "Build an Xcode deliverable from the specified config."

  opts.on('-c', "--config name", "Required - Name of the config we are building from.") do |v|
    options[:config] = v
  end

  opts.on('-a', "--archive archivePath", "Path to build the archive") do |v|
    options[:archive] = v
  end
  
end

#required_optionsObject

required options



19
20
21
22
23
# File 'lib/commands/xcode_build.rb', line 19

def required_options
  @required_options ||= Set.new [
    :config,
  ]
end

#run(global_options) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/commands/xcode_build.rb', line 74

def run(global_options)
   # see if we can open the config file - we append the .config suffix
   # the file is expected to be in JSON format
   config_name = options[:config]
   archivePath = options[:archive]

   config_repo_url = EcbSharedLib.prepare_config_repo(nil)
   info = EcbSharedLib.read_repo_config(config_repo_url, config_name)
   build_config = EcbSharedLib.read_build_config(config_repo_url)

   # Now that we have the json, prepare the world by creating a directory with the config name and placing
   # the various repos beneath that.  The directory is created relative to the current directory.
   
   cmd = "security unlock-keychain -p #{build_config[:login_password]} ~/Library/Keychains/login.keychain"
   EcbSharedLib::CL.do_cmd(cmd, '.')
 
   #/Applications/Xcode.app/Contents/Developer
   cmd = "rm -Rf build"
   EcbSharedLib::CL.do_cmd(cmd, '.')
   
   if !archivePath.empty? then
     cmd = "rm -Rf #{archivePath}"
     EcbSharedLib::CL.do_cmd(cmd, '.')
   end
   
   xcode_version = info[:xcode_version]
   if xcode_version.nil? then
     cmd = "xcode-select --switch /Applications/Xcode.app/Contents/Developer"
   else
     cmd = "xcode-select --switch /Applications/Xcode#{xcode_version}.app/Contents/Developer"
   end
   EcbSharedLib::CL.do_cmd(cmd, '.')

   builds = info[:builds]
   builds.each do |build|
     do_build(build, archivePath)
     cmd = "git checkout ."
     EcbSharedLib::CL.do_cmd(cmd, '.')
   end
end