cocoapods-gd 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +13 -0
  3. data/Gemfile.lock +131 -0
  4. data/LICENSE +22 -0
  5. data/README.md +42 -0
  6. data/Rakefile +29 -0
  7. data/cocoapods-gd.gemspec +22 -0
  8. data/lib/cocoapods-gd.rb +5 -0
  9. data/lib/cocoapods-gd/builder.rb +393 -0
  10. data/lib/cocoapods-gd/framework.rb +66 -0
  11. data/lib/cocoapods-gd/install_frameworks.rb +77 -0
  12. data/lib/cocoapods-gd/mangle.rb +32 -0
  13. data/lib/cocoapods-gd/pod_utils.rb +246 -0
  14. data/lib/cocoapods-gd/podfile_env.rb +26 -0
  15. data/lib/cocoapods-gd/spec_builder.rb +72 -0
  16. data/lib/cocoapods-gd/symbols.rb +42 -0
  17. data/lib/cocoapods-gd/uploader.rb +70 -0
  18. data/lib/cocoapods-gd/user_interface/build_failed_report.rb +15 -0
  19. data/lib/cocoapods_plugin.rb +10 -0
  20. data/lib/pod/command/gd.rb +185 -0
  21. data/scripts/lstconst.sh +9 -0
  22. data/scripts/lstsym.sh +8 -0
  23. data/spec/command/error_spec.rb +81 -0
  24. data/spec/command/gd_spec.rb +420 -0
  25. data/spec/command/subspecs_spec.rb +30 -0
  26. data/spec/fixtures/Archs.podspec +13 -0
  27. data/spec/fixtures/Builder.podspec +25 -0
  28. data/spec/fixtures/CPDColors.podspec +19 -0
  29. data/spec/fixtures/FH.podspec +18 -0
  30. data/spec/fixtures/KFData.podspec +73 -0
  31. data/spec/fixtures/LibraryConsumerDemo/.gitignore +22 -0
  32. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer.xcodeproj/project.pbxproj +311 -0
  33. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  34. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer.xcodeproj/xcshareddata/xcschemes/LibraryConsumer.xcscheme +100 -0
  35. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/AppDelegate.h +17 -0
  36. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/AppDelegate.m +27 -0
  37. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/Info.plist +40 -0
  38. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/main.m +16 -0
  39. data/spec/fixtures/LibraryConsumerDemo/Podfile +5 -0
  40. data/spec/fixtures/LibraryDemo.podspec +14 -0
  41. data/spec/fixtures/LocalSources/LICENSE +0 -0
  42. data/spec/fixtures/LocalSources/LocalNikeKit.h +4 -0
  43. data/spec/fixtures/LocalSources/LocalNikeKit.m +9 -0
  44. data/spec/fixtures/LocalSources/LocalNikeKit.podspec +19 -0
  45. data/spec/fixtures/NikeKit.podspec +19 -0
  46. data/spec/fixtures/OpenSans.podspec +18 -0
  47. data/spec/fixtures/PackagerTest/.gitignore +21 -0
  48. data/spec/fixtures/PackagerTest/PackagerTest.xcodeproj/project.pbxproj +507 -0
  49. data/spec/fixtures/PackagerTest/PackagerTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  50. data/spec/fixtures/PackagerTest/PackagerTest.xcodeproj/xcshareddata/xcschemes/PackagerTest.xcscheme +110 -0
  51. data/spec/fixtures/PackagerTest/PackagerTest.xcworkspace/contents.xcworkspacedata +1 -0
  52. data/spec/fixtures/PackagerTest/PackagerTest/CPDAppDelegate.h +15 -0
  53. data/spec/fixtures/PackagerTest/PackagerTest/CPDAppDelegate.m +49 -0
  54. data/spec/fixtures/PackagerTest/PackagerTest/Images.xcassets/AppIcon.appiconset/Contents.json +23 -0
  55. data/spec/fixtures/PackagerTest/PackagerTest/Images.xcassets/LaunchImage.launchimage/Contents.json +23 -0
  56. data/spec/fixtures/PackagerTest/PackagerTest/PackagerTest-Info.plist +38 -0
  57. data/spec/fixtures/PackagerTest/PackagerTest/PackagerTest-Prefix.pch +16 -0
  58. data/spec/fixtures/PackagerTest/PackagerTest/en.lproj/InfoPlist.strings +2 -0
  59. data/spec/fixtures/PackagerTest/PackagerTest/main.m +18 -0
  60. data/spec/fixtures/PackagerTest/PackagerTestTests/PackagerTestTests-Info.plist +22 -0
  61. data/spec/fixtures/PackagerTest/PackagerTestTests/PackagerTestTests.m +34 -0
  62. data/spec/fixtures/PackagerTest/PackagerTestTests/en.lproj/InfoPlist.strings +2 -0
  63. data/spec/fixtures/PackagerTest/Podfile +10 -0
  64. data/spec/fixtures/PackagerTest/Podfile.lock +36 -0
  65. data/spec/fixtures/Weakly.podspec +13 -0
  66. data/spec/fixtures/a.podspec +19 -0
  67. data/spec/fixtures/foo-bar.podspec +19 -0
  68. data/spec/fixtures/layer-client-messaging-schema.podspec +13 -0
  69. data/spec/integration/project_spec.rb +70 -0
  70. data/spec/spec_helper.rb +79 -0
  71. data/spec/unit/pod/utils_spec.rb +58 -0
  72. data/spec/unit/specification/builder_spec.rb +62 -0
  73. data/spec/unit/specification/spec_builder_spec.rb +61 -0
  74. data/spec/unit/user_interface/build_failed_report_spec.rb +11 -0
  75. metadata +217 -0
