cocoapods-packager-xz 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +4 -0
  4. data/.rubocop-cocoapods.yml +71 -0
  5. data/.rubocop.yml +38 -0
  6. data/.travis.yml +17 -0
  7. data/Gemfile +12 -0
  8. data/Gemfile.lock +129 -0
  9. data/LICENSE +22 -0
  10. data/README.md +42 -0
  11. data/Rakefile +29 -0
  12. data/cocoapods-packager-xz.gemspec +22 -0
  13. data/lib/cocoapods-packager/builder.rb +336 -0
  14. data/lib/cocoapods-packager/framework.rb +77 -0
  15. data/lib/cocoapods-packager/mangle.rb +32 -0
  16. data/lib/cocoapods-packager/pod_utils.rb +244 -0
  17. data/lib/cocoapods-packager/spec_builder.rb +63 -0
  18. data/lib/cocoapods-packager/symbols.rb +42 -0
  19. data/lib/cocoapods-packager/user_interface/build_failed_report.rb +15 -0
  20. data/lib/cocoapods_packager.rb +5 -0
  21. data/lib/cocoapods_plugin.rb +8 -0
  22. data/lib/pod/command/package.rb +177 -0
  23. data/scripts/lstconst.sh +9 -0
  24. data/scripts/lstsym.sh +8 -0
  25. data/spec/command/error_spec.rb +81 -0
  26. data/spec/command/package_spec.rb +420 -0
  27. data/spec/command/subspecs_spec.rb +30 -0
  28. data/spec/fixtures/Archs.podspec +13 -0
  29. data/spec/fixtures/Builder.podspec +25 -0
  30. data/spec/fixtures/CPDColors.podspec +19 -0
  31. data/spec/fixtures/FH.podspec +18 -0
  32. data/spec/fixtures/KFData.podspec +73 -0
  33. data/spec/fixtures/LibraryConsumerDemo/.gitignore +22 -0
  34. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer.xcodeproj/project.pbxproj +311 -0
  35. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  36. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer.xcodeproj/xcshareddata/xcschemes/LibraryConsumer.xcscheme +100 -0
  37. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/AppDelegate.h +17 -0
  38. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/AppDelegate.m +27 -0
  39. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/Info.plist +40 -0
  40. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/main.m +16 -0
  41. data/spec/fixtures/LibraryConsumerDemo/Podfile +5 -0
  42. data/spec/fixtures/LibraryDemo.podspec +14 -0
  43. data/spec/fixtures/LocalSources/LICENSE +0 -0
  44. data/spec/fixtures/LocalSources/LocalNikeKit.h +4 -0
  45. data/spec/fixtures/LocalSources/LocalNikeKit.m +9 -0
  46. data/spec/fixtures/LocalSources/LocalNikeKit.podspec +19 -0
  47. data/spec/fixtures/NikeKit.podspec +19 -0
  48. data/spec/fixtures/OpenSans.podspec +18 -0
  49. data/spec/fixtures/PackagerTest/.gitignore +21 -0
  50. data/spec/fixtures/PackagerTest/PackagerTest.xcodeproj/project.pbxproj +507 -0
  51. data/spec/fixtures/PackagerTest/PackagerTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  52. data/spec/fixtures/PackagerTest/PackagerTest.xcodeproj/xcshareddata/xcschemes/PackagerTest.xcscheme +110 -0
  53. data/spec/fixtures/PackagerTest/PackagerTest.xcworkspace/contents.xcworkspacedata +1 -0
  54. data/spec/fixtures/PackagerTest/PackagerTest/CPDAppDelegate.h +15 -0
  55. data/spec/fixtures/PackagerTest/PackagerTest/CPDAppDelegate.m +49 -0
  56. data/spec/fixtures/PackagerTest/PackagerTest/Images.xcassets/AppIcon.appiconset/Contents.json +23 -0
  57. data/spec/fixtures/PackagerTest/PackagerTest/Images.xcassets/LaunchImage.launchimage/Contents.json +23 -0
  58. data/spec/fixtures/PackagerTest/PackagerTest/PackagerTest-Info.plist +38 -0
  59. data/spec/fixtures/PackagerTest/PackagerTest/PackagerTest-Prefix.pch +16 -0
  60. data/spec/fixtures/PackagerTest/PackagerTest/en.lproj/InfoPlist.strings +2 -0
  61. data/spec/fixtures/PackagerTest/PackagerTest/main.m +18 -0
  62. data/spec/fixtures/PackagerTest/PackagerTestTests/PackagerTestTests-Info.plist +22 -0
  63. data/spec/fixtures/PackagerTest/PackagerTestTests/PackagerTestTests.m +34 -0
  64. data/spec/fixtures/PackagerTest/PackagerTestTests/en.lproj/InfoPlist.strings +2 -0
  65. data/spec/fixtures/PackagerTest/Podfile +10 -0
  66. data/spec/fixtures/PackagerTest/Podfile.lock +36 -0
  67. data/spec/fixtures/Weakly.podspec +13 -0
  68. data/spec/fixtures/a.podspec +19 -0
  69. data/spec/fixtures/foo-bar.podspec +19 -0
  70. data/spec/fixtures/layer-client-messaging-schema.podspec +13 -0
  71. data/spec/integration/project_spec.rb +70 -0
  72. data/spec/spec_helper.rb +79 -0
  73. data/spec/unit/pod/utils_spec.rb +58 -0
  74. data/spec/unit/specification/builder_spec.rb +62 -0
  75. data/spec/unit/specification/spec_builder_spec.rb +61 -0
  76. data/spec/unit/user_interface/build_failed_report_spec.rb +11 -0
  77. metadata +220 -0
