Class: Pod::Command::Package
- Inherits:
-
Object
- Object
- Pod::Command::Package
- Defined in:
- lib/cocoapods-packager-ext/command/package_ext.rb,
lib/cocoapods-packager-ext/ext/pod_utils.rb
Overview
Create a PR to add your plugin to CocoaPods/cocoapods.org in the ‘plugins.json` file, once your plugin is released.
This is an example of a cocoapods plugin adding a top-level subcommand to the ‘pod’ command.
You can also create subcommands of existing or new commands. Say you wanted to add a subcommand to ‘list` to show newly deprecated pods, (e.g. `pod list deprecated`), there are a few things that would need to change.
-
move this file to ‘lib/pod/command/list/deprecated.rb` and update the class to exist in the the Pod::Command::List namespace
-
change this class to extend from ‘List` instead of `Command`. This tells the plugin system that it is a subcommand of `list`.
-
edit ‘lib/cocoapods_plugins.rb` to require this file
Instance Method Summary collapse
- #build_dynamic_target(dynamic_sandbox, static_installer, platform) ⇒ Object
- #build_dynamic_target_t ⇒ Pod::PodTarget
- #build_in_sandbox(platform) ⇒ Object
- #build_in_sandbox_t ⇒ Object
- #build_package ⇒ Object
- #build_package_t ⇒ Object
- #clean_dummy_files(path) ⇒ Object
- #copy_dynamic_target(static_sandbox, _dynamic_target, dynamic_sandbox) ⇒ Object
- #copy_dynamic_target_t ⇒ Object
-
#initialize(argv) ⇒ Package
constructor
A new instance of Package.
- #initialize_t ⇒ Object
- #install_pod(platform_name, sandbox) ⇒ Object
- #install_pod_t ⇒ Object
- #ln_source_to_dynamic_target(static_installer, dynamic_sandbox) ⇒ Object
- #perform_build(platform, static_sandbox, dynamic_sandbox, static_installer) ⇒ Object
- #perform_build_t ⇒ Object
- #podfile_from_spec_sandbox(path, spec_name, platform_name, deployment_target, subspecs, sources, sandbox) ⇒ Object
- #pre_podfile(path, sandbox) ⇒ Object
- #spec_framework(platform) ⇒ Object
- #spec_library(platform) ⇒ Object
- #write_pod_project(dynamic_project, dynamic_sandbox) ⇒ Object
- #write_pod_project_t ⇒ Object
Constructor Details
#initialize(argv) ⇒ Package
Returns a new instance of Package.
45 46 47 48 49 50 51 52 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 45 def initialize(argv) @exclude_dep_items = argv.option('exclude-deps','').split(',') @select_archs = argv.option('archs','').split(',') @podfile = argv.option('podfile' ) @platform = argv.option('platform','') @update = argv.flag?('update',false ) initialize_t argv end |
Instance Method Details
#build_dynamic_target(dynamic_sandbox, static_installer, platform) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 12 def build_dynamic_target(dynamic_sandbox, static_installer, platform) spec_targets = static_installer.pod_targets.select do |target| target.name == @spec.name end static_target = spec_targets[0] file_accessors = create_file_accessors(static_target, dynamic_sandbox) archs = [] dynamic_target = Pod::PodTarget.new(dynamic_sandbox, BuildType.dynamic_framework, static_target.user_build_configurations, archs, platform, static_target.specs, static_target.target_definitions, file_accessors) ln_source_to_dynamic_target(static_installer,dynamic_sandbox) dynamic_target end |
#build_dynamic_target_t ⇒ Pod::PodTarget
10 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 10 alias build_dynamic_target_t build_dynamic_target |
#build_in_sandbox(platform) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 55 def build_in_sandbox(platform) config.installation_root = Pathname.new(Dir.pwd) config.sandbox_root = 'Pods' static_sandbox = build_static_sandbox(@dynamic) static_installer = install_pod(platform.name, static_sandbox) if @dynamic dynamic_sandbox = build_dynamic_sandbox(static_sandbox, static_installer) install_dynamic_pod(dynamic_sandbox, static_sandbox, static_installer, platform) end begin perform_build(platform, static_sandbox, dynamic_sandbox, static_installer) ensure # in case the build fails; see Builder#xcodebuild. if ENV['ENABLE_BACKUP_WORKSPACE'] && (ENV['ENABLE_BACKUP_WORKSPACE'].upcase == 'YES' || ENV['ENABLE_BACKUP_WORKSPACE'].upcase == 'TRUE') UI. 'Backup Workspace' else UI. 'Delete Workspace' Pathname.new(config.sandbox_root).rmtree FileUtils.rm_f('Podfile.lock') end end end |
#build_in_sandbox_t ⇒ Object
54 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 54 alias build_in_sandbox_t build_in_sandbox |
#build_package ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 101 def build_package if @platform == '' build_package_t else builder = SpecBuilder.new(@spec, @source, @embedded, @dynamic) newspec = builder. @spec.available_platforms.each do |platform| if @platform.include?(platform.name.to_s) UI.puts 'build package platform:'+platform.name.to_s build_in_sandbox(platform) if @library newspec += spec_library(platform) else newspec += builder.spec_platform(platform) end else UI.puts 'jump build platforms:'+platform.to_s end end newspec += builder.spec_close File.open(@spec.name + '.podspec', 'w') { |file| file.write(newspec) } end end |
#build_package_t ⇒ Object
100 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 100 alias build_package_t build_package |
#clean_dummy_files(path) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 130 def clean_dummy_files(path) Dir.entries(path).each do |sub| if sub != '.' && sub != '..' if File.directory?("#{path}/#{sub}") clean_dummy_files("#{path}/#{sub}") else if(sub =~ /-dummy.m$/) File.open("#{path}/#{sub}",'w')do |file| file.write('') UI. " - clean dummy file:#{sub}" end end end end end end |
#copy_dynamic_target(static_sandbox, _dynamic_target, dynamic_sandbox) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 26 def copy_dynamic_target(static_sandbox, _dynamic_target, dynamic_sandbox) if Dir.exist? static_sandbox.root+@spec.name command = "ln -sf #{static_sandbox.root}/#{@spec.name} #{dynamic_sandbox.root}" `#{command}` end end |
#copy_dynamic_target_t ⇒ Object
25 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 25 alias copy_dynamic_target_t copy_dynamic_target |
#initialize_t ⇒ Object
44 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 44 alias initialize_t initialize |
#install_pod(platform_name, sandbox) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 235 def install_pod(platform_name, sandbox) if !@podfile && !@update install_pod_t platform_name,sandbox else if not @podfile podfile = podfile_from_spec( @path, @spec.name, platform_name, @spec.deployment_target(platform_name), @subspecs, @spec_sources ) else podfile = podfile_from_spec_sandbox( @path, @spec.name, platform_name, @spec.deployment_target(platform_name), @subspecs, @spec_sources, sandbox ) end static_installer = Installer.new(sandbox, podfile) if @update static_installer.repo_update = true end static_installer.install! unless static_installer.nil? static_installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO' config.build_settings['GCC_GENERATE_DEBUGGING_SYMBOLS'] = 'NO' end end static_installer.pods_project.save end static_installer end end |
#install_pod_t ⇒ Object
234 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 234 alias install_pod_t install_pod |
#ln_source_to_dynamic_target(static_installer, dynamic_sandbox) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 33 def ln_source_to_dynamic_target(static_installer, dynamic_sandbox) if not Dir.exist? static_installer.sandbox.root+@spec.name file_accessors = static_installer.pod_targets.select { |t| t.pod_name == @spec.name }.flat_map(&:file_accessors) if file_accessors && file_accessors.length > 0 source_root = file_accessors[0].path_list.root command = "ln -sf #{source_root} #{dynamic_sandbox.root}/#{@spec.name}" `#{command}` else UI.puts "#{@spec.name} 根目录找不到" end end end |
#perform_build(platform, static_sandbox, dynamic_sandbox, static_installer) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 148 def perform_build(platform, static_sandbox, dynamic_sandbox,static_installer) if @select_archs.length > 0 || @exclude_dep_items.length > 0 static_sandbox_root = config.sandbox_root.to_s if @dynamic static_sandbox_root = "#{static_sandbox_root}/#{static_sandbox.root.to_s.split('/').last}" dynamic_sandbox_root = "#{config.sandbox_root}/#{dynamic_sandbox.root.to_s.split('/').last}" end if (ENV['ENABLE_CLEAN_DUMMY_FILE'] && (ENV['ENABLE_CLEAN_DUMMY_FILE'].upcase == 'YES' || ENV['ENABLE_CLEAN_DUMMY_FILE'].upcase == 'TRUE')) UI.title 'Clean Dummy Files' do clean_dummy_files(static_sandbox.target_support_files_root) if @dynamic clean_dummy_files(dynamic_sandbox.target_support_files_root) end end else UI.puts 'Jump clean dummy files' end builder = Pod::Builder.new( platform, static_installer, @source_dir, static_sandbox_root, dynamic_sandbox_root, static_sandbox.public_headers.root, @spec, @embedded, @mangle, @dynamic, @config, @bundle_identifier, @exclude_deps, @exclude_dep_items, @select_archs ) builder.build(@package_type) return unless @embedded builder. else perform_build_t(platform,static_sandbox,dynamic_sandbox,static_installer) end end |
#perform_build_t ⇒ Object
147 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 147 alias perform_build_t perform_build |
#podfile_from_spec_sandbox(path, spec_name, platform_name, deployment_target, subspecs, sources, sandbox) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 210 def podfile_from_spec_sandbox(path, spec_name, platform_name, deployment_target, subspecs, sources,sandbox) = {} if path if @local [:path] = path else [:podspec] = path end end [:subspecs] = subspecs if subspecs podfile_path = pre_podfile @podfile,sandbox podfile = Pod::Podfile.from_file(podfile_path) sources.each { |s| podfile.source s } # podfile.platform(platform_name, deployment_target) podfile.pod(spec_name, ) podfile.install!('cocoapods', :integrate_targets => false, :deterministic_uuids => false) podfile.target('packager') do podfile.inherit! :complete end podfile end |
#pre_podfile(path, sandbox) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 195 def pre_podfile(path,sandbox) path = Pathname.new(path) unless path.exist? raise Informative, "No Podfile exists at path `#{path}`." end retpath = sandbox.root.to_s+'/podfile' contents = '' File.foreach(path) do |line| contents += line unless line.include? '<!SKIP_PATCH_LINE>' end File.write(retpath,contents) retpath end |
#spec_framework(platform) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 91 def spec_framework(platform) spec = <<RB s.#{platform.name.to_s}.public_header_files = ['#{platform.name.to_s}/Headers/*.{h}'] s.#{platform.name.to_s}.source_files = ['#{platform.name.to_s}/**/Headers/*.{h}'] s.#{platform.name.to_s}.resource = ['#{platform.name.to_s}/**/Resources/*.bundle'] s.#{platform.name.to_s}.module_map = "#{platform.name.to_s}/**/Modules/module.modulemap" RB end |
#spec_library(platform) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 80 def spec_library(platform) spec = <<RB s.#{platform.name.to_s}.deployment_target = '#{platform.deployment_target}' s.#{platform.name.to_s}.vendored_libraries = ['#{platform.name.to_s}/*.a'] s.#{platform.name.to_s}.public_header_files = ['#{platform.name.to_s}/Headers/*.{h}'] s.#{platform.name.to_s}.source_files = ['#{platform.name.to_s}/Headers/*.{h}',"#{platform.name.to_s}/Modules/module.modulemap"] s.#{platform.name.to_s}.resource = ['#{platform.name.to_s}/Resources/*.bundle'] s.#{platform.name.to_s}.module_map = "#{platform.name.to_s}/Modules/module.modulemap" RB end |
#write_pod_project(dynamic_project, dynamic_sandbox) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 48 def write_pod_project(dynamic_project, dynamic_sandbox) UI. "- Writing Xcode project file to #{UI.path dynamic_sandbox.project_path}" do dynamic_project.pods.remove_from_project if dynamic_project.pods.empty? dynamic_project.development_pods.remove_from_project if dynamic_project.development_pods.empty? dynamic_project.sort(:groups_position => :below) dynamic_project.recreate_user_schemes(false) # Edit search paths so that we can find our dependency headers dynamic_project.targets.first.build_configuration_list.build_configurations.each do |config| header_path = Dir.glob("#{Dir.pwd}/Pods/Static/Headers/*/*") header_path.push "#{Dir.pwd}/Pods/Static/Headers/Public" header_path.push "#{Dir.pwd}/Pods/Static/Headers/Private" header_path.reject! {|item|item.split('/').last == dynamic_project.targets.first.name} header_path = header_path.join " " config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) #{header_path}" config.build_settings['USER_HEADER_SEARCH_PATHS'] = "$(inherited) #{header_path}" config.build_settings['OTHER_LDFLAGS'] = '$(inherited) -ObjC' if ENV['DISABLE_BITCODE'] && (ENV['DISABLE_BITCODE'].upcase == 'YES' || ENV['DISABLE_BITCODE'].upcase == 'TRUE') config.build_settings['ENABLE_BITCODE'] = 'NO' end end dynamic_project.save end end |
#write_pod_project_t ⇒ Object
47 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 47 alias write_pod_project_t write_pod_project |