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
- #ln_source_to_dynamic_target(static_installer, dynamic_sandbox) ⇒ Object
- #perform_build(platform, static_sandbox, dynamic_sandbox, static_installer) ⇒ Object
- #perform_build_t ⇒ 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.
44 45 46 47 48 49 50 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 44 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','') initialize_t argv end |
Instance Method Details
#build_dynamic_target(dynamic_sandbox, static_installer, platform) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 11 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
9 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 9 alias build_dynamic_target_t build_dynamic_target |
#build_in_sandbox(platform) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 53 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
52 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 52 alias build_in_sandbox_t build_in_sandbox |
#build_package ⇒ Object
99 100 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 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 99 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
98 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 98 alias build_package_t build_package |
#clean_dummy_files(path) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 128 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
25 26 27 28 29 30 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 25 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
24 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 24 alias copy_dynamic_target_t copy_dynamic_target |
#initialize_t ⇒ Object
43 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 43 alias initialize_t initialize |
#ln_source_to_dynamic_target(static_installer, dynamic_sandbox) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 32 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
146 147 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 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 146 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
145 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 145 alias perform_build_t perform_build |
#spec_framework(platform) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 89 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
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cocoapods-packager-ext/command/package_ext.rb', line 78 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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 47 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
46 |
# File 'lib/cocoapods-packager-ext/ext/pod_utils.rb', line 46 alias write_pod_project_t write_pod_project |