cocoapods-packager-mls 1.5.0.21

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 (79) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +5 -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 +131 -0
  9. data/LICENSE +22 -0
  10. data/README.md +42 -0
  11. data/Rakefile +29 -0
  12. data/cocoapods-packager.gemspec +22 -0
  13. data/lib/cocoapods-packager/builder.rb +457 -0
  14. data/lib/cocoapods-packager/framework.rb +66 -0
  15. data/lib/cocoapods-packager/mangle.rb +32 -0
  16. data/lib/cocoapods-packager/pod_utils.rb +324 -0
  17. data/lib/cocoapods-packager/spec_builder.rb +171 -0
  18. data/lib/cocoapods-packager/symbols.rb +42 -0
  19. data/lib/cocoapods-packager/tal_installer.rb +33 -0
  20. data/lib/cocoapods-packager/tal_target_validator.rb +62 -0
  21. data/lib/cocoapods-packager/user_interface/build_failed_report.rb +15 -0
  22. data/lib/cocoapods_packager.rb +5 -0
  23. data/lib/cocoapods_plugin.rb +16 -0
  24. data/lib/pod/command/package.rb +243 -0
  25. data/scripts/lstconst.sh +9 -0
  26. data/scripts/lstsym.sh +8 -0
  27. data/spec/command/error_spec.rb +81 -0
  28. data/spec/command/package_spec.rb +420 -0
  29. data/spec/command/subspecs_spec.rb +30 -0
  30. data/spec/fixtures/Archs.podspec +13 -0
  31. data/spec/fixtures/Builder.podspec +25 -0
  32. data/spec/fixtures/CPDColors.podspec +19 -0
  33. data/spec/fixtures/FH.podspec +18 -0
  34. data/spec/fixtures/KFData.podspec +73 -0
  35. data/spec/fixtures/LibraryConsumerDemo/.gitignore +22 -0
  36. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer.xcodeproj/project.pbxproj +311 -0
  37. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  38. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer.xcodeproj/xcshareddata/xcschemes/LibraryConsumer.xcscheme +100 -0
  39. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/AppDelegate.h +17 -0
  40. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/AppDelegate.m +27 -0
  41. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/Info.plist +40 -0
  42. data/spec/fixtures/LibraryConsumerDemo/LibraryConsumer/main.m +16 -0
  43. data/spec/fixtures/LibraryConsumerDemo/Podfile +5 -0
  44. data/spec/fixtures/LibraryDemo.podspec +14 -0
  45. data/spec/fixtures/LocalSources/LICENSE +0 -0
  46. data/spec/fixtures/LocalSources/LocalNikeKit.h +4 -0
  47. data/spec/fixtures/LocalSources/LocalNikeKit.m +9 -0
  48. data/spec/fixtures/LocalSources/LocalNikeKit.podspec +19 -0
  49. data/spec/fixtures/NikeKit.podspec +19 -0
  50. data/spec/fixtures/OpenSans.podspec +18 -0
  51. data/spec/fixtures/PackagerTest/.gitignore +21 -0
  52. data/spec/fixtures/PackagerTest/PackagerTest.xcodeproj/project.pbxproj +507 -0
  53. data/spec/fixtures/PackagerTest/PackagerTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  54. data/spec/fixtures/PackagerTest/PackagerTest.xcodeproj/xcshareddata/xcschemes/PackagerTest.xcscheme +110 -0
  55. data/spec/fixtures/PackagerTest/PackagerTest.xcworkspace/contents.xcworkspacedata +1 -0
  56. data/spec/fixtures/PackagerTest/PackagerTest/CPDAppDelegate.h +15 -0
  57. data/spec/fixtures/PackagerTest/PackagerTest/CPDAppDelegate.m +49 -0
  58. data/spec/fixtures/PackagerTest/PackagerTest/Images.xcassets/AppIcon.appiconset/Contents.json +23 -0
  59. data/spec/fixtures/PackagerTest/PackagerTest/Images.xcassets/LaunchImage.launchimage/Contents.json +23 -0
  60. data/spec/fixtures/PackagerTest/PackagerTest/PackagerTest-Info.plist +38 -0
  61. data/spec/fixtures/PackagerTest/PackagerTest/PackagerTest-Prefix.pch +16 -0
  62. data/spec/fixtures/PackagerTest/PackagerTest/en.lproj/InfoPlist.strings +2 -0
  63. data/spec/fixtures/PackagerTest/PackagerTest/main.m +18 -0
  64. data/spec/fixtures/PackagerTest/PackagerTestTests/PackagerTestTests-Info.plist +22 -0
  65. data/spec/fixtures/PackagerTest/PackagerTestTests/PackagerTestTests.m +34 -0
  66. data/spec/fixtures/PackagerTest/PackagerTestTests/en.lproj/InfoPlist.strings +2 -0
  67. data/spec/fixtures/PackagerTest/Podfile +10 -0
  68. data/spec/fixtures/PackagerTest/Podfile.lock +36 -0
  69. data/spec/fixtures/Weakly.podspec +13 -0
  70. data/spec/fixtures/a.podspec +19 -0
  71. data/spec/fixtures/foo-bar.podspec +19 -0
  72. data/spec/fixtures/layer-client-messaging-schema.podspec +13 -0
  73. data/spec/integration/project_spec.rb +70 -0
  74. data/spec/spec_helper.rb +79 -0
  75. data/spec/unit/pod/utils_spec.rb +58 -0
  76. data/spec/unit/specification/builder_spec.rb +62 -0
  77. data/spec/unit/specification/spec_builder_spec.rb +61 -0
  78. data/spec/unit/user_interface/build_failed_report_spec.rb +11 -0
  79. metadata +223 -0
