Class: Commands::XcodeBuild

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

Instance Method Summary collapse

Instance Method Details

#builddistribution(target_file, build_dir, artwork, exportName, deliverablesPath, appicon) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/commands/xcode_build.rb', line 52

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}'";
    cmd =  "ditto -c -k --norsrc --keepParent '#{build_dir}/#{target_file}.dSYM' '#{deliverablesPath}/#{archiveName}/dSYMs/#{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



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
123
124
125
126
127
128
# File 'lib/commands/xcode_build.rb', line 80

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
        export_name = exportName.split(".").first
        sym_file = "#{export_name}_dSYM.zip"
        cmd =  "ditto -c -k --norsrc --keepParent '#{build_dir}/#{target_file}.dSYM' '#{deliverablesPath}/#{archiveName}/dSYMs/#{sym_file}'";
        EcbSharedLib::CL.do_cmd(cmd, '.')
        cmd = "ditto -c -k --norsrc #{archiveName} #{archiveName}.zip"
        EcbSharedLib::CL.do_cmd(cmd, "#{deliverablesPath}")
        
        #cmd =  "ditto -c -k --norsrc --keepParent '#{build_dir}/#{target_file}.dSYM' '#{deliverablesPath}/#{sym_file}'";
        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, '.')
            cmd = " rm -Rf #{deliverablesPath}/#{export_name}.zip"
            EcbSharedLib::CL.do_cmd(cmd, '.')
        end
        
        
        else
        builddistribution(target_file, build_dir, itunes_artwork, exportName, deliverablesPath, copy_appicon)
    end
end

#optionsObject

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



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

def options
    @options ||= {
    }
end

#register(opts, global_options) ⇒ Object



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

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
    opts.on('-i', "--copy-appicon", "copy icons for iTunesArtWork") do |v|
        options[:copy_appicon] = true
    end
    
end

#required_optionsObject

required options



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

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

#run(global_options) ⇒ Object



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
171
172
173
174
175
176
177
178
179
# File 'lib/commands/xcode_build.rb', line 130

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 = 'master' if config_branch.nil? || config_branch.empty?
    deliverablesPath = options[:deliverables]
    archive_build = options[:archive_build]
    copy_appicon = options[: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, '.')
    
    cmd = "rm -Rf ~/Library/Developer/Xcode/DerivedData/"
    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