Class: Motion::Project::CocoaPods
- Inherits:
-
Object
- Object
- Motion::Project::CocoaPods
- Defined in:
- lib/motion/project/cocoapods.rb,
lib/motion/project/version.rb
Overview
—————————————————————————#
Constant Summary collapse
- PODS_ROOT =
'vendor/Pods'
- SUPPORT_FILES =
File.join(PODS_ROOT, 'Target Support Files/Pods')
- HEADERS_ROOT =
File.join(PODS_ROOT, 'Headers')
- VERSION =
'1.6.0'
Instance Attribute Summary collapse
-
#podfile ⇒ Object
Returns the value of attribute podfile.
Instance Method Summary collapse
- #analyzer ⇒ Object
- #bridgesupport_file ⇒ Object
-
#configure_project ⇒ Object
Adds the Pods project to the RubyMotion config as a vendored project and.
- #copy_cocoapods_env_and_prefix_headers ⇒ Object
-
#cp_config ⇒ Object
Helpers ————————————————————————-#.
-
#dependency(*name_and_version_requirements, &block) ⇒ Object
Deprecated.
-
#initialize(config, vendor_options) ⇒ CocoaPods
constructor
A new instance of CocoaPods.
-
#install!(update) ⇒ Object
Performs a CocoaPods Installation.
-
#install_resources ⇒ Object
TODO this probably breaks in cases like resource bundles etc, need to test.
-
#pod(*name_and_version_requirements, &block) ⇒ Object
DSL ————————————————————————-#.
-
#pods_installer ⇒ Object
Installation ————————————————————————-#.
- #pods_xcconfig ⇒ Object
- #pods_xcconfig_hash ⇒ Object
- #post_install(&block) ⇒ Object
-
#resources ⇒ Object
Do not copy ‘.framework` bundles, these should be handled through RM’s ‘embedded_frameworks` config attribute.
- #resources_dir ⇒ Object
Constructor Details
#initialize(config, vendor_options) ⇒ CocoaPods
Returns a new instance of CocoaPods.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/motion/project/cocoapods.rb', line 69 def initialize(config, ) @config = config @vendor_options = @podfile = Pod::Podfile.new(Pathname.new(Rake.original_dir) + 'Rakefile') {} @podfile.platform((App.respond_to?(:template) ? App.template : :ios), config.deployment_target) cp_config.podfile = @podfile cp_config.skip_repo_update = true cp_config.integrate_targets = false cp_config.installation_root = Pathname.new(File.(config.project_dir)) + 'vendor' if cp_config.verbose = !!ENV['COCOAPODS_VERBOSE'] require 'claide' end configure_project end |
Instance Attribute Details
#podfile ⇒ Object
Returns the value of attribute podfile.
67 68 69 |
# File 'lib/motion/project/cocoapods.rb', line 67 def podfile @podfile end |
Instance Method Details
#analyzer ⇒ Object
263 264 265 266 |
# File 'lib/motion/project/cocoapods.rb', line 263 def analyzer cp_config = Pod::Config.instance Pod::Installer::Analyzer.new(cp_config.sandbox, @podfile, cp_config.lockfile) end |
#bridgesupport_file ⇒ Object
268 269 270 |
# File 'lib/motion/project/cocoapods.rb', line 268 def bridgesupport_file Pathname.new(@config.project_dir) + PODS_ROOT + 'Pods.bridgesupport' end |
#configure_project ⇒ Object
Adds the Pods project to the RubyMotion config as a vendored project and
89 90 91 92 93 94 95 96 97 98 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 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 |
# File 'lib/motion/project/cocoapods.rb', line 89 def configure_project @config.resources_dirs << resources_dir.to_s # TODO replace this all once Xcodeproj has the proper xcconfig parser. if (xcconfig = self.pods_xcconfig_hash) && ldflags = xcconfig['OTHER_LDFLAGS'] lib_search_paths = xcconfig['LIBRARY_SEARCH_PATHS'] || "" lib_search_paths = lib_search_paths.split(/\s/).map do |path| '-L ' << path.gsub('$(PODS_ROOT)', File.join(@config.project_dir, PODS_ROOT)) end.join(' ') # Collect the Pod products pods_libs = [] @config.libs.concat(ldflags.scan(/-l"?([^\s"]+)"?/).map { |m| lib_name = m[0] next if lib_name.nil? if lib_name.start_with?('Pods-') pods_libs << lib_name nil elsif lib_search_paths.length == 0 || File.exist?("/usr/lib/lib#{lib_name}.dylib") "/usr/lib/lib#{lib_name}.dylib" else "#{lib_search_paths} -ObjC -l#{lib_name}" end }.compact) @config.libs.uniq! @config.vendor_project(PODS_ROOT, :xcode, { :target => 'Pods', :headers_dir => 'Headers/Public', :products => pods_libs.map { |lib_name| "lib#{lib_name}.a" } }.merge(@vendor_options)) framework_search_paths = [] if search_paths = xcconfig['FRAMEWORK_SEARCH_PATHS'] search_paths = search_paths.strip unless search_paths.empty? search_paths.scan(/\"([^\"]+)\"/) do |search_path| path = search_path.first.gsub!(/(\$\(PODS_ROOT\))|(\$\{PODS_ROOT\})/, "#{@config.project_dir}/#{PODS_ROOT}") framework_search_paths << path if path end # If we couldn't parse any search paths, then presumably nothing was properly quoted, so # fallback to just assuming the whole value is one path. if framework_search_paths.empty? path = search_paths.gsub!(/(\$\(PODS_ROOT\))|(\$\{PODS_ROOT\})/, "#{@config.project_dir}/#{PODS_ROOT}") framework_search_paths << path if path end end end frameworks = ldflags.scan(/-framework\s+([^\s]+)/).map { |m| m[0] } case @config.deploy_platform when 'MacOSX' @config.framework_search_paths.concat(framework_search_paths) @config.frameworks.concat(frameworks) @config.frameworks.uniq! framework_search_paths.each do |framework_search_path| frameworks.reject! do |framework| path = File.join(framework_search_path, "#{framework}.framework") if File.exist?(path) @config. << path true else false end end end when 'iPhoneOS' # If we would really specify these as ‘frameworks’ then the linker # would not link the archive into the application, because it does not # see any references to any of the symbols in the archive. Treating it # as a static library (which it is) with `-force_load` fixes this. # framework_search_paths.each do |framework_search_path| frameworks.reject! do |framework| path = File.join(framework_search_path, "#{framework}.framework") if File.exist?(path) @config.libs << "-force_load '#{File.join(path, framework)}'" true else false end end end end @config.frameworks.concat(frameworks) @config.frameworks.uniq! @config.weak_frameworks.concat(ldflags.scan(/-weak_framework\s+([^\s]+)/).map { |m| m[0] }) @config.weak_frameworks.uniq! end end |
#copy_cocoapods_env_and_prefix_headers ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/motion/project/cocoapods.rb', line 243 def copy_cocoapods_env_and_prefix_headers headers = Dir.glob(["#{PODS_ROOT}/*.h", "#{PODS_ROOT}/*.pch"]) headers.each do |header| src = File.basename(header) dst = src.sub(/\.pch$/, '.h') dst_path = File.join(HEADERS_ROOT, "____#{dst}") unless File.exist?(dst_path) FileUtils.mkdir_p(HEADERS_ROOT) FileUtils.cp(File.join(PODS_ROOT, src), dst_path) end end end |
#cp_config ⇒ Object
Helpers ————————————————————————-#
259 260 261 |
# File 'lib/motion/project/cocoapods.rb', line 259 def cp_config Pod::Config.instance end |
#dependency(*name_and_version_requirements, &block) ⇒ Object
Deprecated.
192 193 194 |
# File 'lib/motion/project/cocoapods.rb', line 192 def dependency(*name_and_version_requirements, &block) @podfile.dependency(*name_and_version_requirements, &block) end |
#install!(update) ⇒ Object
Performs a CocoaPods Installation.
For now we only support one Pods target, this will have to be expanded once we work on more spec support.
Let RubyMotion re-generate the BridgeSupport file whenever the list of installed pods changes.
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/motion/project/cocoapods.rb', line 215 def install!(update) pods_installer.update = update pods_installer.install! if bridgesupport_file.exist? && !pods_installer.installed_specs.empty? bridgesupport_file.delete end install_resources copy_cocoapods_env_and_prefix_headers end |
#install_resources ⇒ Object
TODO this probably breaks in cases like resource bundles etc, need to test.
228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/motion/project/cocoapods.rb', line 228 def install_resources FileUtils.mkdir_p(resources_dir) resources.each do |file| begin FileUtils.cp_r(file, resources_dir) if file.exist? rescue ArgumentError => exc unless exc. =~ /same file/ raise end end end end |
#pod(*name_and_version_requirements, &block) ⇒ Object
DSL ————————————————————————-#
187 188 189 |
# File 'lib/motion/project/cocoapods.rb', line 187 def pod(*name_and_version_requirements, &block) @podfile.pod(*name_and_version_requirements, &block) end |
#pods_installer ⇒ Object
Installation ————————————————————————-#
203 204 205 |
# File 'lib/motion/project/cocoapods.rb', line 203 def pods_installer @installer ||= Pod::Installer.new(cp_config.sandbox, @podfile, cp_config.lockfile) end |
#pods_xcconfig ⇒ Object
272 273 274 275 |
# File 'lib/motion/project/cocoapods.rb', line 272 def pods_xcconfig path = Pathname.new(@config.project_dir) + SUPPORT_FILES + 'Pods.release.xcconfig' Xcodeproj::Config.new(path) if path.exist? end |
#pods_xcconfig_hash ⇒ Object
277 278 279 280 281 |
# File 'lib/motion/project/cocoapods.rb', line 277 def pods_xcconfig_hash if xcconfig = pods_xcconfig xcconfig.to_hash end end |
#post_install(&block) ⇒ Object
196 197 198 |
# File 'lib/motion/project/cocoapods.rb', line 196 def post_install(&block) @podfile.post_install(&block) end |
#resources ⇒ Object
Do not copy ‘.framework` bundles, these should be handled through RM’s ‘embedded_frameworks` config attribute.
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/motion/project/cocoapods.rb', line 286 def resources resources = [] File.open(Pathname.new(@config.project_dir) + SUPPORT_FILES + 'Pods-resources.sh') { |f| f.each_line do |line| if matched = line.match(/install_resource\s+(.*)/) path = (matched[1].strip)[1..-2] path.sub!("${BUILD_DIR}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}", ".build") unless File.extname(path) == '.framework' resources << Pathname.new(@config.project_dir) + PODS_ROOT + path end end end } resources end |
#resources_dir ⇒ Object
302 303 304 |
# File 'lib/motion/project/cocoapods.rb', line 302 def resources_dir Pathname.new(@config.project_dir) + PODS_ROOT + 'Resources' end |