-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathRakefile
331 lines (279 loc) · 11.9 KB
/
Rakefile
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/usr/bin/env ruby
require 'xcodeproj'
$top_level = File.expand_path(File.dirname(__FILE__))
$macOSDeploymentTarget = "11"
$iOSDeploymentTarget = "15.0"
$demos = {
:osx => ["Glacier2/callback",
"Ice/async",
"Ice/asyncInvocation",
"Ice/bidir",
"Ice/context",
"Ice/hello",
"Ice/interceptor",
"Ice/invoke",
"Ice/latency",
"Ice/minimal",
"Ice/optional",
"Ice/throughput",
"IceDiscovery/hello",
"IceDiscovery/replication",
"IceGrid/simple",
"IceStorm/clock",
"Manual/printer",
"Manual/simpleFilesystem"],
:ios => ["IceDiscovery/helloUI",
"Ice/helloUI",
"Chat"]
}
$demo_variants = ["Client", "Server", "Publisher", "Subscriber"]
#
# Default sources for each variant
#
$demo_variant_sources = {
"Client" => ["Client/*.swift"],
"Server" => ["Server/*.swift"],
"Publisher" => ["Publisher/*.swift"],
"Subscriber" => ["Subscriber/*.swift"]
}
$demo_extra_frameworks = {
"Glacier2/callback" => ["Glacier2.xcframework"],
"IceStorm/clock" => ["IceStorm.xcframework"],
"IceGrid/simple" => ["Glacier2.xcframework", "IceGrid.xcframework"],
"Chat" => ["Glacier2.xcframework",
"MessageKit.xcframework",
"InputBarAccessoryView.xcframework"]
}
$demo_resources = {
"Ice/helloUI" => ["../certs"],
"IceDiscovery/helloUI" => ["../certs"],
"IceGrid/simple" => ["IceGrid/simple"] #For adding xml
}
desc "Generate Xcode projects required to build Ice for Swift Demo Applications"
task :iceproj do
project = Xcodeproj::Project.new("demos.xcodeproj")
aggregate_target_macos = project.new_aggregate_target("allDemos macOS")
aggregate_target_ios = project.new_aggregate_target("allDemos iOS")
group_add_files(project.main_group, "#{project.project_dir}", ["README.md"])
$demos.each do |platform, demos|
demos.each do |demo|
if platform == :ios then
create_swiftui_targets(project, demo, aggregate_target_ios)
else
create_commandline_targets(project, demo, aggregate_target_macos)
end
end
end
attributes = project.root_object.attributes
attributes["TargetAttributes"] ||= {}
project.targets.each do |target|
attributes["TargetAttributes"][target.uuid] ||= {}
attributes["TargetAttributes"][target.uuid]["ProvisioningStyle"] = "Automatic"
end
project.root_object.development_region = "en"
project.root_object.known_regions = ["Base", "en"]
project.build_independent_targets_in_parallel = true
#
# Sort the project and save it
#
project.sort({:groups_position => :above})
project.save()
end
task :default => [:iceproj]
def create_commandline_targets(project, demo, aggregate_target)
$demo_variants.each do |variant|
if demo_has_variant(demo, variant)
target = project.new_target(:command_line_tool, target_name(demo, variant), :osx)
aggregate_target.add_dependency(target)
target_set_common_build_settings(target, variant.downcase, "$SRCROOT/#{demo}", :osx)
target.frameworks_build_phases.clear()
group = project_group(project, demo)
group_add_files(group, "#{project.project_dir}/#{demo}", ["README.md", "config.*"])
target_add_files(target, group, "#{project.project_dir}/#{demo}/Sources", ["*.ice"])
group = project_group(project, "#{demo}/#{variant}")
target_add_files(target, group, "#{project.project_dir}/#{demo}/Sources",
demo_variant_sources(demo, variant))
target_add_carthage_framework(target, :osx, "IceImpl.xcframework")
target_add_carthage_framework(target, :osx, "Ice.xcframework")
target_add_carthage_framework(target, :osx, "PromiseKit.xcframework")
extra_frameworks = $demo_extra_frameworks[demo] || []
extra_frameworks.each do |f|
target_add_carthage_framework(target, :osx, f)
end
target_set_framework_build_settings(target, :osx)
target_add_slice2swift_build_rule(project, target)
end
end
end
def create_swiftui_targets(project, demo, aggregate_target)
target = project.new_target(:application, target_name(demo, ""), :ios)
aggregate_target.add_dependency(target)
target_set_common_build_settings(target, product_name(demo), "$SRCROOT/#{demo}", :ios, "$SRCROOT/#{demo}/Info.plist")
target.frameworks_build_phases.clear()
group = project_group(project, demo)
group_add_files(group, "#{project.project_dir}/#{demo}", ["README.md"])
target_add_files(target, group, "#{project.project_dir}/#{demo}", ["*.swift", "*.ice"])
if Dir.exists? "#{project.project_dir}/#{demo}/views"
target_add_files(target, group, "#{project.project_dir}/#{demo}/views", ["*.swift"])
end
if Dir.exists? "#{project.project_dir}/#{demo}/models"
target_add_files(target, group, "#{project.project_dir}/#{demo}/models", ["*.swift"])
end
target_add_files(target, group, "#{project.project_dir}/#{demo}", ["*.xcassets"])
target.add_resources(group_add_files(group, "#{project.project_dir}/#{demo}", ["config.client"]))
if $demo_resources.include? demo
target.add_resources(group_add_files(group, "#{project.project_dir}", $demo_resources[demo]))
end
target_add_carthage_framework(target, :ios, "IceImpl.xcframework", true)
target_add_carthage_framework(target, :ios, "Ice.xcframework", true)
target_add_carthage_framework(target, :ios, "PromiseKit.xcframework", true)
extra_frameworks = $demo_extra_frameworks[demo] || []
extra_frameworks.each do |f|
target_add_carthage_framework(target, :ios, f, true)
end
target_set_framework_build_settings(target, :ios)
target_add_slice2swift_build_rule(project, target)
if ENV.has_key?("DEVELOPMENT_TEAM") then
target.build_configurations.each { |config|
if target.product_type == "com.apple.product-type.application" or
target.product_type == "com.apple.product-type.bundle" then
config.build_settings["CODE_SIGN_STYLE"] = "Automatic"
config.build_settings["CODE_SIGN_IDENTITY"] = "Apple Development"
config.build_settings["DEVELOPMENT_TEAM"] = ENV["DEVELOPMENT_TEAM"]
end
}
end
return target
end
def project_group(project, name)
group = project.main_group
name.split("/").each { |item|
new_group = group[item]
unless new_group
new_group = group.new_group(item)
end
group = new_group
}
group
end
def target_name(basename, suffix)
basename.split("/").map{ |item| item[0].upcase + item[1..-1]}.join() + suffix
end
def product_name(basename)
basename.split("/")[-1].downcase
end
def target_add_slice2swift_build_rule(project, target, prefix = nil)
#
# Add Slice Compiler build rule to the target
#
rule = project.new(Xcodeproj::Project::PBXBuildRule)
rule.compiler_spec = "com.apple.compilers.proxy.script"
rule.file_type = "pattern.proxy"
script = <<~SCRIPT
BREW_PREFIX=$($SHELL -c 'brew --prefix' 2>/dev/null)
if [ -f "${ICE_HOME-unset}/bin/slice2swift" ]; then
SLICE2SWIFT="$ICE_HOME/bin/slice2swift"
SLICEDIR="$ICE_HOME/slice"
elif [ -f "${BREW_PREFIX-unset}/bin/slice2swift" ]; then
SLICE2SWIFT=$BREW_PREFIX/bin/slice2swift
SLICEDIR=$BREW_PREFIX/share/ice/slice
else
echo "Failed to locate slice2swift compiler"
exit 1
fi
"$SLICE2SWIFT" -I"$SLICEDIR" -I"$INPUT_FILE_DIR" --output-dir "$DERIVED_FILE_DIR" "$INPUT_FILE_PATH"
SCRIPT
rule.script = script
rule.run_once_per_architecture = "0"
if prefix then
rule.name = "Slice Compiler for #{prefix}/*.ice"
rule.file_patterns = "*/#{prefix}/*.ice"
rule.output_files = ["$(DERIVED_FILE_DIR)/#{prefix}_$(INPUT_FILE_BASE).swift"]
else
rule.name = "Slice Compiler"
rule.file_patterns = "*.ice"
rule.output_files = ["$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).swift"]
end
target.build_rules << rule
end
def group_add_files(group, basedir, patterns, exclude = [])
files = []
Dir.chdir(basedir) do
patterns.each do |p|
Dir.glob(p) do |file|
files << file
end
end
end
files = files.reject { |item| exclude.any? { |pattern| item.match(pattern) } }
files = files.uniq
files.map { |file| group.find_subpath(File.basename(file)) || group.new_file("#{basedir}/#{file}") }
end
def target_add_files(target, group, basedir, patterns, excludes = [])
target.add_file_references(group_add_files(group, basedir, patterns, excludes))
end
def target_add_headers(target, group, basedir, patterns, excludes: [], attributes: ["Public"])
files = group_add_files(group, basedir, patterns, excludes)
if attributes.include? "Public" then
files.each do |file|
header = target.headers_build_phase.add_file_reference(file)
header.settings = { "ATTRIBUTES" => attributes }
end
end
end
def target_set_common_build_settings(target, product, build_dir, platform, plist = nil)
target.build_configurations.each { |config|
config.build_settings["ENABLE_TESTABILITY"] = "NO"
config.build_settings["CODE_SIGN_STYLE"] = "Automatic"
config.build_settings["CURRENT_PROJECT_VERSION"] = "3.7.10"
config.build_settings["DYLIB_CURRENT_VERSION"] = "3.7.10"
config.build_settings["DYLIB_COMPATIBILITY_VERSION"] = "0"
config.build_settings["SWIFT_VERSION"] = "5.0"
if plist != nil then
config.build_settings["INFOPLIST_FILE"] = plist
end
config.build_settings["PRODUCT_NAME"] = product
config.build_settings["CONFIGURATION_BUILD_DIR"] = "#{build_dir}/Build"
config.build_settings["PRODUCT_BUNDLE_IDENTIFIER"] = "com.zeroc.demo.#{product}"
if platform == :osx
config.build_settings["MACOSX_DEPLOYMENT_TARGET"] = $macOSDeploymentTarget
else
config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = $iOSDeploymentTarget
end
}
end
def target_set_framework_build_settings(target, platform)
carthage_prefix = (platform == :osx) ? "Mac" : "iOS"
target.build_configurations.each { |config|
config.build_settings["FRAMEWORK_SEARCH_PATHS"] = "$SRCROOT/Carthage/Build/"
if carthage_prefix == "Mac" then
config.build_settings["LD_RUNPATH_SEARCH_PATHS"] = "@executable_path"
end
}
end
def target_add_carthage_framework(target, platform, framework, copy=false)
group = target.project.frameworks_group[(platform == :osx ? "OS X" : "iOS")]
group_add_files(group, "#{$top_level}/Carthage/Build", [framework]).each do |ref|
target.frameworks_build_phases.add_file_reference(ref, true)
if copy then
embed_frameworks_build_phase = target.build_phases.find { |bp| bp.display_name == "Embed Frameworks" }
if !embed_frameworks_build_phase then
embed_frameworks_build_phase = target.new_copy_files_build_phase('Embed Frameworks')
embed_frameworks_build_phase.dst_subfolder_spec = "10" # Frameworks
end
build_file = embed_frameworks_build_phase.add_file_reference(ref, true)
# add 'CodeSignOnCopy' to the list to enable signing
build_file.settings = { 'ATTRIBUTES' => ['RemoveHeadersOnCopy', 'CodeSignOnCopy'] }
end
end
end
#
# Check if the test include the given variant
#
def demo_has_variant(demo, variant)
return File.file?("#{demo}/Sources/#{variant}/main.swift") ||
File.file?("#{demo}/#{variant}/AppDelegate.swift")
end
def demo_variant_sources(demo, variant)
$demo_variant_sources[variant] || []
end