@@ -0,0 +1,66 @@
1
+ module Framework
2
+ class Tree
3
+ attr_reader :headers_path
4
+ attr_reader :module_map_path
5
+ attr_reader :resources_path
6
+ attr_reader :root_path
7
+ attr_reader :versions_path
8
+
9
+ def delete_resources
10
+ Pathname.new(@resources_path).rmtree
11
+ (Pathname.new(@fwk_path) + Pathname.new('Resources')).delete
12
+ end
13
+
14
+ def initialize(name, platform, embedded)
15
+ @name = name
16
+ @platform = platform
17
+ @embedded = embedded
18
+ end
19
+
20
+ def make
21
+ make_root
22
+ make_framework
23
+ make_headers
24
+ make_resources
25
+ make_current_version
26
+ end
27
+
28
+ private
29
+
30
+ def make_current_version
31
+ current_version_path = @versions_path + Pathname.new('../Current')
32
+ `ln -sf A #{current_version_path}`
33
+ `ln -sf Versions/Current/Headers #{@fwk_path}/`
34
+ `ln -sf Versions/Current/Resources #{@fwk_path}/`
35
+ `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
36
+ end
37
+
38
+ def make_framework
39
+ @fwk_path = @root_path + Pathname.new(@name + '.framework')
40
+ @fwk_path.mkdir unless @fwk_path.exist?
41
+
42
+ @module_map_path = @fwk_path + Pathname.new('Modules')
43
+ @versions_path = @fwk_path + Pathname.new('Versions/A')
44
+ end
45
+
46
+ def make_headers
47
+ @headers_path = @versions_path + Pathname.new('Headers')
48
+ @headers_path.mkpath unless @headers_path.exist?
49
+ end
50
+
51
+ def make_resources
52
+ @resources_path = @versions_path + Pathname.new('Resources')
53
+ @resources_path.mkpath unless @resources_path.exist?
54
+ end
55
+
56
+ def make_root
57
+ @root_path = Pathname.new(@platform)
58
+
59
+ if @embedded
60
+ @root_path += Pathname.new(@name + '.embeddedframework')
61
+ end
62
+
63
+ @root_path.mkpath unless @root_path.exist?
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,77 @@
1
+ require 'cocoapods'
2
+ require 'cocoapods-gd/podfile_env'
3
+
4
+ module Pod
5
+ class InstallFramework
6
+ def install()
7
+ podfile = Pod::Config.instance.podfile
8
+ sandbox_path = "#{Dir.pwd}/Pods"
9
+ FileUtils.mkdir_p(sandbox_path) unless File.exists?(sandbox_path)
10
+ standard_sandbox = Pod::Sandbox.new(sandbox_path)
11
+
12
+ if !podfile.get_use_binaries
13
+ Pod::UI::puts("installing source code")
14
+ podfile_hash = podfile.to_hash
15
+ prebuild_podfile = Pod::Podfile.from_hash(podfile_hash)
16
+ binary_installer = Pod::Installer.new(standard_sandbox, prebuild_podfile)
17
+ binary_installer.install!
18
+ return
19
+ end
20
+
21
+ Pod::UI::puts("replaceing Frameworks")
22
+ nameList = podfile.get_use_source_code_selector.call()
23
+ if nameList.nil?
24
+ nameList = []
25
+ end
26
+
27
+ dependencies = []
28
+ podfile.to_hash["target_definitions"].first["children"].first["dependencies"].each do |library|
29
+ newLibrary = Hash.new
30
+ if library.is_a?(Hash)
31
+ for name in nameList
32
+ if library.keys.first == name
33
+ if library.values.first.first.is_a?(String)
34
+ newLibrary = Hash[name => [{:source=>sources(name) }]]
35
+ elsif library.values.first.first.is_a?(Hash)
36
+ if library.values.first.first[:git].nil?
37
+ newLibrary = library
38
+ newLibrary.values.first.first[:source] = sources(name)
39
+ end
40
+ end
41
+ break
42
+ end
43
+ end
44
+ end
45
+ if library.is_a?(String)
46
+ for name in nameList
47
+ if library == name
48
+ newLibrary = Hash[library => [{:source=> sources(library)}]]
49
+ break
50
+ end
51
+ end
52
+ end
53
+
54
+ if newLibrary.empty?
55
+ dependencies.push(library)
56
+ else
57
+ dependencies.push(newLibrary)
58
+ end
59
+ end
60
+ podfile_hash = podfile.to_hash
61
+ podfile_hash["target_definitions"].first["children"].first["dependencies"] = dependencies
62
+ podfile_hash["sources"] = ["https://gitlab.gaodun.com/iOSLibs/FrameworkSpecs.git", "https://gitlab.gaodun.com/iOSLibs/Specs.git", "https://gitlab.gaodun.com/iOSLibs/CocoaPods.git", "https://github.com/CocoaPods/Specs.git"]
63
+ prebuild_podfile = Pod::Podfile.from_hash(podfile_hash)
64
+ binary_installer = Pod::Installer.new(standard_sandbox, prebuild_podfile)
65
+ binary_installer.install!
66
+ end
67
+
68
+ def sources(name)
69
+ source_path = "https://gitlab.gaodun.com/iOSLibs/CocoaPods.git"
70
+ privateLibrary = ["AliPlayerSDK", "AliYunCeng", "AliyunLOGiOS", "TXIMSDK_TUIKit_iOS", "WCDBSwift", "WeexSDK"]
71
+ if name.start_with? "GD" || privateLibrary.include?(name)
72
+ source_path = "http://gitlab.gaodun.com/iOSLibs/Specs.git"
73
+ end
74
+ source_path
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,32 @@
1
+ module Symbols
2
+ #
3
+ # performs symbol aliasing
4
+ #
5
+ # for each dependency:
6
+ # - determine symbols for classes and global constants
7
+ # - alias each symbol to Pod#{pod_name}_#{symbol}
8
+ # - put defines into `GCC_PREPROCESSOR_DEFINITIONS` for passing to Xcode
9
+ #
10
+ def mangle_for_pod_dependencies(pod_name, sandbox_root)
11
+ pod_libs = Dir.glob("#{sandbox_root}/build/lib*.a").select do |file|
12
+ file !~ /lib#{pod_name}.a$/
13
+ end
14
+
15
+ dummy_alias = alias_symbol "PodsDummy_#{pod_name}", pod_name
16
+ all_syms = [dummy_alias]
17
+
18
+ pod_libs.each do |pod_lib|
19
+ syms = Symbols.symbols_from_library(pod_lib)
20
+ all_syms += syms.map! { |sym| alias_symbol sym, pod_name }
21
+ end
22
+
23
+ "GCC_PREPROCESSOR_DEFINITIONS='$(inherited) #{all_syms.uniq.join(' ')}'"
24
+ end
25
+
26
+ def alias_symbol(sym, pod_name)
27
+ pod_name = pod_name.tr('-', '_')
28
+ sym + "=Pod#{pod_name}_" + sym
29
+ end
30
+
31
+ module_function :mangle_for_pod_dependencies, :alias_symbol
32
+ end
@@ -0,0 +1,246 @@
1
+ module Pod
2
+ class Command
3
+ class Gd < Command
4
+ private
5
+
6
+ def build_static_sandbox(dynamic)
7
+ static_sandbox_root = if dynamic
8
+ Pathname.new(config.sandbox_root + '/Static')
9
+ else
10
+ Pathname.new(config.sandbox_root)
11
+ end
12
+ Sandbox.new(static_sandbox_root)
13
+ end
14
+
15
+ def install_pod(platform_name, sandbox)
16
+ podfile = podfile_from_spec(
17
+ @path,
18
+ @spec.name,
19
+ platform_name,
20
+ @spec.deployment_target(platform_name),
21
+ @subspecs,
22
+ @spec_sources
23
+ )
24
+
25
+ static_installer = Installer.new(sandbox, podfile)
26
+ static_installer.install!
27
+
28
+ unless static_installer.nil?
29
+ static_installer.pods_project.targets.each do |target|
30
+ target.build_configurations.each do |config|
31
+ config.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
32
+ config.build_settings['GCC_GENERATE_DEBUGGING_SYMBOLS'] = 'NO'
33
+ end
34
+ end
35
+ static_installer.pods_project.save
36
+ end
37
+
38
+ static_installer
39
+ end
40
+
41
+ def podfile_from_spec(path, spec_name, platform_name, deployment_target, subspecs, sources)
42
+ options = {}
43
+ if path
44
+ if @local
45
+ options[:path] = path
46
+ else
47
+ options[:podspec] = path
48
+ end
49
+ end
50
+ options[:subspecs] = subspecs if subspecs
51
+ Pod::Podfile.new do
52
+ sources.each { |s| source s }
53
+ platform(platform_name, deployment_target)
54
+ pod(spec_name, options)
55
+
56
+ install!('cocoapods',
57
+ :integrate_targets => false,
58
+ :deterministic_uuids => false)
59
+
60
+ target('gd') do
61
+ use_modular_headers!
62
+ inherit! :complete
63
+ end
64
+ end
65
+ end
66
+
67
+ def binary_only?(spec)
68
+ deps = spec.dependencies.map { |dep| spec_with_name(dep.name) }
69
+ [spec, *deps].each do |specification|
70
+ %w(vendored_frameworks vendored_libraries).each do |attrib|
71
+ if specification.attributes_hash[attrib]
72
+ return true
73
+ end
74
+ end
75
+ end
76
+
77
+ false
78
+ end
79
+
80
+ def spec_with_name(name)
81
+ return if name.nil?
82
+
83
+ set = Pod::Config.instance.sources_manager.search(Dependency.new(name))
84
+ return nil if set.nil?
85
+
86
+ set.specification.root
87
+ end
88
+
89
+ def spec_with_path(path)
90
+ return if path.nil?
91
+ path = Pathname.new(path)
92
+ path = Pathname.new(Dir.pwd).join(path) unless path.absolute?
93
+ return unless path.exist?
94
+
95
+ @path = path.expand_path
96
+
97
+ if @path.directory?
98
+ help! @path + ': is a directory.'
99
+ return
100
+ end
101
+
102
+ unless ['.podspec', '.json'].include? @path.extname
103
+ help! @path + ': is not a podspec.'
104
+ return
105
+ end
106
+
107
+ Specification.from_file(@path)
108
+ end
109
+
110
+ #----------------------
111
+ # Dynamic Project Setup
112
+ #----------------------
113
+
114
+ def build_dynamic_sandbox(_static_sandbox, _static_installer)
115
+ dynamic_sandbox_root = Pathname.new(config.sandbox_root + '/Dynamic')
116
+ dynamic_sandbox = Sandbox.new(dynamic_sandbox_root)
117
+
118
+ dynamic_sandbox
119
+ end
120
+
121
+ # @param [Pod::Sandbox] dynamic_sandbox
122
+ #
123
+ # @param [Pod::Sandbox] static_sandbox
124
+ #
125
+ # @param [Pod::Installer] static_installer
126
+ #
127
+ # @param [Pod::Platform] platform
128
+ #
129
+ def install_dynamic_pod(dynamic_sandbox, static_sandbox, static_installer, platform)
130
+ # 1 Create a dynamic target for only the spec pod.
131
+ dynamic_target = build_dynamic_target(dynamic_sandbox, static_installer, platform)
132
+
133
+ # 2. Build a new xcodeproj in the dynamic_sandbox with only the spec pod as a target.
134
+ project = prepare_pods_project(dynamic_sandbox, dynamic_target.name, static_installer)
135
+
136
+ # 3. Copy the source directory for the dynamic framework from the static sandbox.
137
+ copy_dynamic_target(static_sandbox, dynamic_target, dynamic_sandbox)
138
+
139
+ # 4. Create the file references.
140
+ install_file_references(dynamic_sandbox, [dynamic_target], project)
141
+
142
+ # 5. Install the target.
143
+ install_library(dynamic_sandbox, dynamic_target, project)
144
+
145
+ # 6. Write the actual .xcodeproj to the dynamic sandbox.
146
+ write_pod_project(project, dynamic_sandbox)
147
+ end
148
+
149
+ # @param [Pod::Installer] static_installer
150
+ #
151
+ # @return [Pod::PodTarget]
152
+ #
153
+ def build_dynamic_target(dynamic_sandbox, static_installer, platform)
154
+ spec_targets = static_installer.pod_targets.select do |target|
155
+ target.name == @spec.name
156
+ end
157
+ static_target = spec_targets[0]
158
+
159
+ file_accessors = create_file_accessors(static_target, dynamic_sandbox)
160
+
161
+ archs = []
162
+ buildy_type = Pod::BuildType.static_framework()
163
+ dynamic_target = Pod::PodTarget.new(dynamic_sandbox, buildy_type, static_target.user_build_configurations, archs, platform, static_target.specs, static_target.target_definitions, file_accessors)
164
+ dynamic_target
165
+ end
166
+
167
+ # @param [Pod::Sandbox] dynamic_sandbox
168
+ #
169
+ # @param [String] spec_name
170
+ #
171
+ # @param [Pod::Installer] installer
172
+ #
173
+ def prepare_pods_project(dynamic_sandbox, spec_name, installer)
174
+ # Create a new pods project
175
+ pods_project = Pod::Project.new(dynamic_sandbox.project_path)
176
+
177
+ # Update build configurations
178
+ installer.analysis_result.all_user_build_configurations.each do |name, type|
179
+ pods_project.add_build_configuration(name, type)
180
+ end
181
+
182
+ # Add the pod group for only the dynamic framework
183
+ local = dynamic_sandbox.local?(spec_name)
184
+ path = dynamic_sandbox.pod_dir(spec_name)
185
+ was_absolute = dynamic_sandbox.local_path_was_absolute?(spec_name)
186
+ pods_project.add_pod_group(spec_name, path, local, was_absolute)
187
+ pods_project
188
+ end
189
+
190
+ def copy_dynamic_target(static_sandbox, _dynamic_target, dynamic_sandbox)
191
+ command = "cp -a #{static_sandbox.root}/#{@spec.name} #{dynamic_sandbox.root}"
192
+ `#{command}`
193
+ end
194
+
195
+ def create_file_accessors(target, dynamic_sandbox)
196
+ pod_root = dynamic_sandbox.pod_dir(target.root_spec.name)
197
+
198
+ path_list = Sandbox::PathList.new(pod_root)
199
+ target.specs.map do |spec|
200
+ Sandbox::FileAccessor.new(path_list, spec.consumer(target.platform))
201
+ end
202
+ end
203
+
204
+ def install_file_references(dynamic_sandbox, pod_targets, pods_project)
205
+ installer = Pod::Installer::Xcode::PodsProjectGenerator::FileReferencesInstaller.new(dynamic_sandbox, pod_targets, pods_project)
206
+ installer.install!
207
+ end
208
+
209
+ def install_library(dynamic_sandbox, dynamic_target, project)
210
+ return if dynamic_target.target_definitions.flat_map(&:dependencies).empty?
211
+ target_installer = Pod::Installer::Xcode::PodsProjectGenerator::PodTargetInstaller.new(dynamic_sandbox, project, dynamic_target)
212
+ result = target_installer.install!
213
+ native_target = result.native_target
214
+
215
+ # Installs System Frameworks
216
+ if dynamic_target.should_build?
217
+ dynamic_target.file_accessors.each do |file_accessor|
218
+ file_accessor.spec_consumer.frameworks.each do |framework|
219
+ native_target.add_system_framework(framework)
220
+ end
221
+ file_accessor.spec_consumer.libraries.each do |library|
222
+ native_target.add_system_library(library)
223
+ end
224
+ end
225
+ end
226
+ end
227
+
228
+ def write_pod_project(dynamic_project, dynamic_sandbox)
229
+ UI.message "- Writing Xcode project file to #{UI.path dynamic_sandbox.project_path}" do
230
+ dynamic_project.pods.remove_from_project if dynamic_project.pods.empty?
231
+ dynamic_project.development_pods.remove_from_project if dynamic_project.development_pods.empty?
232
+ dynamic_project.sort(:groups_position => :below)
233
+ dynamic_project.recreate_user_schemes(false)
234
+
235
+ # Edit search paths so that we can find our dependency headers
236
+ dynamic_project.targets.first.build_configuration_list.build_configurations.each do |config|
237
+ config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) #{Dir.pwd}/Pods/Static/Headers/**"
238
+ config.build_settings['USER_HEADER_SEARCH_PATHS'] = "$(inherited) #{Dir.pwd}/Pods/Static/Headers/**"
239
+ config.build_settings['OTHER_LDFLAGS'] = '$(inherited) -ObjC'
240
+ end
241
+ dynamic_project.save
242
+ end
243
+ end
244
+ end
245
+ end
246
+ end
@@ -0,0 +1,26 @@
1
+ require 'cocoapods'
2
+
3
+ module Pod
4
+ class Podfile
5
+ USE_BINARIES = 'use_binaries'
6
+ USE_SOURCE_CODE_SELECTOR = 'use_source_code'
7
+
8
+ def use_binaries!(flag = true)
9
+ internal_hash[USE_BINARIES] = flag
10
+ end
11
+
12
+ def get_use_binaries
13
+ internal_hash[USE_BINARIES]
14
+ end
15
+
16
+ def use_source_code_selector!(&block)
17
+ raise Informative, '必须提供选择需要二进制组件的 block !' unless block_given?
18
+ internal_hash[USE_SOURCE_CODE_SELECTOR] = block
19
+ end
20
+
21
+ def get_use_source_code_selector
22
+ internal_hash[USE_SOURCE_CODE_SELECTOR]
23
+ end
24
+
25
+ end
26
+ end