-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
app_host_installer.rb
146 lines (128 loc) · 5.79 KB
/
app_host_installer.rb
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
module Pod
class Installer
class Xcode
class PodsProjectGenerator
# Installs an app host target to a given project.
#
class AppHostInstaller
include TargetInstallerHelper
# @return [Sandbox]
# The sandbox used for this installation.
#
attr_reader :sandbox
# @return [Pod::Project]
# The project to install the app host into.
#
attr_reader :project
# @return [Platform] the platform to use for this app host.
#
attr_reader :platform
# @return [String] the name of the sub group.
#
attr_reader :subgroup_name
# @return [String] the name of the group the app host installer will be installing within.
#
attr_reader :group_name
# @return [String] the name of the app target label that will be used.
#
attr_reader :app_target_label
# @return [Boolean] whether the app host installer should add main.m
#
attr_reader :add_main
# @return [Boolean] whether the app host installer should add a launch screen storyboard
#
attr_reader :add_launchscreen_storyboard
# @return [Hash] Info.plist entries for the app host
#
attr_reader :info_plist_entries
# Initialize a new instance
#
# @param [Sandbox] sandbox @see #sandbox
# @param [Pod::Project] project @see #project
# @param [Platform] platform @see #platform
# @param [String] subgroup_name @see #subgroup_name
# @param [String] group_name @see #group_name
# @param [String] app_target_label see #app_target_label
# @param [Boolean] add_main see #add_main
# @param [Hash] info_plist_entries see #info_plist_entries
#
def initialize(sandbox, project, platform, subgroup_name, group_name, app_target_label, add_main: true, add_launchscreen_storyboard: platform == :ios, info_plist_entries: {})
@sandbox = sandbox
@project = project
@platform = platform
@subgroup_name = subgroup_name
@group_name = group_name
@app_target_label = app_target_label
@add_main = add_main
@add_launchscreen_storyboard = add_launchscreen_storyboard
@info_plist_entries = info_plist_entries
target_group = project.pod_group(group_name)
@group = target_group[subgroup_name] || target_group.new_group(subgroup_name)
end
# @return [PBXNativeTarget] the app host native target that was installed.
#
def install!
platform_name = platform.name
app_host_target = Pod::Generator::AppTargetHelper.add_app_target(project, platform_name, deployment_target,
app_target_label)
app_host_target.build_configurations.each do |configuration|
configuration.build_settings['PRODUCT_NAME'] = app_target_label
configuration.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'org.cocoapods.${PRODUCT_NAME:rfc1034identifier}'
if platform == :osx
configuration.build_settings['CODE_SIGN_IDENTITY'] = ''
elsif platform == :ios
configuration.build_settings['CODE_SIGN_IDENTITY'] = 'iPhone Developer'
end
configuration.build_settings['CURRENT_PROJECT_VERSION'] = '1'
end
Pod::Generator::AppTargetHelper.add_app_host_main_file(project, app_host_target, platform_name, @group, app_target_label) if add_main
Pod::Generator::AppTargetHelper.add_launchscreen_storyboard(project, app_host_target, @group, deployment_target, app_target_label) if add_launchscreen_storyboard
create_info_plist_file_with_sandbox(sandbox, app_host_info_plist_path, app_host_target, '1.0.0', platform,
:appl, :additional_entries => additional_info_plist_entries)
@group.new_file(app_host_info_plist_path)
app_host_target
end
private
ADDITIONAL_INFO_PLIST_ENTRIES = {
'NSAppTransportSecurity' => {
'NSAllowsArbitraryLoads' => true,
},
}.freeze
ADDITIONAL_IOS_INFO_PLIST_ENTRIES = {
'UILaunchStoryboardName' => 'LaunchScreen',
'UISupportedInterfaceOrientations' => %w(
UIInterfaceOrientationPortrait
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
),
'UISupportedInterfaceOrientations~ipad' => %w(
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
),
}.freeze
# @return [Hash] the additional Info.plist entries to be included
#
def additional_info_plist_entries
result = {}
result.merge!(ADDITIONAL_INFO_PLIST_ENTRIES)
result.merge!(ADDITIONAL_IOS_INFO_PLIST_ENTRIES) if platform == :ios
result.merge!(info_plist_entries) if info_plist_entries
result
end
# @return [Pathname] The absolute path of the Info.plist to use for an app host.
#
def app_host_info_plist_path
project.path.dirname.+(subgroup_name).+("#{app_target_label}-Info.plist")
end
# @return [String] The deployment target.
#
def deployment_target
platform.deployment_target.to_s
end
end
end
end
end
end