Skip to content

Commit

Permalink
Don't use rake tasks to generate gemspec, there's no benefit over jus…
Browse files Browse the repository at this point in the history
…t having a gemspec in the repo.
  • Loading branch information
alloy committed May 7, 2012
1 parent 5c0d956 commit 5bce12e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 83 deletions.
28 changes: 5 additions & 23 deletions Rakefile
@@ -1,26 +1,8 @@
require 'rake/gempackagetask'

Version = 1.0

GemSpec = Gem::Specification.new do |spec|
spec.name = 'motion-cocoapods'
spec.summary = 'CocoaPods integration for RubyMotion projects'
spec.description = "motion-cocoapods allows RubyMotion projects to have access to the CocoaPods dependency manager."
spec.author = 'Laurent Sansonetti'
spec.email = 'lrz@hipbyte.com'
spec.homepage = 'http://www.rubymotion.com'
spec.version = Version

files = []
files << 'README.rdoc'
files << 'LICENSE'
files.concat(Dir.glob('lib/**/*.rb'))
spec.files = files
end

Rake::GemPackageTask.new(GemSpec) do |pkg|
pkg.need_zip = false
pkg.need_tar = true
desc "Build the gem"
task :gem do
sh "bundle exec gem build motion-cocoapods.gemspec"
sh "mkdir -p pkg"
sh "mv *.gem pkg/"
end

task :clean do
Expand Down
124 changes: 64 additions & 60 deletions lib/motion/project/cocoapods.rb
Expand Up @@ -28,76 +28,80 @@

require 'cocoapods'

class CocoaPodsConfig
def initialize(config)
@config = config
@podfile = Pod::Podfile.new {}
@podfile.platform :ios
module Motion::Project
class Config
variable :pods

Pod::Config.instance.silent = true
Pod::Config.instance.rootspec = @podfile
Pod::Config.instance.instance_variable_set(:@project_pods_root, Pathname.new(File.join(config.project_dir, 'vendor')))
def pods(&block)
@pods ||= Motion::Project::CocoaPods.new(self)
if block
@pods.instance_eval(&block)
@pods.resolve!
end
@pods
end
end

def dependency(*name_and_version_requirements, &block)
@podfile.dependency(*name_and_version_requirements, &block)
end
class CocoaPods
VERSION = '1.0.0'

def pods_installer
@installer ||= Pod::Installer.new(@podfile)
end
def initialize(config)
@config = config
@podfile = Pod::Podfile.new {}
@podfile.platform :ios

def resolve!
pods_installer.install_dependencies!
specs = pods_installer.build_specifications
header_paths = specs.map do |podspec|
podspec.expanded_source_files.select do |p|
File.extname(p) == '.h'
end.map do |p|
"-I\"" + File.expand_path(File.join('./vendor', File.dirname(p))) + "\""
end
end.flatten.join(' ')
specs.each do |podspec|
cflags = (podspec.compiler_flags or '') + ' ' + header_paths
source_files = podspec.expanded_source_files.map do |path|
# Remove the first part of the path which is the project directory.
path.to_s.split('/')[1..-1].join('/')
end
Pod::Config.instance.silent = true
Pod::Config.instance.rootspec = @podfile
Pod::Config.instance.instance_variable_set(:@project_pods_root, Pathname.new(File.join(config.project_dir, 'vendor')))
end

@config.vendor_project(podspec.pod_destroot, :static,
:cflags => cflags,
:source_files => source_files)
def dependency(*name_and_version_requirements, &block)
@podfile.dependency(*name_and_version_requirements, &block)
end

ldflags = podspec.xcconfig.to_hash['OTHER_LDFLAGS']
if ldflags
@config.frameworks.concat(ldflags.scan(/-framework\s+([^\s]+)/).flatten)
@config.frameworks.uniq!
@config.libs.concat(ldflags.scan(/-l([^\s]+)/).map { |n| "/usr/lib/lib#{n}.dylib" })
@config.libs.uniq!
end
def pods_installer
@installer ||= Pod::Installer.new(@podfile)
end

def resolve!
pods_installer.install_dependencies!
specs = pods_installer.build_specifications
header_paths = specs.map do |podspec|
podspec.expanded_source_files.select do |p|
File.extname(p) == '.h'
end.map do |p|
"-I\"" + File.expand_path(File.join('./vendor', File.dirname(p))) + "\""
end
end.flatten.join(' ')
specs.each do |podspec|
cflags = (podspec.compiler_flags or '') + ' ' + header_paths
source_files = podspec.expanded_source_files.map do |path|
# Remove the first part of the path which is the project directory.
path.to_s.split('/')[1..-1].join('/')
end

@config.vendor_project(podspec.pod_destroot, :static,
:cflags => cflags,
:source_files => source_files)

ldflags = podspec.xcconfig.to_hash['OTHER_LDFLAGS']
if ldflags
@config.frameworks.concat(ldflags.scan(/-framework\s+([^\s]+)/).flatten)
@config.frameworks.uniq!
@config.libs.concat(ldflags.scan(/-l([^\s]+)/).map { |n| "/usr/lib/lib#{n}.dylib" })
@config.libs.uniq!
end

=begin
# Remove .h files that are not covered in the podspec, to avoid
# future preprocessor #include collisions.
headers_to_ignore = (Dir.chdir(podspec.pod_destroot) do
Dir.glob('*/**/*.h')
end) - source_files.select { |p| File.extname(p) == '.h' }
p headers_to_ignore,source_files.select { |p| File.extname(p) == '.h' } ,:ok
#headers_to_ignore.each { |p| FileUtils.rm_rf File.join(podspec.pod_destroot, p) }
# Remove .h files that are not covered in the podspec, to avoid
# future preprocessor #include collisions.
headers_to_ignore = (Dir.chdir(podspec.pod_destroot) do
Dir.glob('*/**/*.h')
end) - source_files.select { |p| File.extname(p) == '.h' }
p headers_to_ignore,source_files.select { |p| File.extname(p) == '.h' } ,:ok
#headers_to_ignore.each { |p| FileUtils.rm_rf File.join(podspec.pod_destroot, p) }
=end
end
end
end
end

module Motion; module Project; class Config
variable :pods

def pods(&block)
@pods ||= CocoaPodsConfig.new(self)
if block
@pods.instance_eval(&block)
@pods.resolve!
end
@pods
end
end; end; end
21 changes: 21 additions & 0 deletions motion-cocoapods.gemspec
@@ -0,0 +1,21 @@
# This is just so that the source file can be loaded.
module ::Motion; module Project; class Config
def self.variable(*); end
end; end; end

require File.expand_path('../lib/motion/project/cocoapods', __FILE__)
require 'rake/file_list'

Gem::Specification.new do |spec|
spec.name = 'motion-cocoapods'
spec.version = Motion::Project::CocoaPods::VERSION
spec.date = Date.today
spec.summary = 'CocoaPods integration for RubyMotion projects'
spec.description = "motion-cocoapods allows RubyMotion projects to have access to the CocoaPods dependency manager."
spec.author = 'Laurent Sansonetti'
spec.email = 'lrz@hipbyte.com'
spec.homepage = 'http://www.rubymotion.com'
spec.files = Rake::FileList['README.rdoc,LICENSE,lib/**/*.rb']

spec.add_runtime_dependency 'cocoapods', '>= 0.5.1'
end

0 comments on commit 5bce12e

Please sign in to comment.