@@ -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
@@ -0,0 +1,33 @@
1
+ module Pod
2
+ class TalInstaller < Installer
3
+ def initialize(sandbox, podfile, auto_fix_conflict = true, lockfile = nil)
4
+ @sandbox = sandbox
5
+ @podfile = podfile
6
+ @lockfile = lockfile
7
+ @auto_fix_conflict = auto_fix_conflict
8
+
9
+ @use_default_plugins = true
10
+ @has_dependencies = true
11
+ super(sandbox, podfile, lockfile)
12
+ end
13
+
14
+ def install!
15
+ prepare
16
+ resolve_dependencies
17
+ download_dependencies
18
+ validate_targets_remove_confilict
19
+ generate_pods_project
20
+ if installation_options.integrate_targets?
21
+ integrate_user_project
22
+ else
23
+ UI.section 'Skipping User Project Integration'
24
+ end
25
+ perform_post_install_actions
26
+ end
27
+
28
+ def validate_targets_remove_confilict
29
+ validator = Xcode::TalTargetValidator.new(aggregate_targets, pod_targets, @auto_fix_conflict)
30
+ validator.validate!
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,62 @@
1
+ module Pod
2
+ class Installer
3
+ class Xcode
4
+ class TalTargetValidator < TargetValidator
5
+
6
+ def initialize(aggregate_targets, pod_targets, auto_fix_conflict = true)
7
+ @aggregate_targets = aggregate_targets
8
+ @pod_targets = pod_targets
9
+ @auto_fix_conflict = auto_fix_conflict
10
+ super(aggregate_targets, pod_targets)
11
+ end
12
+
13
+ def verify_no_duplicate_framework_and_library_names
14
+ aggregate_targets.each do |aggregate_target|
15
+ aggregate_target.user_build_configurations.keys.each do |config|
16
+ pod_targets = aggregate_target.pod_targets_for_build_configuration(config)
17
+ file_accessors = pod_targets.flat_map(&:file_accessors)
18
+
19
+ frameworks = file_accessors.flat_map(&:vendored_frameworks).uniq.map(&:basename)
20
+ frameworks += pod_targets.select { |pt| pt.should_build? && pt.requires_frameworks? }.map(&:product_module_name).uniq
21
+ verify_no_duplicate_names(frameworks, aggregate_target, 'frameworks', file_accessors)
22
+
23
+ libraries = file_accessors.flat_map(&:vendored_libraries).uniq.map(&:basename)
24
+ libraries += pod_targets.select { |pt| pt.should_build? && !pt.requires_frameworks? }.map(&:product_name)
25
+ verify_no_duplicate_names(libraries, aggregate_target, 'libraries', file_accessors)
26
+ end
27
+ end
28
+ end
29
+
30
+ def verify_no_duplicate_names(names, aggregate_target, type, file_accessors)
31
+ duplicates = names.map { |n| n.to_s.downcase }.group_by { |f| f }.select { |_, v| v.size > 1 }.keys
32
+
33
+ if !duplicates.empty? && @auto_fix_conflict
34
+ # 移除冲突文件
35
+ duplicate_files = Array.new
36
+ duplicates.each do |d|
37
+ tmp_duplicate = file_accessors.flat_map(&:vendored_libraries).uniq.find_all { |p|
38
+ d == p.basename.to_s && File.exist?(p)
39
+ }.sort || []
40
+ duplicate_files << tmp_duplicate
41
+ end
42
+
43
+ duplicate_files.each do |dfs|
44
+ if dfs.count > 1
45
+ dfs.pop
46
+ dfs.each do |file|
47
+ puts "remove confliting file #{file}"
48
+ FileUtils.rm(file) if File.exist?(file)
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ if duplicates.empty? && !@auto_fix_conflict
55
+ raise Informative, "The '#{aggregate_target.label}' target has " \
56
+ "#{type} with conflicting names: #{duplicates.to_sentence}."
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -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.5.0.21'.freeze
4
+ end
5
+ end
@@ -0,0 +1,16 @@
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'
9
+ require 'cocoapods-packager/tal_installer'
10
+ require 'cocoapods-packager/tal_target_validator'
11
+
12
+ # module CocoapodsPackager
13
+ # Pod::HooksManager.register('cocoapods-packager', :pre_install) do |context|
14
+ # # do some thing
15
+ # end
16
+ # end
@@ -0,0 +1,243 @@
1
+ require 'tmpdir'
2
+ require 'fileutils'
3
+ module Pod
4
+ class Command
5
+ class Package < Command
6
+ self.summary = 'Package a podspec into a static library.'
7
+ self.arguments = [
8
+ CLAide::Argument.new('NAME', true),
9
+ CLAide::Argument.new('SOURCE', false),
10
+ CLAide::Argument.new('OPTIONS', false)
11
+ ]
12
+
13
+ def self.options
14
+ [
15
+ ['--force', 'Overwrite existing files.'],
16
+ ['--no-mangle', 'Do not mangle symbols of depedendant Pods.'],
17
+ ['--embedded', 'Generate embedded frameworks.'],
18
+ ['--library', 'Generate static libraries.'],
19
+ ['--dynamic', 'Generate dynamic framework.'],
20
+ ['--local', 'Use local state rather than published versions.'],
21
+ ['--bundle-identifier', 'Bundle identifier for dynamic framework'],
22
+ ['--exclude-deps', 'Exclude symbols from dependencies. default true'],
23
+ ['--include-deps', 'Include symbols from dependencies. default false'],
24
+ ['--configuration', 'Build the specified configuration (e.g. Debug). Defaults to Release'],
25
+ ['--subspecs', 'Only include the given subspecs'],
26
+ ['--spec-sources=private,https://github.com/CocoaPods/Specs.git', 'The sources to pull dependent ' \
27
+ 'pods from (defaults to https://github.com/CocoaPods/Specs.git)'],
28
+ ['--auto-fix-conflict', 'fix cocoapods conflict .a or .framework , default is true'],
29
+ ['--local-sources=./', '相对 podspec 路径,Paths from which to find local podspecs for transitive dependencies. Multiple local-sources must be comma-delimited.' \
30
+ 'pods from local'],
31
+ ['--no-repos', '不自动添加 pod repo list 显示出的 source'],
32
+ ['--repo-update', 'update repo'],
33
+ ['--work-dir', 'the dir when build '],
34
+ ['--git-source', 'framework podspec s.source= '],
35
+ ['--output-dsym', 'generate dSYM file'],
36
+ ['--xcconfig-path', 'xcode build xcconfig path'],
37
+ ['--disable-force-load', 'do not add -force_load flag in spec file xcconfig , default is false'],
38
+ ['--force-enable-module', 'force create module map file in framework, default if public headers contains \#{spec.name}.h will create umbrella header and module map'],
39
+ ]
40
+ end
41
+
42
+ def initialize(argv)
43
+ @embedded = argv.flag?('embedded')
44
+ @library = argv.flag?('library')
45
+ @dynamic = argv.flag?('dynamic')
46
+ @local = argv.flag?('local', false)
47
+ @output_dsym = argv.flag?('output-dsym', true)
48
+ @package_type = if @embedded
49
+ :static_framework
50
+ elsif @dynamic
51
+ :dynamic_framework
52
+ elsif @library
53
+ :static_library
54
+ else
55
+ :static_framework
56
+ end
57
+ @force = argv.flag?('force')
58
+ @mangle = argv.flag?('mangle', true)
59
+ @bundle_identifier = argv.option('bundle-identifier', nil)
60
+ @include_deps = argv.flag?('include-deps', false)
61
+ @exclude_deps = argv.flag?('exclude-deps', !@include_deps)
62
+ @auto_fix_conflict = argv.flag?('auto-fix-conflict', true)
63
+ @disable_force_load = argv.flag?('disable-force-load', false)
64
+ @force_enable_module = argv.flag?('force-enable-module', false)
65
+ @name = argv.shift_argument
66
+ @source = argv.shift_argument
67
+ @spec_sources = argv.option('spec-sources', 'https://github.com/CocoaPods/Specs.git').split(',')
68
+ @local_sources = argv.option('local-sources', '').split(',')
69
+ @no_repos = argv.flag?('no-repos', false)
70
+ @repo_update = argv.flag?('repo-update', false)
71
+ @work_dir = argv.option('work-dir', Dir.tmpdir)
72
+ @git_source = argv.option('git-source', nil)
73
+ @xcconfig_path = argv.option('xcconfig-path', nil)
74
+ subspecs = argv.option('subspecs')
75
+ @subspecs = subspecs.split(',') unless subspecs.nil?
76
+
77
+ @config = argv.option('configuration', 'Release')
78
+
79
+ @source_dir = Dir.pwd
80
+ @is_spec_from_path = false
81
+ @spec = spec_with_path(@name)
82
+ @is_spec_from_path = true if @spec
83
+ @spec ||= spec_with_name(@name)
84
+
85
+ @source = "{ :git => \"#{@git_source}\", :tag => s.version.to_s }" unless @git_source.nil?
86
+
87
+ super
88
+ end
89
+
90
+ def validate!
91
+ super
92
+ help! 'A podspec name or path is required.' unless @spec
93
+ help! 'podspec has binary-only depedencies, mangling not possible.' if @mangle && binary_only?(@spec)
94
+ help! '--bundle-identifier option can only be used for dynamic frameworks' if @bundle_identifier && !@dynamic
95
+ help! '--exclude-deps option can only be used for static libraries' if @exclude_deps && @dynamic
96
+ help! '--local option can only be used when a local `.podspec` path is given.' if @local && !@is_spec_from_path
97
+ end
98
+
99
+ def run
100
+ if @spec.nil?
101
+ help! "Unable to find a podspec with path or name `#{@name}`."
102
+ return
103
+ end
104
+
105
+ if !@no_repos
106
+ if @spec_sources.nil?
107
+ @spec_sources = []
108
+ end
109
+ config.sources_manager.all.each do |s|
110
+ @spec_sources << s.url
111
+ end
112
+ end
113
+
114
+ if @repo_update
115
+ update_sources
116
+ end
117
+
118
+ target_dir, work_dir = create_working_directory
119
+ return if target_dir.nil?
120
+ build_package
121
+
122
+ `mv "#{work_dir}" "#{target_dir}"`
123
+ Dir.chdir(@source_dir)
124
+ end
125
+
126
+ def update_sources
127
+ UI.title 'Updating specs repos' do
128
+ @spec_sources.each do |source|
129
+ source = config.sources_manager.source_with_name_or_url(source)
130
+ UI.titled_section "Updating spec repo `#{source.name}`" do
131
+ source.update(config.verbose?)
132
+ source.verify_compatibility!
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ private
139
+
140
+ def build_in_sandbox(platform)
141
+ config.installation_root = Pathname.new(Dir.pwd)
142
+ config.sandbox_root = 'Pods'
143
+
144
+ static_sandbox = build_static_sandbox(@dynamic)
145
+ static_installer = install_pod(platform.name, static_sandbox)
146
+
147
+ if @dynamic
148
+ dynamic_sandbox = build_dynamic_sandbox(static_sandbox, static_installer)
149
+ install_dynamic_pod(dynamic_sandbox, static_sandbox, static_installer, platform)
150
+ end
151
+
152
+ begin
153
+ perform_build(platform, static_sandbox, dynamic_sandbox, static_installer)
154
+ ensure # in case the build fails; see Builder#xcodebuild.
155
+ Pathname.new(config.sandbox_root).rmtree
156
+ FileUtils.rm_f('Podfile.lock')
157
+ end
158
+ end
159
+
160
+ def build_package
161
+ builder = SpecBuilder.new(@spec, @source, @embedded, @dynamic, !@disable_force_load)
162
+ newspec = builder.spec_metadata
163
+
164
+ @spec.available_platforms.each do |platform|
165
+ build_in_sandbox(platform)
166
+
167
+ newspec += builder.spec_platform(platform)
168
+ end
169
+
170
+ newspec += builder.spec_close
171
+ File.open(@spec.name + '.podspec', 'w') { |file| file.write(newspec) }
172
+ end
173
+
174
+ def create_target_directory
175
+ target_dir = "#{@source_dir}/#{@spec.name}-#{@spec.version}"
176
+ if File.exist? target_dir
177
+ if @force
178
+ Pathname.new(target_dir).rmtree
179
+ else
180
+ UI.puts "Target directory '#{target_dir}' already exists."
181
+ return nil
182
+ end
183
+ end
184
+ target_dir
185
+ end
186
+
187
+ def create_working_directory
188
+ target_dir = create_target_directory
189
+ return if target_dir.nil?
190
+ rootDir = @work_dir
191
+ if rootDir[0] != '/'
192
+ rootDir = File.expand_path(rootDir,@source_dir)
193
+ end
194
+ if rootDir.nil?
195
+ rootDir = Dir.tmpdir
196
+ end
197
+
198
+ # work_dir = rootDir + '/cocoapods-' + Array.new(8) { rand(36).to_s(36) }.join
199
+ work_dir = rootDir + '/cocoapods-packager-build'
200
+ if File.exist?(work_dir)
201
+ FileUtils.rm_rf(work_dir)
202
+ end
203
+ # Pathname.new(work_dir).mkdir
204
+ FileUtils.mkdir_p(work_dir)
205
+ Dir.chdir(work_dir)
206
+
207
+ [target_dir, work_dir]
208
+ end
209
+
210
+ def perform_build(platform, static_sandbox, dynamic_sandbox, static_installer)
211
+ static_sandbox_root = config.sandbox_root.to_s
212
+
213
+ if @dynamic
214
+ static_sandbox_root = "#{static_sandbox_root}/#{static_sandbox.root.to_s.split('/').last}"
215
+ dynamic_sandbox_root = "#{config.sandbox_root}/#{dynamic_sandbox.root.to_s.split('/').last}"
216
+ end
217
+
218
+ builder = Pod::Builder.new(
219
+ platform,
220
+ static_installer,
221
+ @source_dir,
222
+ static_sandbox_root,
223
+ dynamic_sandbox_root,
224
+ static_sandbox.public_headers.root,
225
+ @spec,
226
+ @embedded,
227
+ @mangle,
228
+ @dynamic,
229
+ @config,
230
+ @bundle_identifier,
231
+ @exclude_deps,
232
+ @xcconfig_path,
233
+ @force_enable_module
234
+ )
235
+
236
+ builder.build(@package_type)
237
+
238
+ return unless @embedded
239
+ builder.link_embedded_resources
240
+ end
241
+ end
242
+ end
243
+ 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-