Class: Commands::XcodeBuild

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

Instance Method Summary collapse

Instance Method Details

#builddistribtion(target_file, build_dir, artwork, exportName, deliverablesPath) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/commands/xcode_build.rb', line 48

def builddistribtion(target_file, build_dir, artwork, exportName, deliverablesPath)
  cmd = "mkdir -p tmp/Payload"
  EcbSharedLib::CL.do_cmd(cmd, "#{build_dir}")
  cmd =  "cp -Rp '#{target_file}' tmp/Payload"
  EcbSharedLib::CL.do_cmd(cmd, "#{build_dir}")
  export_name = exportName.split(".").first
  sym_file = "#{export_name}_dSYM.zip"
  unless "#{artwork}".nil?
    if (File.exist?("#{artwork}"))
      cmd =  "cp '#{artwork}' #{build_dir}/tmp/Payload"
      EcbSharedLib::CL.do_cmd(cmd, '.')
      paths = artwork.split("/") 
      cmd =  "mv 'tmp/PayLoad/#{paths.last}' tmp/Payload/iTunesArtwork"
      EcbSharedLib::CL.do_cmd(cmd, "#{build_dir}")
    end
  end
  cmd =  "ditto -c -k --norsrc #{build_dir}/tmp/Payload \"#{deliverablesPath}/#{exportName}\""
  EcbSharedLib::CL.do_cmd(cmd, '.')
  cmd =  "ditto -c -k --norsrc --keepParent '#{build_dir}/#{target_file}.dSYM' '#{deliverablesPath}/#{sym_file}'";
  EcbSharedLib::CL.do_cmd(cmd, '.')
end

#do_build(build, deliverablesPath, archive_build) ⇒ 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



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
# File 'lib/commands/xcode_build.rb', line 74

def do_build(build, deliverablesPath, archive_build)
 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]
 build_dir = build[:build_dir]
 itunes_artwork = build[:itunes_artwork]
 target_file = build[:target_file]
 
 archive = archive_build ? 'archive' : ''
 
 cmd = "xcodebuild #{archive} -workspace #{workspace} -scheme #{scheme} -xcconfig '#{xcconfig}' -configuration #{configuration} -archivePath '#{deliverablesPath}/#{archiveName}' #{extra_configs}"
 if EcbSharedLib::CL.do_cmd_result(cmd, '.') != 0
   raise "Xcode Build failed."
 end
 if archive_build then
   cmd = "xcodebuild -exportArchive -exportFormat IPA -archivePath '#{deliverablesPath}/#{archiveName}' -exportPath '#{deliverablesPath}/#{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, "#{deliverablesPath}")
 else
   builddistribtion(target_file, build_dir, itunes_artwork, exportName, deliverablesPath)
 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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/commands/xcode_build.rb', line 26

def register(opts, global_options)
  opts.banner = "Usage: xcode_build [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('-d', "--deliverables deliverablesPath", "Path to build the deliverables") do |v|
    options[:deliverables] = v
  end
  
  opts.on('-a', "--archive-build", "Do archive build") do |v|
    options[:archive_build] = true
  end
  
  opts.on('-b', "--branch config branch name", "Use build config branch") do |v|
    options[:branch] = v
  end
  
end

#required_optionsObject

required options



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

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

#run(global_options) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/commands/xcode_build.rb', line 105

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]
   #config_branch = options[:branch]
   config_branch = options[:branch].nil? ? "master" : options[:branch]
   deliverablesPath = options[:deliverables]
   archive_build = options[:archive_build]
   
   config_repo_url = EcbSharedLib.prepare_config_repo(config_branch)
   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, '.')
 
   cmd = "rm -Rf #{deliverablesPath}"
   EcbSharedLib::CL.do_cmd(cmd, '.')
         
   xcode_version = info[:xcode_version].nil? ? "" : info[:xcode_version]
   unless File.exists?("/Applications/Xcode#{xcode_version}.app")
     cmd = "sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer"
   else
     cmd = "sudo xcode-select --switch /Applications/Xcode#{xcode_version}.app/Contents/Developer"
   end
   EcbSharedLib::CL.do_cmd(cmd, '.')

   builds = info[:builds]
   builds.each do |build|
     info_plist = info[:info_plist]
     enterprise_info_plist = info[:enterprise_info_plist]
     if build[:build_type] == "enterprise" && 
       !info_plist.nil? && !enterprise_info_plist.nil? then
       cmd = "rm #{info_plist}"
       EcbSharedLib::CL.do_cmd(cmd, '.')
       cmd = "cp #{enterprise_info_plist} #{info_plist}"
       EcbSharedLib::CL.do_cmd(cmd, '.')
     end
     do_build(build, deliverablesPath, archive_build)
     cmd = "git checkout ."
     EcbSharedLib::CL.do_cmd(cmd, '.')
   end
end