Class: Motion::Project::CocoaPods

Inherits:
Object
  • Object
show all
Defined in:
lib/motion/project/cocoapods.rb,
lib/motion/project/version.rb

Overview

—————————————————————————#

Constant Summary collapse

PODS_ROOT =
'vendor/Pods'
VERSION =
'1.4.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CocoaPods

Returns a new instance of CocoaPods.



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/motion/project/cocoapods.rb', line 68

def initialize(config)
  @config = config

  @podfile = Pod::Podfile.new {}
  @podfile.platform((App.respond_to?(:template) ? App.template : :ios), config.deployment_target)
  cp_config.podfile = @podfile
  cp_config.skip_repo_update = true
  cp_config.verbose = !!ENV['COCOAPODS_VERBOSE']
  cp_config.integrate_targets = false
  cp_config.installation_root = Pathname.new(File.expand_path(config.project_dir)) + 'vendor'

  configure_project
end

Instance Attribute Details

#podfileObject

Returns the value of attribute podfile.



66
67
68
# File 'lib/motion/project/cocoapods.rb', line 66

def podfile
  @podfile
end

Instance Method Details

#analyzerObject



195
196
197
198
# File 'lib/motion/project/cocoapods.rb', line 195

def analyzer
  cp_config = Pod::Config.instance
  Pod::Installer::Analyzer.new(cp_config.sandbox, @podfile, cp_config.lockfile)
end

#bridgesupport_fileObject



200
201
202
# File 'lib/motion/project/cocoapods.rb', line 200

def bridgesupport_file
  Pathname.new(@config.project_dir) + PODS_ROOT + 'Pods.bridgesupport'
end

#configure_projectObject

Adds the Pods project to the RubyMotion config as a vendored project and



84
85
86
87
88
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
# File 'lib/motion/project/cocoapods.rb', line 84

def configure_project
  @config.vendor_project(PODS_ROOT, :xcode,
    :target => 'Pods',
    :headers_dir => 'Headers',
    :products => %w{ libPods.a }
  )

  @config.resources_dirs << resources_dir.to_s

  # TODO replace this all once Xcodeproj has the proper xcconfig parser.
  if (xcconfig = self.pods_xcconfig) && ldflags = xcconfig.to_hash['OTHER_LDFLAGS']
    lib_search_paths = xcconfig.to_hash['LIBRARY_SEARCH_PATHS'] || ""
    lib_search_paths.gsub!('$(PODS_ROOT)', "-L#{@config.project_dir}/#{PODS_ROOT}")

    framework_search_paths = xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS']
    if framework_search_paths
      framework_search_paths.scan(/\"([^\"]+)\"/) do |search_path|
        path = search_path.first.gsub!(/(\$\(PODS_ROOT\))|(\$\{PODS_ROOT\})/, "#{@config.project_dir}/#{PODS_ROOT}")
        @config.framework_search_paths << path if path
      end
    end

    @config.frameworks.concat(ldflags.scan(/-framework\s+([^\s]+)/).map { |m| m[0] })
    @config.frameworks.uniq!
    @config.libs.concat(ldflags.scan(/-l([^\s]+)/).map { |m|
      if lib_search_paths.length == 0 || File.exist?("/usr/lib/lib#{m[0]}.dylib")
        "/usr/lib/lib#{m[0]}.dylib"
      else
        "#{lib_search_paths} -ObjC -l#{m[0]}"
      end
    })
    @config.weak_frameworks.concat(ldflags.scan(/-weak_framework\s+([^\s]+)/).map { |m| m[0] })
    @config.weak_frameworks.uniq!
    @config.libs.uniq!
  end
end

#copy_cocoapods_env_and_prefix_headersObject



177
178
179
180
181
182
183
184
185
186
# File 'lib/motion/project/cocoapods.rb', line 177

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')
    unless File.exist?("#{PODS_ROOT}/Headers/____#{dst}")
      FileUtils.cp("#{PODS_ROOT}/#{src}", "#{PODS_ROOT}/Headers/____#{dst}")
    end
  end
end

#cp_configObject

Helpers ————————————————————————-#



191
192
193
# File 'lib/motion/project/cocoapods.rb', line 191

def cp_config
  Pod::Config.instance
end

#dependency(*name_and_version_requirements, &block) ⇒ Object

Deprecated.



129
130
131
# File 'lib/motion/project/cocoapods.rb', line 129

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.



152
153
154
155
156
157
158
159
160
161
# File 'lib/motion/project/cocoapods.rb', line 152

def install!(update)
  pods_installer.update_mode = 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_resourcesObject

TODO this probably breaks in cases like resource bundles etc, need to test.



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/motion/project/cocoapods.rb', line 164

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.message =~ /same file/
        raise
      end
    end
  end
end

#pod(*name_and_version_requirements, &block) ⇒ Object

DSL ————————————————————————-#



124
125
126
# File 'lib/motion/project/cocoapods.rb', line 124

def pod(*name_and_version_requirements, &block)
  @podfile.pod(*name_and_version_requirements, &block)
end

#pods_installerObject

Installation ————————————————————————-#



140
141
142
# File 'lib/motion/project/cocoapods.rb', line 140

def pods_installer
  @installer ||= Pod::Installer.new(cp_config.sandbox, @podfile, cp_config.lockfile)
end

#pods_xcconfigObject



204
205
206
207
# File 'lib/motion/project/cocoapods.rb', line 204

def pods_xcconfig
  path = Pathname.new(@config.project_dir) + PODS_ROOT + 'Pods.xcconfig'
  Xcodeproj::Config.new(path) if path.exist?
end

#post_install(&block) ⇒ Object



133
134
135
# File 'lib/motion/project/cocoapods.rb', line 133

def post_install(&block)
  @podfile.post_install(&block)
end

#resourcesObject



209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/motion/project/cocoapods.rb', line 209

def resources
  resources = []
  File.open(Pathname.new(@config.project_dir) + PODS_ROOT + '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")
        resources << Pathname.new(@config.project_dir) + PODS_ROOT + path
      end
    end
  }
  resources
end

#resources_dirObject



223
224
225
# File 'lib/motion/project/cocoapods.rb', line 223

def resources_dir
  Pathname.new(@config.project_dir) + PODS_ROOT + 'Resources'
end