-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathpackage
More file actions
executable file
·168 lines (153 loc) · 5.78 KB
/
package
File metadata and controls
executable file
·168 lines (153 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
73
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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env ruby
#
# Copyright (c) 2012 FadingRed LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
require 'fileutils'
require 'rexml/document'
class Packager < Object
def run
puts "Building project (this may take a while)..."
File.open "greenwich.build", :mode => "w" do |output|
def execute(output, command)
IO.popen command + [:err=>[:child, :out]] do |io|
begin
while line = io.readline
output.write line
puts line if line =~ /^(Test|warning:)/
end
rescue EOFError
# finished reading
end
end
end
execute output, %w(xcodebuild) +
%w(-target) + ["Package (Simulator)"] +
%w(-sdk iphonesimulator) +
%w(-configuration Release) +
%w(-project Framework/Greenwich.xcodeproj)
raise Exception.new("Build failed") if $?.exitstatus != 0
execute output, %w(xcodebuild) +
%w(-target Package) +
%w(-configuration Release) +
%w(-project Framework/Greenwich.xcodeproj)
raise Exception.new("Build failed") if $?.exitstatus != 0
end
puts "Packaging complete."
end
def make_ios_universal
device = File.join(ENV["BUILT_PRODUCTS_DIR"] + "-iphoneos", "Greenwich.framework/Greenwich")
simulator = File.join(ENV["BUILT_PRODUCTS_DIR"] + "-iphonesimulator", "Greenwich.framework/Greenwich")
command = %w(lipo -create) + [simulator, device] + %w(-output) + [device]
raise Exception.new("Failure creating universal binary") unless system *command
end
def build
make_ios_universal
outdir = File.join ENV["PROJECT_DIR"], '..'
version = ENV["GREENWICH_VERSION"]
scripts = File.join ENV["PROJECT_DIR"], "Scripts"
readme = File.join ENV["PROJECT_DIR"], "PackageReadme.md"
license = File.join ENV["PROJECT_DIR"], "..", "License"
mac = [File.join(ENV["BUILT_PRODUCTS_DIR"], "Greenwich.framework"), scripts]
ios = [File.join(ENV["BUILT_PRODUCTS_DIR"] + "-iphoneos", "Greenwich.framework"), scripts]
tools = [File.join(ENV["BUILT_PRODUCTS_DIR"], "Greenwich Translator.app"), File.join(ENV["BUILT_PRODUCTS_DIR"], "Proofer.app")]
archive = File.join outdir, "greenwich_#{version}.tbz"
archive_dsym = File.join outdir, "greenwich_#{version}.dsym.tbz"
tools.each do |tool|
codesign tool
end
if ENV["CONFIGURATION"] == "Release"
puts "creating packages..."
Dir.chdir File.join ENV["BUILT_PRODUCTS_DIR"], ".." do
FileUtils.rm_rf "Greenwich"
FileUtils.mkdir_p "Greenwich/Tools"
FileUtils.mkdir_p "Greenwich/Mac"
FileUtils.mkdir_p "Greenwich/iOS"
mac.each { |file| system "cp", "-R", file, "Greenwich/Mac/" }
ios.each { |file| system "cp", "-R", file, "Greenwich/iOS/" }
tools.each { |file| system "cp", "-R", file, "Greenwich/Tools/" }
FileUtils.cp readme, "Greenwich/Readme"
FileUtils.cp license, "Greenwich/License"
tbz ["Greenwich"], :output => archive
end
Dir.chdir File.join ENV["BUILT_PRODUCTS_DIR"] do
tbz Dir.glob("*.dSYM"), :output => archive_dsym
end
else
puts "need to build as a release!"
exit 1
end
end
private
def zip(files, options={})
output = options[:output]
output = File.basename(files[0]) unless output
command = %w(zip -ryq) + [output] + files
raise Exception.new("Archive failure") unless system *command
end
def tbz(files, options={})
output = options[:output]
output = File.basename(files[0]) unless output
command = %w(tar cjf) + [output] + files
raise Exception.new("Archive failure") unless system *command
end
def codesign(bundle, options={})
identity = (options[:identity] or signing_identity)
identifier = signing_identifier(bundle)
puts "code signing with #{identity}: #{bundle}"
command = "/usr/bin/codesign -f -s '#{identity}' -i #{identifier} '#{bundle}'"
result = system command
unless result
puts "warning: did not code sign #{bundle} -- see above output for the reason (this may be okay)"
end
end
def signing_identity(options={})
search = []
search.push "Developer ID Application:"
identity = nil
for name in search
if `security find-certificate -c "#{name}" 2> /dev/null | grep \""labl\""` =~ /"labl"<blob>="(.*)"/
identity = $1
break
end
end
return identity
end
def signing_identifier(bundle)
identifier = nil
path = "#{bundle}/Info.plist"
path = "#{bundle}/Contents/Info.plist" unless File.exists? path
path = "#{bundle}/Resources/Info.plist" unless File.exists? path
if File.exists? path
File.open path do |file|
document = REXML::Document.new(file)
identifier = REXML::XPath.first(document, '//plist/dict/key[text() = "CFBundleIdentifier"]').next_element.text
end
else
raise "Missing bundle identifier for #{bundle}"
end
return identifier
end
end
if __FILE__ == $PROGRAM_NAME
if ARGV.length == 1 && ARGV[0] == "build"
Packager.new.build
elsif ARGV.length == 0
Packager.new.run
else
$stderr.puts "usage: package [build]"
exit 1
end
end