Class: Commands::XcodeBuild
- Inherits:
-
Object
- Object
- Commands::XcodeBuild
- Defined in:
- lib/commands/xcode_build.rb
Instance Method Summary collapse
- #builddistribution(target_file, build_dir, artwork, exportName, deliverablesPath, appicon) ⇒ Object
-
#do_build(build, deliverablesPath, archive_build, copy_appicon) ⇒ 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.
-
#options ⇒ Object
holds the options that were passed you can set any initial defaults here.
- #register(opts, global_options) ⇒ Object
-
#required_options ⇒ Object
required options.
- #run(global_options) ⇒ Object
Instance Method Details
#builddistribution(target_file, build_dir, artwork, exportName, deliverablesPath, appicon) ⇒ Object
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 51 def builddistribution(target_file, build_dir, artwork, exportName, deliverablesPath, appicon) 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" if (!artwork.nil?) then if (appicon == true and File.exist?("#{artwork}")) then cmd = "cp '#{artwork}' #{build_dir}/tmp/" EcbSharedLib::CL.do_cmd(cmd, '.') paths = artwork.split("/") cmd = "mv 'tmp/#{paths.last}' tmp/iTunesArtwork" EcbSharedLib::CL.do_cmd(cmd, "#{build_dir}") end end #cmd = "ditto -c -k --norsrc #{build_dir}/tmp/Payload \"#{deliverablesPath}/#{exportName}\"" cmd = "ditto -c -k --norsrc #{build_dir}/tmp \"#{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, copy_appicon) ⇒ 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
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 114 115 116 117 118 119 120 121 122 |
# File 'lib/commands/xcode_build.rb', line 78 def do_build(build, deliverablesPath, archive_build, copy_appicon) 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}") export_name = exportName.split(".").first sym_file = "#{export_name}_dSYM.zip" cmd = "ditto -c -k --norsrc --keepParent '#{build_dir}/#{target_file}.dSYM' '#{deliverablesPath}/#{sym_file}'"; EcbSharedLib::CL.do_cmd(cmd, '.') if (copy_appicon == true and File.exist?("#{itunes_artwork}")) then cmd = "mv #{deliverablesPath}/#{export_name}.ipa #{deliverablesPath}/#{export_name}.zip" EcbSharedLib::CL.do_cmd(cmd, ".") cmd = "unzip #{deliverablesPath}/#{export_name}.zip -d #{deliverablesPath}/#{export_name}" EcbSharedLib::CL.do_cmd(cmd, '.') cmd = "cp '#{itunes_artwork}' #{deliverablesPath}/#{export_name}/iTunesArtwork" EcbSharedLib::CL.do_cmd(cmd, '.') cmd = " ditto -c -k --norsrc #{deliverablesPath}/#{export_name} #{deliverablesPath}/#{export_name}.ipa" EcbSharedLib::CL.do_cmd(cmd, '.') end else builddistribution(target_file, build_dir, itunes_artwork, exportName, deliverablesPath, copy_appicon) end end |
#options ⇒ Object
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 ||= { } 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 47 48 49 |
# File 'lib/commands/xcode_build.rb', line 26 def register(opts, ) opts. = "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| [:config] = v end opts.on('-d', "--deliverables deliverablesPath", "Path to build the deliverables") do |v| [:deliverables] = v end opts.on('-a', "--archive-build", "Do archive build") do |v| [:archive_build] = true end opts.on('-b', "--branch config branch name", "Use build config branch") do |v| [:branch] = v end opts.on('-i', "--copy-appicon", "copy icons for iTunesArtWork") do |v| [:copy_appicon] = true end end |
#required_options ⇒ Object
required options
19 20 21 22 23 24 |
# File 'lib/commands/xcode_build.rb', line 19 def @required_options ||= Set.new [ :config, :deliverables, ] end |
#run(global_options) ⇒ Object
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/commands/xcode_build.rb', line 124 def run() # see if we can open the config file - we append the .config suffix # the file is expected to be in JSON format config_name = [:config] config_branch = [:branch] config_branch = 'master' if config_branch.nil? || config_branch.empty? deliverablesPath = [:deliverables] archive_build = [:archive_build] copy_appicon = [:copy_appicon] 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, copy_appicon) cmd = "git checkout ." EcbSharedLib::CL.do_cmd(cmd, '.') end end |