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,15 @@
1
+ module Pod
2
+ module UserInterface
3
+ module BuildFailedReport
4
+ class << self
5
+ def report(command, output)
6
+ <<-EOF
7
+ Build command failed: #{command}
8
+ Output:
9
+ #{output.map { |line| " #{line}" }.join}
10
+ EOF
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Pod
2
+ module Packager
3
+ VERSION = '1.0.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'pod/command/package'
2
+ require 'cocoapods-packager/user_interface/build_failed_report'
3
+ require 'cocoapods-packager/builder'
4
+ require 'cocoapods-packager/framework'
5
+ require 'cocoapods-packager/mangle'
6
+ require 'cocoapods-packager/pod_utils'
7
+ require 'cocoapods-packager/spec_builder'
8
+ require 'cocoapods-packager/symbols'
@@ -0,0 +1,177 @@
1
+ require 'tmpdir'
2
+ module Pod
3
+ class Command
4
+ class Package < Command
5
+ self.summary = 'Package a podspec into a static library.'
6
+ self.arguments = [
7
+ CLAide::Argument.new('NAME', true),
8
+ CLAide::Argument.new('SOURCE', false)
9
+ ]
10
+
11
+ def self.options
12
+ [
13
+ ['--force', 'Overwrite existing files.'],
14
+ ['--no-mangle', 'Do not mangle symbols of depedendant Pods.'],
15
+ ['--embedded', 'Generate embedded frameworks.'],
16
+ ['--library', 'Generate static libraries.'],
17
+ ['--dynamic', 'Generate dynamic framework.'],
18
+ ['--local', 'Use local state rather than published versions.'],
19
+ ['--bundle-identifier', 'Bundle identifier for dynamic framework'],
20
+ ['--exclude-deps', 'Exclude symbols from dependencies.'],
21
+ ['--configuration', 'Build the specified configuration (e.g. Debug). Defaults to Release'],
22
+ ['--subspecs', 'Only include the given subspecs'],
23
+ ['--spec-sources=private,https://github.com/CocoaPods/Specs.git', 'The sources to pull dependent ' \
24
+ 'pods from (defaults to https://github.com/CocoaPods/Specs.git)']
25
+ ]
26
+ end
27
+
28
+ def initialize(argv)
29
+ @embedded = argv.flag?('embedded')
30
+ @library = argv.flag?('library')
31
+ @dynamic = argv.flag?('dynamic')
32
+ @local = argv.flag?('local', false)
33
+ @package_type = if @embedded
34
+ :static_framework
35
+ elsif @dynamic
36
+ :dynamic_framework
37
+ elsif @library
38
+ :static_library
39
+ else
40
+ :static_framework
41
+ end
42
+ @force = argv.flag?('force')
43
+ @mangle = argv.flag?('mangle', true)
44
+ @bundle_identifier = argv.option('bundle-identifier', nil)
45
+ @exclude_deps = argv.flag?('exclude-deps', false)
46
+ @name = argv.shift_argument
47
+ @source = argv.shift_argument
48
+ @spec_sources = argv.option('spec-sources', 'https://github.com/CocoaPods/Specs.git').split(',')
49
+
50
+ subspecs = argv.option('subspecs')
51
+ @subspecs = subspecs.split(',') unless subspecs.nil?
52
+
53
+ @config = argv.option('configuration', 'Release')
54
+
55
+ @source_dir = Dir.pwd
56
+ @is_spec_from_path = false
57
+ @spec = spec_with_path(@name)
58
+ @is_spec_from_path = true if @spec
59
+ @spec ||= spec_with_name(@name)
60
+ super
61
+ end
62
+
63
+ def validate!
64
+ super
65
+ help! 'A podspec name or path is required.' unless @spec
66
+ help! 'podspec has binary-only depedencies, mangling not possible.' if @mangle && binary_only?(@spec)
67
+ help! '--bundle-identifier option can only be used for dynamic frameworks' if @bundle_identifier && !@dynamic
68
+ help! '--exclude-deps option can only be used for static libraries' if @exclude_deps && @dynamic
69
+ help! '--local option can only be used when a local `.podspec` path is given.' if @local && !@is_spec_from_path
70
+ end
71
+
72
+ def run
73
+ if @spec.nil?
74
+ help! "Unable to find a podspec with path or name `#{@name}`."
75
+ return
76
+ end
77
+
78
+ target_dir, work_dir = create_working_directory
79
+ return if target_dir.nil?
80
+ build_package
81
+
82
+ `mv "#{work_dir}" "#{target_dir}"`
83
+ Dir.chdir(@source_dir)
84
+ end
85
+
86
+ private
87
+
88
+ def build_in_sandbox(platform)
89
+ config.installation_root = Pathname.new(Dir.pwd)
90
+ config.sandbox_root = 'Pods'
91
+
92
+ static_sandbox = build_static_sandbox(@dynamic)
93
+ static_installer = install_pod(platform.name, static_sandbox)
94
+
95
+ if @dynamic
96
+ dynamic_sandbox = build_dynamic_sandbox(static_sandbox, static_installer)
97
+ install_dynamic_pod(dynamic_sandbox, static_sandbox, static_installer, platform)
98
+ end
99
+
100
+ begin
101
+ perform_build(platform, static_sandbox, dynamic_sandbox, static_installer)
102
+ ensure # in case the build fails; see Builder#xcodebuild.
103
+ Pathname.new(config.sandbox_root).rmtree
104
+ FileUtils.rm_f('Podfile.lock')
105
+ end
106
+ end
107
+
108
+ def build_package
109
+ builder = SpecBuilder.new(@spec, @source, @embedded, @dynamic)
110
+ newspec = builder.spec_metadata
111
+
112
+ @spec.available_platforms.each do |platform|
113
+ build_in_sandbox(platform)
114
+
115
+ newspec += builder.spec_platform(platform)
116
+ end
117
+
118
+ newspec += builder.spec_close
119
+ File.open(@spec.name + '.podspec', 'w') { |file| file.write(newspec) }
120
+ end
121
+
122
+ def create_target_directory
123
+ target_dir = "#{@source_dir}/#{@spec.name}-#{@spec.version}"
124
+ if File.exist? target_dir
125
+ if @force
126
+ Pathname.new(target_dir).rmtree
127
+ else
128
+ UI.puts "Target directory '#{target_dir}' already exists."
129
+ return nil
130
+ end
131
+ end
132
+ target_dir
133
+ end
134
+
135
+ def create_working_directory
136
+ target_dir = create_target_directory
137
+ return if target_dir.nil?
138
+
139
+ work_dir = Dir.tmpdir + '/cocoapods-' + Array.new(8) { rand(36).to_s(36) }.join
140
+ Pathname.new(work_dir).mkdir
141
+ Dir.chdir(work_dir)
142
+
143
+ [target_dir, work_dir]
144
+ end
145
+
146
+ def perform_build(platform, static_sandbox, dynamic_sandbox, static_installer)
147
+ static_sandbox_root = config.sandbox_root.to_s
148
+
149
+ if @dynamic
150
+ static_sandbox_root = "#{static_sandbox_root}/#{static_sandbox.root.to_s.split('/').last}"
151
+ dynamic_sandbox_root = "#{config.sandbox_root}/#{dynamic_sandbox.root.to_s.split('/').last}"
152
+ end
153
+
154
+ builder = Pod::Builder.new(
155
+ platform,
156
+ static_installer,
157
+ @source_dir,
158
+ static_sandbox_root,
159
+ dynamic_sandbox_root,
160
+ static_sandbox.public_headers.root,
161
+ @spec,
162
+ @embedded,
163
+ @mangle,
164
+ @dynamic,
165
+ @config,
166
+ @bundle_identifier,
167
+ @exclude_deps
168
+ )
169
+
170
+ builder.build(@package_type)
171
+
172
+ return unless @embedded
173
+ builder.link_embedded_resources
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ #
4
+ # List symbols for all constants
5
+ #
6
+
7
+ nm "$@"|grep ' S '|grep -v 'OBJC\|\.eh$'| \
8
+ cut -d_ -f2-|sort|uniq
9
+ nm "$@"|grep ' T '|cut -d_ -f2-|sort|uniq
data/scripts/lstsym.sh ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+
3
+ #
4
+ # List symbols for all Objective-C classes
5
+ #
6
+
7
+ nm "$@"| grep 'OBJC_CLASS_\$_'|grep -v '_NS\|_UI'| \
8
+ rev|cut -d' ' -f-1|rev|sort|uniq|cut -d'_' -f5-
@@ -0,0 +1,81 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe 'Packager' do
5
+ after do
6
+ Dir.glob("CPDColors-*").each { |dir| Pathname.new(dir).rmtree }
7
+ Dir.glob("layer-client-messaging-schema-*").each { |dir| Pathname.new(dir).rmtree }
8
+ Dir.glob("OpenSans-*").each { |dir| Pathname.new(dir).rmtree }
9
+ Dir.glob("Weakly-*").each { |dir| Pathname.new(dir).rmtree }
10
+ end
11
+
12
+ it 'presents the help if a directory is provided' do
13
+ should.raise CLAide::Help do
14
+ command = Command.parse(%w{ package spec })
15
+ end.message.should.match /is a directory/
16
+ end
17
+
18
+ it 'presents the help if a random file is provided instead of a specification' do
19
+ should.raise CLAide::Help do
20
+ command = Command.parse(%w{ package README.md })
21
+ end.message.should.match /is not a podspec/
22
+ end
23
+
24
+ it 'presents the help if a podspec with binary-only dependencies is used' do
25
+ command = Command.parse(%w{ package spec/fixtures/CPDColors.podspec })
26
+ should.raise CLAide::Help do
27
+ command.validate!
28
+ end.message.should.match /binary-only/
29
+ end
30
+
31
+ it 'presents the help if only --bundle-identifier is specified' do
32
+ command = Command.parse(%w{ package spec/fixtures/NikeKit.podspec --bundle-identifier=com.example.NikeKit })
33
+ should.raise CLAide::Help do
34
+ command.validate!
35
+ end.message.should.match /--bundle-identifier option can only be used for dynamic frameworks/
36
+ end
37
+
38
+ it 'presents the help if both --exclude-deps and --dynamic are specified' do
39
+ command = Command.parse(%w{ package spec/fixtures/NikeKit.podspec --exclude-deps --dynamic })
40
+ should.raise CLAide::Help do
41
+ command.validate!
42
+ end.message.should.match /--exclude-deps option can only be used for static libraries/
43
+ end
44
+
45
+ it 'presents the help if --local is specified without .podspec path' do
46
+ command = Command.parse(%w{ package AFNetworking --local })
47
+ should.raise CLAide::Help do
48
+ command.validate!
49
+ end.message.should.match /--local option can only be used when a local `.podspec` path is given/
50
+ end
51
+
52
+ it 'can package a podspec with only resources' do
53
+ command = Command.parse(%w{ package spec/fixtures/layer-client-messaging-schema.podspec --no-mangle })
54
+ command.run
55
+
56
+ true.should == true # To make the test pass without any shoulds
57
+ end
58
+
59
+ it 'can package a podspec with binary-only dependencies if --no-mangle is specified' do
60
+ command = Command.parse(%w{ package spec/fixtures/CPDColors.podspec --no-mangle })
61
+ command.run
62
+
63
+ true.should == true # To make the test pass without any shoulds
64
+ end
65
+
66
+ it 'can package a podspec with resource bundles' do
67
+ command = Command.parse(%w{ package spec/fixtures/OpenSans.podspec })
68
+ command.run
69
+
70
+ bundles = Dir.glob('OpenSans-*/ios/OpenSans.framework/Versions/A/Resources/*.bundle')
71
+ bundles.count.should == 1
72
+ end
73
+
74
+ it 'can package a podspec with weak frameworks without strong linking' do
75
+ command = Command.parse(%w{ package spec/fixtures/Weakly.podspec })
76
+ command.run
77
+
78
+ `otool -l Weakly-*/ios/Weakly.framework/Weakly`.should.not.match /AssetsLibrary/
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,420 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+
5
+ DONT_CODESIGN = true
6
+
7
+ describe Command::Spec::Package do
8
+ describe 'CLAide' do
9
+ after do
10
+ Dir.glob("Archs-*").each { |dir| Pathname.new(dir).rmtree }
11
+ Dir.glob("CPDColors-*").each { |dir| Pathname.new(dir).rmtree }
12
+ Dir.glob("KFData-*").each { |dir| Pathname.new(dir).rmtree }
13
+ Dir.glob("NikeKit-*").each { |dir| Pathname.new(dir).rmtree }
14
+ Dir.glob("LocalNikeKit-*").each { |dir| Pathname.new(dir).rmtree }
15
+ Dir.glob("foo-bar-*").each { |dir| Pathname.new(dir).rmtree }
16
+ Dir.glob("a-*").each { |dir| Pathname.new(dir).rmtree }
17
+ Dir.glob("FH-*").each { |dir| Pathname.new(dir).rmtree }
18
+ Dir.glob("FirebaseAnalytics-*").each { |dir| Pathname.new(dir).rmtree }
19
+ end
20
+
21
+ def reject_block_symbols(symbols)
22
+ symbols
23
+ .reject { |e| e =~ /__block_descriptor.*/ }
24
+ .reject { |e| e =~ /__destroy_helper_block.*/ }
25
+ .reject { |e| e =~ /__copy_helper_block.*/ }
26
+ end
27
+
28
+ it 'registers itself' do
29
+ Command.parse(%w{ package }).should.be.instance_of Command::Package
30
+ end
31
+
32
+ it 'presents the help if no spec is provided' do
33
+ command = Command.parse(%w{ package })
34
+ should.raise CLAide::Help do
35
+ command.validate!
36
+ end.message.should.match /required/
37
+ end
38
+
39
+ it "errors if it cannot find a spec" do
40
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
41
+
42
+ command = Command.parse(%w{ package KFData })
43
+ should.raise CLAide::Help do
44
+ command.run
45
+ end.message.should.match /Unable to find/
46
+ end
47
+
48
+
49
+ it "should produce a dynamic library when dynamic is specified" do
50
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
51
+
52
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--dynamic'])
53
+ command.run
54
+
55
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
56
+ file_command = "file #{lib}"
57
+ output = `#{file_command}`.lines.to_a
58
+
59
+ output[0].should.match /Mach-O universal binary with 5 architectures/
60
+ output[1].should.match /Mach-O dynamically linked shared library i386/
61
+ end
62
+
63
+ it "should produce a dSYM when dynamic is specified" do
64
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
65
+
66
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--dynamic'])
67
+ command.run
68
+
69
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework.dSYM/Contents/Resources/DWARF/NikeKit").first
70
+ file_command = "file #{lib}"
71
+ output = `#{file_command}`.lines.to_a
72
+
73
+ output[0].should.match /Mach-O universal binary with 3 architectures/
74
+ output[1].should.match /Mach-O dSYM companion file arm/
75
+ end
76
+
77
+ it "should link category symbols when dynamic is specified" do
78
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
79
+
80
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--dynamic'])
81
+ command.run
82
+
83
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
84
+ file_command = "nm #{lib}"
85
+ output = `#{file_command}`.lines.to_a
86
+
87
+ match = output.detect { |line| line =~ /UIButton\(AFNetworking\)/ }
88
+ match.should.not.be.empty
89
+ end
90
+
91
+ it "should produce a dynamic library for OSX when dynamic is specified" do
92
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
93
+
94
+ command = Command.parse(['package', fixture('KFData.podspec'), '--dynamic'])
95
+ command.run
96
+
97
+ lib = Dir.glob("KFData-*/osx/KFData.framework/KFData").first
98
+ file_command = "file #{lib}"
99
+ output = `#{file_command}`.lines.to_a
100
+
101
+ output[0].should.match /Mach-O 64-bit dynamically linked shared library x86_64/
102
+ end
103
+
104
+ it "should produce a dSYM for OSX when dynamic is specified" do
105
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
106
+
107
+ command = Command.parse(['package', fixture('KFData.podspec'), '--dynamic'])
108
+ command.run
109
+
110
+ lib = Dir.glob("KFData-*/osx/KFData.framework.dSYM/Contents/Resources/DWARF/KFData").first
111
+ file_command = "file #{lib}"
112
+ output = `#{file_command}`.lines.to_a
113
+
114
+ output[0].should.match /Mach-O 64-bit dSYM companion file x86_64/
115
+ end
116
+
117
+ it "should produce the default plist for iOS and OSX when --dynamic is specified but --bundle-identifier is not" do
118
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
119
+
120
+ command = Command.parse(['package', fixture('KFData.podspec'), '--dynamic'])
121
+ command.run
122
+
123
+ ios_plist = File.expand_path(Dir.glob("KFData-*/ios/KFData.framework/Info.plist").first)
124
+ osx_plist = File.expand_path(Dir.glob("KFData-*/osx/KFData.framework/Resources/Info.plist").first)
125
+
126
+ ios_bundle_id = `defaults read #{ios_plist} CFBundleIdentifier`
127
+ osx_bundle_id = `defaults read #{osx_plist} CFBundleIdentifier`
128
+
129
+ ios_bundle_id.should.match /org.cocoapods.KFData/
130
+ osx_bundle_id.should.match /org.cocoapods.KFData/
131
+ end
132
+
133
+ it "should produce the correct plist for iOS and OSX when --dynamic and --bundle-identifier are specified" do
134
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
135
+
136
+ command = Command.parse(['package', fixture('KFData.podspec'), '--dynamic', '--bundle-identifier=com.example.KFData'])
137
+ command.run
138
+
139
+ ios_plist = File.expand_path(Dir.glob("KFData-*/ios/KFData.framework/Info.plist").first)
140
+ osx_plist = File.expand_path(Dir.glob("KFData-*/osx/KFData.framework/Resources/Info.plist").first)
141
+
142
+ ios_bundle_id = `defaults read #{ios_plist} CFBundleIdentifier`
143
+ osx_bundle_id = `defaults read #{osx_plist} CFBundleIdentifier`
144
+
145
+ ios_bundle_id.should.match /com.example.KFData/
146
+ osx_bundle_id.should.match /com.example.KFData/
147
+ end
148
+
149
+ it "should produce a static library when dynamic is not specified" do
150
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
151
+
152
+ command = Command.parse(['package', fixture('NikeKit.podspec')])
153
+ command.run
154
+
155
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
156
+ file_command = "file #{lib}"
157
+ output = `#{file_command}`.lines.to_a
158
+
159
+ output[0].should.match /Mach-O universal binary with 5 architectures/
160
+ output[1].should.match /current ar archive/
161
+ end
162
+
163
+ it "produces package using local sources when --local is specified" do
164
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
165
+
166
+ command = Command.parse(['package', fixture('LocalSources/LocalNikeKit.podspec'), '--local'])
167
+ command.run
168
+
169
+ lib = Dir.glob("LocalNikeKit-*/ios/LocalNikeKit.framework/LocalNikeKit").first
170
+ symbols = Symbols.symbols_from_library(lib)
171
+ symbols.should.include('LocalNikeKit')
172
+ symbols.should.not.include('BBUNikePlusActivity')
173
+ end
174
+
175
+ it "includes vendor symbols both from itself and pod dependencies" do
176
+ command = Command.parse(%w{ package FirebaseAnalytics --no-mangle })
177
+ command.run
178
+
179
+ lib = Dir.glob("FirebaseAnalytics-*/ios/FirebaseAnalytics.framework/FirebaseAnalytics").first
180
+ symbols = Symbols.symbols_from_library(lib)
181
+ # from itself
182
+ symbols.should.include('FIRAnalytics')
183
+ # from pod dependency
184
+ symbols.should.include('FIRApp')
185
+ end
186
+
187
+ it "does not include vendor symbols from pod dependencies if option --exclude-deps is specified" do
188
+ command = Command.parse(%w{ package FirebaseAnalytics --no-mangle --exclude-deps})
189
+ command.run
190
+
191
+ lib = Dir.glob("FirebaseAnalytics-*/ios/FirebaseAnalytics.framework/FirebaseAnalytics").first
192
+ symbols = Symbols.symbols_from_library(lib)
193
+ # from itself
194
+ symbols.should.include('FIRAnalytics')
195
+ # from pod dependency
196
+ symbols.should.not.include('FIRApp')
197
+ end
198
+
199
+ it "includes only available architectures when packaging an iOS Pod with binary dependencies" do
200
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
201
+
202
+ command = Command.parse(['package', fixture('Archs.podspec'), '--no-mangle'])
203
+ command.run
204
+
205
+ lib = Dir.glob("Archs-*/ios/Archs.framework/Archs").first
206
+ `lipo #{lib} -verify_arch x86_64 i386 armv7 arm64`
207
+ $?.success?.should == true
208
+ end
209
+
210
+ it "mangles symbols if the Pod has dependencies" do
211
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
212
+
213
+ command = Command.parse(['package', fixture('NikeKit.podspec')])
214
+ command.run
215
+
216
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
217
+ symbols = Symbols.symbols_from_library(lib).uniq.sort.reject { |e| e =~ /PodNikeKit/ }
218
+ symbols = reject_block_symbols(symbols)
219
+
220
+ symbols.should == %w{ BBUNikePlusActivity BBUNikePlusSessionManager
221
+ BBUNikePlusTag }
222
+ end
223
+
224
+ it "mangles symbols if the Pod has dependencies and framework is dynamic" do
225
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
226
+
227
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--dynamic'])
228
+ command.run
229
+
230
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
231
+ symbols = Symbols.symbols_from_library(lib).uniq.sort.reject { |e| e =~ /PodNikeKit/ }
232
+ symbols = reject_block_symbols(symbols)
233
+
234
+ symbols.should == %w{ BBUNikePlusActivity BBUNikePlusSessionManager
235
+ BBUNikePlusTag NikeKitVersionNumber NikeKitVersionString }
236
+ end
237
+
238
+ it "mangles symbols if the Pod has dependencies regardless of name" do
239
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
240
+
241
+ command = Command.parse(['package', fixture('a.podspec')])
242
+ command.run
243
+
244
+ lib = Dir.glob("a-*/ios/a.framework/a").first
245
+ symbols = Symbols.symbols_from_library(lib).uniq.sort.reject { |e| e =~ /Poda/ }
246
+ symbols = reject_block_symbols(symbols)
247
+ symbols.should == %w{ BBUNikePlusActivity BBUNikePlusSessionManager
248
+ BBUNikePlusTag }
249
+ end
250
+
251
+ it "does not mangle symbols if option --no-mangle is specified" do
252
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
253
+
254
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--no-mangle'])
255
+ command.run
256
+
257
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
258
+ symbols = Symbols.symbols_from_library(lib).uniq.sort.select { |e| e =~ /PodNikeKit/ }
259
+ symbols.should == []
260
+ end
261
+
262
+ it "does not mangle symbols if option --no-mangle and --dynamic are specified" do
263
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
264
+
265
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--no-mangle', '--dynamic'])
266
+ command.run
267
+
268
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
269
+ symbols = Symbols.symbols_from_library(lib).uniq.sort.select { |e| e =~ /PodNikeKit/ }
270
+ symbols.should == []
271
+ end
272
+
273
+ it "does not include symbols from dependencies if option --exclude-deps is specified" do
274
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
275
+
276
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--exclude-deps'])
277
+ command.run
278
+
279
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
280
+ symbols = Symbols.symbols_from_library(lib).uniq.sort.select { |e| e =~ /AFNetworking|ISO8601DateFormatter|KZPropertyMapper/ }
281
+ symbols.should == []
282
+ end
283
+
284
+ it "includes the correct architectures when packaging an iOS Pod" do
285
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
286
+
287
+ command = Command.parse(['package', fixture('NikeKit.podspec')])
288
+ command.run
289
+
290
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
291
+ `lipo #{lib} -verify_arch x86_64 i386 armv7 armv7s arm64`
292
+ $?.success?.should == true
293
+ end
294
+
295
+ it "includes the correct architectures when packaging an iOS Pod as --dynamic" do
296
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
297
+
298
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--dynamic'])
299
+ command.run
300
+
301
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
302
+ `lipo #{lib} -verify_arch armv7 armv7s arm64`
303
+ $?.success?.should == true
304
+ end
305
+
306
+ it "includes Bitcode for device arch slices when packaging an iOS Pod" do
307
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
308
+
309
+ command = Command.parse(['package', fixture('NikeKit.podspec')])
310
+ command.run
311
+
312
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
313
+
314
+ #Check for __LLVM segment in each device architecture
315
+ `lipo -extract armv7 #{lib} -o armv7.a && otool -l armv7.a`.should.match /__LLVM/
316
+ `lipo -extract armv7s #{lib} -o armv7s.a && otool -l armv7s.a`.should.match /__LLVM/
317
+ `lipo -extract arm64 #{lib} -o arm64.a && otool -l arm64.a`.should.match /__LLVM/
318
+ `rm armv7.a armv7s.a arm64.a`
319
+ end
320
+
321
+ it "includes Bitcode for device arch slices when packaging an dynamic iOS Pod" do
322
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
323
+
324
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--dynamic'])
325
+ command.run
326
+
327
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
328
+
329
+ #Check for __LLVM segment in each device architecture
330
+ `lipo -extract armv7 #{lib} -o armv7.a && otool -l armv7.a`.should.match /__LLVM/
331
+ `lipo -extract armv7s #{lib} -o armv7s.a && otool -l armv7s.a`.should.match /__LLVM/
332
+ `lipo -extract arm64 #{lib} -o arm64.a && otool -l arm64.a`.should.match /__LLVM/
333
+ `rm armv7.a armv7s.a arm64.a`
334
+ end
335
+
336
+ it "does not include Bitcode for simulator arch slices when packaging an iOS Pod" do
337
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
338
+
339
+ command = Command.parse(['package', fixture('NikeKit.podspec')])
340
+ command.run
341
+
342
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
343
+
344
+ #Check for __LLVM segment in each simulator architecture
345
+ `lipo -extract i386 #{lib} -o i386.a && otool -l i386.a`.should.not.match /__LLVM/
346
+ `lipo -extract x86_64 #{lib} -o x86_64.a && otool -l x86_64.a`.should.not.match /__LLVM/
347
+ `rm i386.a x86_64.a`
348
+ end
349
+
350
+ it "does not include Bitcode for simulator arch slices when packaging an dynamic iOS Pod" do
351
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
352
+
353
+ command = Command.parse(['package', fixture('NikeKit.podspec'), '--dynamic'])
354
+ command.run
355
+
356
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
357
+
358
+ #Check for __LLVM segment in each simulator architecture
359
+ `lipo -extract i386 #{lib} -o i386.a && otool -l i386.a`.should.not.match /__LLVM/
360
+ `lipo -extract x86_64 #{lib} -o x86_64.a && otool -l x86_64.a`.should.not.match /__LLVM/
361
+ `rm i386.a x86_64.a`
362
+ end
363
+
364
+ it "does not include local ModuleCache references" do
365
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
366
+
367
+ command = Command.parse(['package', fixture('NikeKit.podspec')])
368
+ command.run
369
+
370
+ lib = Dir.glob("NikeKit-*/ios/NikeKit.framework/NikeKit").first
371
+
372
+ #Check for ModuleCache references
373
+ `strings #{lib}`.should.not.match /ModuleCache/
374
+ end
375
+
376
+ it "does not fail when the pod name contains a dash" do
377
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
378
+
379
+ command = Command.parse(['package', fixture('foo-bar.podspec')])
380
+ command.run
381
+
382
+ true.should == true # To make the test pass without any shoulds
383
+ end
384
+
385
+ it "runs with a path to a spec" do
386
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
387
+
388
+ command = Command.parse(['package', fixture('KFData.podspec')])
389
+ command.run
390
+
391
+ true.should == true # To make the test pass without any shoulds
392
+ end
393
+
394
+ it "it respects module_map directive" do
395
+ Pod::Config.instance.sources_manager.stubs(:search).returns(nil)
396
+
397
+ command = Command.parse(['package', fixture('FH.podspec')])
398
+ command.run
399
+
400
+ modulemap_contents = File.read(Dir.glob("FH-*/ios/FH.framework/Modules/module.modulemap").first)
401
+ module_map = <<MAP
402
+ framework module FH {
403
+ umbrella header "FeedHenry.h"
404
+
405
+ export *
406
+ module * { export * }
407
+ }
408
+ MAP
409
+ modulemap_contents.should == module_map
410
+ end
411
+
412
+ it "runs with a spec in the master repository" do
413
+ command = Command.parse(%w{ package KFData })
414
+ command.run
415
+
416
+ true.should == true # To make the test pass without any shoulds
417
+ end
418
+ end
419
+ end
420
+ end