Class: Motion::CocoaPods
- Inherits:
-
Object
- Object
- Motion::CocoaPods
- Defined in:
- lib/motion/cocoapods/main.rb
Constant Summary collapse
- PODS_ROOT =
'vendor/Pods'
- TARGET_NAME =
'RubyMotion'
- PUBLIC_HEADERS_ROOT =
File.join(PODS_ROOT, 'Headers/Public')
- PODS_ROOT_MATCHER =
/(\$\(PODS_ROOT\))|(\$\{PODS_ROOT\})/
- SUPPORT_FILES =
File.join(PODS_ROOT, "Target Support Files/Pods-#{TARGET_NAME}")
Instance Attribute Summary collapse
-
#podfile ⇒ Object
Returns the value of attribute podfile.
Instance Method Summary collapse
- #analyzer ⇒ Object
- #cocoapods_config ⇒ Object
-
#configure_project ⇒ Object
Adds the Pods project to the RubyMotion config as a vendored project and.
- #copy_cocoapods_env_and_prefix_headers ⇒ Object
-
#dependency(*name_and_version_requirements, &block) ⇒ Object
Deprecated.
-
#initialize(config, vendor_options) ⇒ CocoaPods
constructor
A new instance of CocoaPods.
-
#inspect ⇒ Object
This is the output that gets shown in ‘rake config`, so it should be short and sweet.
-
#install!(update) ⇒ Object
Performs a CocoaPods Installation.
- #install_resource(file, resources_dir) ⇒ Object
-
#install_resources ⇒ Object
TODO: this probably breaks in cases like resource bundles etc, need to test.
- #pod(*name_and_version_requirements, &block) ⇒ Object
-
#pods_installer ⇒ Object
Installation ————————————————————————-#.
- #pods_xcconfig ⇒ 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
-
#source(source) ⇒ Object
DSL ————————————————————————-#.
- #xcconfig_hash ⇒ Object
Constructor Details
#initialize(config, vendor_options) ⇒ CocoaPods
Returns a new instance of CocoaPods.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/motion/cocoapods/main.rb', line 35 def initialize(config, ) @config = config @vendor_options = platform = case @config.deploy_platform when 'MacOSX' then :osx when 'iPhoneOS' then :ios when 'AppleTVOS' then :tvos when 'WatchOS' then :watchos else App.fail "Unknown CocoaPods platform: #{@config.deploy_platform}" end @podfile = Pod::Podfile.new(Pathname.new(Rake.original_dir) + 'Rakefile') {} @podfile.platform(platform, config.deployment_target) @podfile.target(TARGET_NAME) cocoapods_config.podfile = @podfile cocoapods_config.skip_repo_update = true cocoapods_config.installation_root = Pathname.new(File.(config.project_dir)) + 'vendor' if cocoapods_config.verbose = !!ENV["COCOAPODS_VERBOSE"] require 'claide' end configure_project end |
Instance Attribute Details
#podfile ⇒ Object
Returns the value of attribute podfile.
33 34 35 |
# File 'lib/motion/cocoapods/main.rb', line 33 def podfile @podfile end |
Instance Method Details
#analyzer ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/motion/cocoapods/main.rb', line 170 def analyzer Pod::Installer::Analyzer.new( cocoapods_config.sandbox, @podfile, cocoapods_config.lockfile ) end |
#cocoapods_config ⇒ Object
166 167 168 |
# File 'lib/motion/cocoapods/main.rb', line 166 def cocoapods_config Pod::Config.instance end |
#configure_project ⇒ Object
Adds the Pods project to the RubyMotion config as a vendored project and
64 65 66 67 68 69 70 |
# File 'lib/motion/cocoapods/main.rb', line 64 def configure_project @config.resources_dirs << resources_dir.to_s # TODO: replace this all once Xcodeproj has the proper xcconfig parser. return unless xcconfig_hash && ldflags configure_xcconfig end |
#copy_cocoapods_env_and_prefix_headers ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/motion/cocoapods/main.rb', line 132 def copy_cocoapods_env_and_prefix_headers headers = Dir.glob([ "#{PODS_ROOT}/*.h", "#{PODS_ROOT}/*.pch", "#{PODS_ROOT}/Target Support Files/**/*.h", "#{PODS_ROOT}/Target Support Files/**/*.pch" ]) headers.each do |header| src = File.basename(header) dst = src.sub(/\.pch$/, ".h") dst_path = File.join(PUBLIC_HEADERS_ROOT, "____#{dst}") next if File.exist?(dst_path) FileUtils.mkdir_p(PUBLIC_HEADERS_ROOT) FileUtils.cp(header, dst_path) end end |
#dependency(*name_and_version_requirements, &block) ⇒ Object
Deprecated.
84 85 86 |
# File 'lib/motion/cocoapods/main.rb', line 84 def dependency(*name_and_version_requirements, &block) @podfile.dependency(*name_and_version_requirements, &block) end |
#inspect ⇒ Object
This is the output that gets shown in ‘rake config`, so it should be short and sweet.
158 159 160 161 162 163 164 |
# File 'lib/motion/cocoapods/main.rb', line 158 def inspect cocoapods_config .lockfile .to_hash["PODS"] .map { |pod| pod.is_a?(Hash) ? pod.keys.first : pod } .inspect 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.
111 112 113 114 115 116 117 |
# File 'lib/motion/cocoapods/main.rb', line 111 def install!(update) pods_installer.update = update pods_installer..integrate_targets = false pods_installer.install! install_resources copy_cocoapods_env_and_prefix_headers end |
#install_resource(file, resources_dir) ⇒ Object
126 127 128 129 130 |
# File 'lib/motion/cocoapods/main.rb', line 126 def install_resource(file, resources_dir) FileUtils.cp_r(file, resources_dir) if file.exist? rescue ArgumentError => exc raise unless exc. =~ /same file/ end |
#install_resources ⇒ Object
TODO: this probably breaks in cases like resource bundles etc, need to test.
120 121 122 123 124 |
# File 'lib/motion/cocoapods/main.rb', line 120 def install_resources FileUtils.rm_rf(resources_dir) FileUtils.mkdir_p(resources_dir) resources.each { |file| install_resource(file, resources_dir) } end |
#pod(*name_and_version_requirements, &block) ⇒ Object
79 80 81 |
# File 'lib/motion/cocoapods/main.rb', line 79 def pod(*name_and_version_requirements, &block) @podfile.pod(*name_and_version_requirements, &block) end |
#pods_installer ⇒ Object
Installation ————————————————————————-#
95 96 97 98 99 100 101 |
# File 'lib/motion/cocoapods/main.rb', line 95 def pods_installer @installer ||= Pod::Installer.new( cocoapods_config.sandbox, @podfile, cocoapods_config.lockfile ) end |
#pods_xcconfig ⇒ Object
178 179 180 181 182 183 184 |
# File 'lib/motion/cocoapods/main.rb', line 178 def pods_xcconfig path = Pathname.new(@config.project_dir) + SUPPORT_FILES + "Pods-#{TARGET_NAME}.release.xcconfig" Xcodeproj::Config.new(path) if path.exist? end |
#post_install(&block) ⇒ Object
88 89 90 |
# File 'lib/motion/cocoapods/main.rb', line 88 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.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/motion/cocoapods/main.rb', line 195 def resources resources = [] resource_path = Pathname.new(@config.project_dir) + SUPPORT_FILES + "Pods-#{TARGET_NAME}-resources.sh" File.open(resource_path) { |f| f.each_line do |line| matched = line.match(/install_resource\s+(.*)/) next unless matched path = (matched[1].strip)[1..-2] path.sub!("${BUILD_DIR}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}", ".build") next if File.extname(path) == ".framework" resources << Pathname.new(@config.project_dir) + PODS_ROOT + path end } resources.uniq end |
#resources_dir ⇒ Object
220 221 222 |
# File 'lib/motion/cocoapods/main.rb', line 220 def resources_dir Pathname.new(@config.project_dir) + PODS_ROOT + "Resources" end |
#source(source) ⇒ Object
DSL ————————————————————————-#
75 76 77 |
# File 'lib/motion/cocoapods/main.rb', line 75 def source(source) @podfile.source(source) end |
#xcconfig_hash ⇒ Object
186 187 188 189 190 |
# File 'lib/motion/cocoapods/main.rb', line 186 def xcconfig_hash return unless pods_xcconfig @xcconfig_hash ||= pods_xcconfig.to_hash end |