@@ -0,0 +1,77 @@
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
+ attr_accessor :fwk_path
9
+ attr_accessor :name
10
+ attr_accessor :versions_path
11
+ def delete_resources
12
+ Pathname.new(@resources_path).rmtree
13
+ (Pathname.new(@fwk_path) + Pathname.new('Resources')).delete
14
+ end
15
+
16
+ def initialize(name, platform, embedded)
17
+ @name = name
18
+ @platform = platform
19
+ @embedded = embedded
20
+ end
21
+
22
+ def make
23
+ make_root
24
+ make_framework
25
+ make_headers
26
+ make_resources
27
+ make_current_version
28
+ end
29
+
30
+ def process_static_framework
31
+ `rm -rf #{@fwk_path}/Headers`
32
+ `rm -rf #{@fwk_path}/Resources`
33
+ `rm -rf #{@fwk_path}/#{@name}`
34
+ `cp -r #{@versions_path}/* #{fwk_path}`
35
+ `rm -rf #{@fwk_path}/Versions`
36
+ end
37
+
38
+ private
39
+
40
+ def make_current_version
41
+ current_version_path = @versions_path + Pathname.new('../Current')
42
+ `ln -sf A #{current_version_path}`
43
+ `ln -sf Versions/Current/Headers #{@fwk_path}/`
44
+ `ln -sf Versions/Current/Resources #{@fwk_path}/`
45
+ `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
46
+ end
47
+
48
+ def make_framework
49
+ @fwk_path = @root_path + Pathname.new(@name + '.framework')
50
+ @fwk_path.mkdir unless @fwk_path.exist?
51
+
52
+ @module_map_path = @fwk_path + Pathname.new('Modules')
53
+ @versions_path = @fwk_path + Pathname.new('Versions/A')
54
+ end
55
+
56
+
57
+ def make_headers
58
+ @headers_path = @versions_path + Pathname.new('Headers')
59
+ @headers_path.mkpath unless @headers_path.exist?
60
+ end
61
+
62
+ def make_resources
63
+ @resources_path = @versions_path + Pathname.new('Resources')
64
+ @resources_path.mkpath unless @resources_path.exist?
65
+ end
66
+
67
+ def make_root
68
+ @root_path = Pathname.new(@platform)
69
+
70
+ if @embedded
71
+ @root_path += Pathname.new(@name + '.embeddedframework')
72
+ end
73
+
74
+ @root_path.mkpath unless @root_path.exist?
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,244 @@
1
+ module Pod
2
+ class Command
3
+ class Package < 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('packager') do
61
+ inherit! :complete
62
+ end
63
+ end
64
+ end
65
+
66
+ def binary_only?(spec)
67
+ deps = spec.dependencies.map { |dep| spec_with_name(dep.name) }
68
+ [spec, *deps].each do |specification|
69
+ %w(vendored_frameworks vendored_libraries).each do |attrib|
70
+ if specification.attributes_hash[attrib]
71
+ return true
72
+ end
73
+ end
74
+ end
75
+
76
+ false
77
+ end
78
+
79
+ def spec_with_name(name)
80
+ return if name.nil?
81
+
82
+ set = Pod::Config.instance.sources_manager.search(Dependency.new(name))
83
+ return nil if set.nil?
84
+
85
+ set.specification.root
86
+ end
87
+
88
+ def spec_with_path(path)
89
+ return if path.nil?
90
+ path = Pathname.new(path)
91
+ path = Pathname.new(Dir.pwd).join(path) unless path.absolute?
92
+ return unless path.exist?
93
+
94
+ @path = path.expand_path
95
+
96
+ if @path.directory?
97
+ help! @path + ': is a directory.'
98
+ return
99
+ end
100
+
101
+ unless ['.podspec', '.json'].include? @path.extname
102
+ help! @path + ': is not a podspec.'
103
+ return
104
+ end
105
+
106
+ Specification.from_file(@path)
107
+ end
108
+
109
+ #----------------------
110
+ # Dynamic Project Setup
111
+ #----------------------
112
+
113
+ def build_dynamic_sandbox(_static_sandbox, _static_installer)
114
+ dynamic_sandbox_root = Pathname.new(config.sandbox_root + '/Dynamic')
115
+ dynamic_sandbox = Sandbox.new(dynamic_sandbox_root)
116
+
117
+ dynamic_sandbox
118
+ end
119
+
120
+ # @param [Pod::Sandbox] dynamic_sandbox
121
+ #
122
+ # @param [Pod::Sandbox] static_sandbox
123
+ #
124
+ # @param [Pod::Installer] static_installer
125
+ #
126
+ # @param [Pod::Platform] platform
127
+ #
128
+ def install_dynamic_pod(dynamic_sandbox, static_sandbox, static_installer, platform)
129
+ # 1 Create a dynamic target for only the spec pod.
130
+ dynamic_target = build_dynamic_target(dynamic_sandbox, static_installer, platform)
131
+
132
+ # 2. Build a new xcodeproj in the dynamic_sandbox with only the spec pod as a target.
133
+ project = prepare_pods_project(dynamic_sandbox, dynamic_target.name, static_installer)
134
+
135
+ # 3. Copy the source directory for the dynamic framework from the static sandbox.
136
+ copy_dynamic_target(static_sandbox, dynamic_target, dynamic_sandbox)
137
+
138
+ # 4. Create the file references.
139
+ install_file_references(dynamic_sandbox, [dynamic_target], project)
140
+
141
+ # 5. Install the target.
142
+ install_library(dynamic_sandbox, dynamic_target, project)
143
+
144
+ # 6. Write the actual .xcodeproj to the dynamic sandbox.
145
+ write_pod_project(project, dynamic_sandbox)
146
+ end
147
+
148
+ # @param [Pod::Installer] static_installer
149
+ #
150
+ # @return [Pod::PodTarget]
151
+ #
152
+ def build_dynamic_target(dynamic_sandbox, static_installer, platform)
153
+ spec_targets = static_installer.pod_targets.select do |target|
154
+ target.name == @spec.name
155
+ end
156
+ static_target = spec_targets[0]
157
+
158
+ file_accessors = create_file_accessors(static_target, dynamic_sandbox)
159
+
160
+ archs = []
161
+ dynamic_target = Pod::PodTarget.new(dynamic_sandbox, true, static_target.user_build_configurations, archs, platform, static_target.specs, static_target.target_definitions, file_accessors)
162
+ dynamic_target
163
+ end
164
+
165
+ # @param [Pod::Sandbox] dynamic_sandbox
166
+ #
167
+ # @param [String] spec_name
168
+ #
169
+ # @param [Pod::Installer] installer
170
+ #
171
+ def prepare_pods_project(dynamic_sandbox, spec_name, installer)
172
+ # Create a new pods project
173
+ pods_project = Pod::Project.new(dynamic_sandbox.project_path)
174
+
175
+ # Update build configurations
176
+ installer.analysis_result.all_user_build_configurations.each do |name, type|
177
+ pods_project.add_build_configuration(name, type)
178
+ end
179
+
180
+ # Add the pod group for only the dynamic framework
181
+ local = dynamic_sandbox.local?(spec_name)
182
+ path = dynamic_sandbox.pod_dir(spec_name)
183
+ was_absolute = dynamic_sandbox.local_path_was_absolute?(spec_name)
184
+ pods_project.add_pod_group(spec_name, path, local, was_absolute)
185
+ pods_project
186
+ end
187
+
188
+ def copy_dynamic_target(static_sandbox, _dynamic_target, dynamic_sandbox)
189
+ command = "cp -a #{static_sandbox.root}/#{@spec.name} #{dynamic_sandbox.root}"
190
+ `#{command}`
191
+ end
192
+
193
+ def create_file_accessors(target, dynamic_sandbox)
194
+ pod_root = dynamic_sandbox.pod_dir(target.root_spec.name)
195
+
196
+ path_list = Sandbox::PathList.new(pod_root)
197
+ target.specs.map do |spec|
198
+ Sandbox::FileAccessor.new(path_list, spec.consumer(target.platform))
199
+ end
200
+ end
201
+
202
+ def install_file_references(dynamic_sandbox, pod_targets, pods_project)
203
+ installer = Pod::Installer::Xcode::PodsProjectGenerator::FileReferencesInstaller.new(dynamic_sandbox, pod_targets, pods_project)
204
+ installer.install!
205
+ end
206
+
207
+ def install_library(dynamic_sandbox, dynamic_target, project)
208
+ return if dynamic_target.target_definitions.flat_map(&:dependencies).empty?
209
+ target_installer = Pod::Installer::Xcode::PodsProjectGenerator::PodTargetInstaller.new(dynamic_sandbox, project, dynamic_target)
210
+ result = target_installer.install!
211
+ native_target = result.native_target
212
+
213
+ # Installs System Frameworks
214
+ if dynamic_target.should_build?
215
+ dynamic_target.file_accessors.each do |file_accessor|
216
+ file_accessor.spec_consumer.frameworks.each do |framework|
217
+ native_target.add_system_framework(framework)
218
+ end
219
+ file_accessor.spec_consumer.libraries.each do |library|
220
+ native_target.add_system_library(library)
221
+ end
222
+ end
223
+ end
224
+ end
225
+
226
+ def write_pod_project(dynamic_project, dynamic_sandbox)
227
+ UI.message "- Writing Xcode project file to #{UI.path dynamic_sandbox.project_path}" do
228
+ dynamic_project.pods.remove_from_project if dynamic_project.pods.empty?
229
+ dynamic_project.development_pods.remove_from_project if dynamic_project.development_pods.empty?
230
+ dynamic_project.sort(:groups_position => :below)
231
+ dynamic_project.recreate_user_schemes(false)
232
+
233
+ # Edit search paths so that we can find our dependency headers
234
+ dynamic_project.targets.first.build_configuration_list.build_configurations.each do |config|
235
+ config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) #{Dir.pwd}/Pods/Static/Headers/**"
236
+ config.build_settings['USER_HEADER_SEARCH_PATHS'] = "$(inherited) #{Dir.pwd}/Pods/Static/Headers/**"
237
+ config.build_settings['OTHER_LDFLAGS'] = '$(inherited) -ObjC'
238
+ end
239
+ dynamic_project.save
240
+ end
241
+ end
242
+ end
243
+ end
244
+ end
@@ -0,0 +1,63 @@
1
+ module Pod
2
+ class SpecBuilder
3
+ def initialize(spec, source, embedded, dynamic)
4
+ @spec = spec
5
+ @source = source.nil? ? '{ :path => \'.\' }' : source
6
+ @embedded = embedded
7
+ @dynamic = dynamic
8
+ end
9
+
10
+ def framework_path
11
+ if @embedded
12
+ @spec.name + '.embeddedframework' + '/' + @spec.name + '.framework'
13
+ else
14
+ @spec.name + '.framework'
15
+ end
16
+ end
17
+
18
+ def spec_platform(platform)
19
+ fwk_base = platform.name.to_s + '/' + framework_path
20
+ spec = <<RB
21
+ s.#{platform.name}.deployment_target = '#{platform.deployment_target}'
22
+ s.#{platform.name}.vendored_framework = '#{fwk_base}'
23
+ RB
24
+
25
+ %w(frameworks weak_frameworks libraries requires_arc xcconfig).each do |attribute|
26
+ attributes_hash = @spec.attributes_hash[platform.name.to_s]
27
+ next if attributes_hash.nil?
28
+ value = attributes_hash[attribute]
29
+ next if value.nil?
30
+
31
+ value = "'#{value}'" if value.class == String
32
+ spec += " s.#{platform.name}.#{attribute} = #{value}\n"
33
+ end
34
+ spec
35
+ end
36
+
37
+ def spec_metadata
38
+ spec = spec_header
39
+ spec
40
+ end
41
+
42
+ def spec_close
43
+ "end\n"
44
+ end
45
+
46
+ private
47
+
48
+ def spec_header
49
+ spec = "Pod::Spec.new do |s|\n"
50
+
51
+ %w(name version summary license authors homepage description social_media_url
52
+ docset_url documentation_url screenshots frameworks weak_frameworks libraries requires_arc
53
+ deployment_target xcconfig).each do |attribute|
54
+ value = @spec.attributes_hash[attribute]
55
+ next if value.nil?
56
+ value = value.dump if value.class == String
57
+ spec += " s.#{attribute} = #{value}\n"
58
+ end
59
+
60
+ spec + " s.source = #{@source}\n\n"
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,42 @@
1
+ module Symbols
2
+ def symbols_from_library(library)
3
+ syms = `nm -defined-only -extern-only #{library}`.split("\n")
4
+ result = classes_from_symbols(syms)
5
+ result += constants_from_symbols(syms)
6
+
7
+ result.select do |e|
8
+ case e
9
+ when 'llvm.cmdline', 'llvm.embedded.module', '__clang_at_available_requires_core_foundation_framework'
10
+ false
11
+ else
12
+ true
13
+ end
14
+ end
15
+ end
16
+
17
+ module_function :symbols_from_library
18
+
19
+ private
20
+
21
+ def classes_from_symbols(syms)
22
+ classes = syms.select { |klass| klass[/OBJC_CLASS_\$_/] }
23
+ classes = classes.uniq
24
+ classes.map! { |klass| klass.gsub(/^.*\$_/, '') }
25
+ end
26
+
27
+ def constants_from_symbols(syms)
28
+ consts = syms.select { |const| const[/ S /] }
29
+ consts = consts.select { |const| const !~ /OBJC|\.eh/ }
30
+ consts = consts.uniq
31
+ consts = consts.map! { |const| const.gsub(/^.* _/, '') }
32
+
33
+ other_consts = syms.select { |const| const[/ T /] }
34
+ other_consts = other_consts.uniq
35
+ other_consts = other_consts.map! { |const| const.gsub(/^.* _/, '') }
36
+
37
+ consts + other_consts
38
+ end
39
+
40
+ module_function :classes_from_symbols
41
+ module_function :constants_from_symbols
42
+ end