cocoapods-kz 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,53 +0,0 @@
1
- module KZ
2
- class BuildFrameworkConfig
3
-
4
- def initialize(main_project, pod_project)
5
- @pod_project = pod_project
6
- end
7
-
8
- def config_project
9
- @pod_project.targets.each do |target|
10
- if target.isa == "PBXNativeTarget" && target.product_type == "com.apple.product-type.framework"
11
- generate_framework_script = target.new_shell_script_build_phase('[KZ] Generate Framework')
12
- generate_framework_script.show_env_vars_in_log = '0'
13
- generate_framework_script.always_out_of_date = '1'
14
- generate_framework_script.shell_script = %q{
15
- if [ "${MACH_O_TYPE}" != "staticlib" ]; then
16
- exit 0
17
- fi
18
-
19
- if [ "${ACTION}" != "build" ]; then
20
- exit 0
21
- fi
22
-
23
- PRODUCT_DIR=${PODS_BUILD_DIR}/Debug-iphoneos/${TARGET_NAME}/${FULL_PRODUCT_NAME}
24
- PRODUCT_SIMULATOR_DIR=${PODS_BUILD_DIR}/Debug-iphonesimulator/${TARGET_NAME}/${FULL_PRODUCT_NAME}
25
- CURRENT_PRODUCT_DIR=${PODS_CONFIGURATION_BUILD_DIR}/${TARGET_NAME}
26
-
27
- if [ -d "${KZ_FRAMEWORK_CACHE_PATH}" ]; then
28
- rm -r "${KZ_FRAMEWORK_CACHE_PATH}"
29
- fi
30
- mkdir -p "${KZ_FRAMEWORK_CACHE_PATH}"
31
-
32
- if [ -d "${KZ_FRAMEWORK_CACHE_PATH}/${FULL_PRODUCT_NAME}" ]; then
33
- rm -r "${KZ_FRAMEWORK_CACHE_PATH}/${FULL_PRODUCT_NAME}"
34
- fi
35
- cp -r ${CURRENT_PRODUCT_DIR}/${FULL_PRODUCT_NAME} "${KZ_FRAMEWORK_CACHE_PATH}"
36
-
37
- find "${CURRENT_PRODUCT_DIR}" -iname "*.bundle" -type d | while read -r BUNDLE_FILE; do
38
- BUNDLE_NAME=$(basename ${BUNDLE_FILE})
39
- if [ -d "${KZ_FRAMEWORK_CACHE_PATH}/${BUNDLE_NAME}" ]; then
40
- rm -r "${KZ_FRAMEWORK_CACHE_PATH}/${BUNDLE_NAME}"
41
- fi
42
- cp -r ${BUNDLE_FILE} "${KZ_FRAMEWORK_CACHE_PATH}"
43
- done
44
-
45
- if [ -f ${PRODUCT_DIR}/${PRODUCT_NAME} ] && [ -f ${PRODUCT_SIMULATOR_DIR}/${PRODUCT_NAME} ]; then
46
- lipo -create ${PRODUCT_DIR}/${PRODUCT_NAME} ${PRODUCT_SIMULATOR_DIR}/${PRODUCT_NAME} -output "${KZ_FRAMEWORK_CACHE_PATH}/${PRODUCT_NAME}.framework/${PRODUCT_NAME}"
47
- fi
48
- }
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,236 +0,0 @@
1
- require 'fileutils'
2
- require_relative 'global_helper'
3
-
4
- module KZ
5
- class HmapContentStyle
6
- QUOTES_PRIVATE = 1
7
- QUOTES_REPAIR = 2
8
- end
9
-
10
- class CreateHmap
11
-
12
- def initialize(main_project, pod_project)
13
- @main_project = main_project
14
- @pod_project = pod_project
15
- end
16
-
17
- def traverse_folder(folder_path)
18
- Dir.foreach(folder_path) do |file_name|
19
- next if file_name == '.' || file_name == '..'
20
-
21
- file_path = File.join(folder_path, file_name)
22
- if File.file?(file_path)
23
- yield(file_path) if file_name.end_with?('.h')
24
- elsif File.directory?(file_path)
25
- traverse_folder(file_path) do |path|
26
- yield(path)
27
- end
28
- end
29
- end
30
- end
31
-
32
- def get_pod_pchfile_path(target_name)
33
- @pod_project.project_dir + 'Target Support Files' + target_name + "#{target_name}-prefix.pch"
34
- end
35
-
36
- def save_hmap_file(hmap_hash, save_path, file_name)
37
- hmap_json = JSON.pretty_generate(hmap_hash)
38
- hmap_json_path = save_path + "#{file_name}.json"
39
- hmap_path = save_path + "#{file_name}.hmap"
40
- json_file = File.new(hmap_json_path, 'w')
41
- return unless json_file
42
-
43
- json_file.syswrite(hmap_json)
44
- system "#{HMAP_EXECUTE_PATH} convert #{hmap_json_path} #{hmap_path}"
45
-
46
- FileUtils.rm(hmap_json_path) unless KZ::KZGlobalHelper.instance.debug
47
- end
48
-
49
- def create_main_hamp
50
- main_sources_path = @main_project.project_dir + @main_project.root_object.display_name
51
- private_hmap_hash = {}
52
- traverse_folder(main_sources_path) do |header_path|
53
- header_pathname = Pathname.new(header_path)
54
- header_pathname_basename = header_pathname.basename.to_s
55
-
56
- header_hmap_value = {}
57
- header_hmap_value['suffix'] = header_pathname_basename
58
- header_hmap_value['prefix'] = header_pathname.dirname.to_s + '/'
59
-
60
- private_hmap_hash[header_pathname_basename] = header_hmap_value
61
- end
62
-
63
- unless private_hmap_hash.empty?
64
- save_hmap_file(private_hmap_hash, KZ_POD_CONFIG_ROOT, @main_project.root_object.display_name)
65
- end
66
-
67
- @main_project.targets.each do |target|
68
- if target.isa == "PBXNativeTarget" and target.product_type == "com.apple.product-type.application"
69
- target.build_configurations.each do |config|
70
- config.build_settings['HEADER_SEARCH_PATHS'] = "${PODS_ROOT}/KZPodConfigure/#{@main_project.root_object.display_name }.hmap"
71
- config.build_settings['USE_HEADERMAP'] = 'NO'
72
- end
73
- end
74
- end
75
- end
76
-
77
- def get_all_native_target_from(project)
78
- all_native_target = {}
79
-
80
- project.targets.each do |target|
81
- if target.isa == "PBXNativeTarget" and target.product_type == "com.apple.product-type.framework" and !target.name.start_with?('Pods-')
82
- all_native_target[target.name] = target
83
- end
84
- end
85
- all_native_target
86
- end
87
-
88
- def get_all_test_target_from(project)
89
- all_native_target = {}
90
-
91
- project.targets.each do |target|
92
- if target.isa == "PBXNativeTarget" and target.product_type == "com.apple.product-type.bundle.unit-test"
93
- all_native_target[target.name] = target
94
- end
95
- end
96
- all_native_target
97
- end
98
-
99
- def get_all_aggregate_target_from(project)
100
- all_handle_target = {}
101
-
102
- project.targets.each do |target|
103
- if target.isa == "PBXAggregateTarget"
104
- all_handle_target[target.name] = target
105
- end
106
- end
107
- all_handle_target
108
- end
109
-
110
- def get_hmap_info_from(kz_pod_target, hmap_content_style)
111
- header_paths = kz_pod_target.public_headers
112
- header_paths = kz_pod_target.all_headers if hmap_content_style == HmapContentStyle::QUOTES_PRIVATE
113
- hmap_info = {}
114
- header_paths.each do |header_pathname|
115
- header_pathname_basename = header_pathname.basename.to_s
116
-
117
- header_hmap_value_quotes = {}
118
- header_hmap_value_quotes['suffix'] = header_pathname_basename
119
- header_hmap_value_quotes['prefix'] = header_pathname.dirname.to_s + '/'
120
- hmap_info[header_pathname_basename] = header_hmap_value_quotes
121
-
122
- if hmap_content_style == HmapContentStyle::QUOTES_PRIVATE
123
- # pch
124
- pchfile_path = get_pod_pchfile_path(kz_pod_target.name)
125
- if pchfile_path.exist?
126
- suffix = pchfile_path.basename.to_s
127
- prefix = pchfile_path.dirname.to_s + '/'
128
- header_hmap_value = {}
129
- header_hmap_value['suffix'] = suffix
130
- header_hmap_value['prefix'] = prefix
131
- hmap_info[suffix] = header_hmap_value
132
- end
133
-
134
- unless kz_pod_target.is_dev_pod
135
- # 各别第三方在使用自己组件文件时,会使用#import <xx/xx.h>的方式
136
- hmap_info[kz_pod_target.name + '/' + header_pathname_basename] = header_hmap_value_quotes
137
- end
138
-
139
- # 例如SPBoss.h会被在SPBoss-Swift.h中以#import <SPBoss/SPBoss.h>的方式使用,需要重定义寻找路径
140
- if kz_pod_target.uses_swift && kz_pod_target.is_dev_pod && header_pathname_basename == "#{kz_pod_target.name}.h"
141
- hmap_info[kz_pod_target.name + '/' + header_pathname_basename] = header_hmap_value_quotes
142
- end
143
- elsif hmap_content_style == HmapContentStyle::QUOTES_REPAIR
144
- header_hmap_value_slash = {}
145
- header_hmap_value_slash['suffix'] = header_pathname_basename
146
- prefix_name = kz_pod_target.name
147
- if header_pathname.dirname.to_s.include?('.framework')
148
- header_pathname.dirname.to_s.split('/').each do |name|
149
- if name.include?('.framework')
150
- prefix_name = name.split('.').first
151
- end
152
- end
153
- end
154
- header_hmap_value_slash['prefix'] = prefix_name + '/'
155
- hmap_info[header_pathname_basename] = header_hmap_value_slash
156
- end
157
- end
158
- hmap_info
159
- end
160
-
161
- def create_pod_hamp(all_kz_pod_targets)
162
- all_native_targets = get_all_native_target_from(@pod_project)
163
- all_handle_targets = all_native_targets.merge(get_all_aggregate_target_from(@pod_project))
164
- all_handle_targets.each do |target_name, target|
165
- kz_pod_target = all_kz_pod_targets[target_name]
166
- next unless kz_pod_target
167
-
168
- # 修复头文件导入方式
169
- kz_recursive_dependent_targets = kz_pod_target.repair_import
170
- if kz_recursive_dependent_targets.count > 0
171
- all_repair_hmap_info = {}
172
- kz_recursive_dependent_targets.each { |recursive_dependent_target|
173
- repair_hmap_info = get_hmap_info_from(recursive_dependent_target, HmapContentStyle::QUOTES_REPAIR)
174
- all_repair_hmap_info.merge!(repair_hmap_info)
175
- }
176
- if all_repair_hmap_info.count > 0
177
- hmap_cache_path = kz_pod_target.pod_config_cache_path(false)
178
- save_hmap_file(all_repair_hmap_info, hmap_cache_path, target_name + '_repair')
179
- kz_pod_target.repair_header_search_path = hmap_cache_path + "#{target_name}_repair.hmap"
180
- end
181
- end
182
- end
183
-
184
- all_native_targets.each do |target_name, target|
185
- target_real_name = target_name.split("-").first
186
- kz_pod_target = all_kz_pod_targets[target_real_name]
187
- next unless kz_pod_target
188
-
189
- # 添加私有头文件引用
190
- private_hamp_info = get_hmap_info_from(kz_pod_target, HmapContentStyle::QUOTES_PRIVATE)
191
- if private_hamp_info.count > 0
192
- hmap_cache_path = kz_pod_target.pod_config_cache_path(false)
193
- save_hmap_file(private_hamp_info, kz_pod_target.pod_config_cache_path(false), target_real_name)
194
- kz_pod_target.private_header_search_path = hmap_cache_path + "#{target_real_name}.hmap"
195
- end
196
-
197
- # 修复缺失的依赖
198
- framework_search_paths = '$(inherited)'
199
- kz_pod_target.all_repair_dependent_target_info.values.each do |repair_target|
200
- result = KZGlobalHelper.instance.pod_config_result_with_target(repair_target)
201
- if result
202
- framework_search_paths += (' ' + "#{result.resource_path.to_s}")
203
- else
204
- # 修复target依赖
205
- dependency_target = all_native_targets[repair_target.name]
206
- target.add_dependency(dependency_target) if dependency_target
207
- # 修复framework_search_paths
208
- framework_search_paths += (' ' + '"${PODS_CONFIGURATION_BUILD_DIR}/' + repair_target.name + '"')
209
- end
210
- end
211
- kz_pod_target.framwork_search_paths = framework_search_paths
212
- end
213
-
214
- all_config_target = all_native_targets.merge(get_all_test_target_from(@pod_project))
215
- all_config_target.each do |target_name, target|
216
- target_real_name = target_name.split("-").first
217
- kz_pod_target = all_kz_pod_targets[target_real_name]
218
- next unless kz_pod_target
219
-
220
- # 添加配置
221
- target.build_configurations.each do |config|
222
- config.build_settings['HEADER_SEARCH_PATHS'] = kz_pod_target.header_search_paths
223
- config.build_settings['USE_HEADERMAP'] = 'NO'
224
- config.build_settings['FRAMEWORK_SEARCH_PATHS'] = kz_pod_target.framwork_search_paths
225
- config.build_settings['KZ_FRAMEWORK_CACHE_PATH'] = kz_pod_target.pod_config_cache_path(true).to_s
226
- end
227
- end
228
- end
229
-
230
- def config_project
231
- create_main_hamp
232
- create_pod_hamp(KZGlobalHelper.instance.kz_analyzer.all_kz_pod_targets)
233
- end
234
-
235
- end
236
- end
@@ -1,40 +0,0 @@
1
- require 'fileutils'
2
- require 'tempfile'
3
-
4
- module KZ
5
- class StripFrameworkConfig
6
- def initialize(main_project, pod_project)
7
- @main_project = main_project
8
- @pod_project = pod_project
9
- end
10
-
11
- def pod_target_support_files_path
12
- @pod_project.project_dir + 'Target Support Files'
13
- end
14
-
15
- def config_project
16
- @main_project.targets.each do |target|
17
- if target.isa == "PBXNativeTarget" and target.product_type == "com.apple.product-type.application"
18
- target_support_file_path = pod_target_support_files_path + "Pods-#{target.name}" + "Pods-#{target.name}-frameworks.sh"
19
- if target_support_file_path.exist?
20
- temp_sh_file_path = @main_project.project_dir + "Pods-#{target.name}" + 'temp.sh'
21
- temp_sh_file = Tempfile.new(temp_sh_file_path.to_s)
22
- chmod_cmd = "chmod +x #{temp_sh_file.path}"
23
- system chmod_cmd
24
-
25
- sh_file = File.open(target_support_file_path, "r+")
26
- sh_file.each_line { |line|
27
- temp_sh_file.puts(line)
28
- if line.start_with?(" # Resign the code if required by the build settings to avoid unstable apps")
29
- temp_sh_file.puts(' xcrun strip -x "${destination}/${basename}.framework/${basename}" 2> /dev/null')
30
- end
31
- }
32
- temp_sh_file.close
33
- FileUtils.mv(temp_sh_file.path, target_support_file_path)
34
- end
35
- end
36
- end
37
- end
38
-
39
- end
40
- end
@@ -1,57 +0,0 @@
1
- require_relative 'global_helper'
2
-
3
- module KZ
4
- class XmlBuildConfig
5
- def initialize(main_project, pod_project)
6
- @pod_project = pod_project
7
- end
8
-
9
- def new_build_rule(project, target, name)
10
- new_rule = nil
11
- target.build_rules.each do |build_rule|
12
- new_rule = build_rule if build_rule.name == name
13
- end
14
-
15
- if new_rule == nil
16
- new_rule = project.new(Xcodeproj::Project::PBXBuildRule)
17
- target.build_rules << new_rule
18
- end
19
-
20
- new_rule.name = name
21
- new_rule.compiler_spec = 'com.apple.compilers.proxy.script'
22
- new_rule
23
- end
24
-
25
- def create_xml_rule(project, target)
26
- xml_rule = new_build_rule(project, target, '[KZ] Custom Xml Build')
27
- xml_rule.file_type = 'text.xml'
28
- xml_rule.output_files = Array['${KZ_XML_FLEX_DIR}/${INPUT_FILE_BASE}.flex']
29
- xml_rule.script = %Q{FLEX_PATH=${KZ_XML_FLEX_DIR}/${INPUT_FILE_BASE}.flex
30
- rm -rf ${FLEX_PATH}
31
- $KZ_XML_FLEX_COMPILER $INPUT_FILE_PATH $FLEX_PATH
32
- if [ -f $FLEX_PATH ] ; then
33
- cp $FLEX_PATH $KZ_XML_FLEX_BUILD_DIR
34
- exit 0
35
- else
36
- exit 1
37
- fi}
38
- end
39
-
40
- def config_project
41
- @pod_project.targets.each do |target|
42
- if target.isa == "PBXNativeTarget" && target.product_type == "com.apple.product-type.framework"
43
- kz_pod_target = KZGlobalHelper.instance.kz_analyzer.all_kz_pod_targets[target.name]
44
- next unless kz_pod_target
45
- next unless kz_pod_target.is_dev_pod
46
-
47
- target.build_configurations.each do |config|
48
- config.build_settings["KZ_XML_FLEX_COMPILER"] = FLEX_COMPLIER_PATH.to_s
49
- config.build_settings["KZ_XML_FLEX_DIR"] = "${TARGET_TEMP_DIR}/XmlFlexs"
50
- config.build_settings["KZ_XML_FLEX_BUILD_DIR"] = "${TARGET_BUILD_DIR}/${PRODUCT_NAME}.bundle"
51
- end
52
- self.create_xml_rule(@pod_project, target)
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,16 +0,0 @@
1
- require 'cocoapods/installer/user_project_integrator'
2
- require 'cocoapods-kz/helpers/global_helper'
3
-
4
- module Pod
5
- class Installer
6
- class UserProjectIntegrator
7
-
8
- alias_method :origin_print_override_warning, :print_override_warning
9
- def print_override_warning(aggregate_target, user_target, config, key)
10
- unless KZ::KZGlobalHelper.instance.kz_pod_enable
11
- origin_print_override_warning(aggregate_target, user_target, config, key)
12
- end
13
- end
14
- end
15
- end
16
- end