mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-05-30 18:04:02 +08:00
new support for vendor libraries
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
require 'motion/project/app'
|
||||
require 'motion/project/config'
|
||||
require 'motion/project/builder'
|
||||
require 'motion/project/vendor'
|
||||
|
||||
desc "Build the project, then run the simulator"
|
||||
task :default => :simulator
|
||||
|
||||
@@ -31,18 +31,11 @@ module Motion; module Project;
|
||||
|
||||
# Build vendor libraries.
|
||||
vendor_libs = []
|
||||
Dir.glob(File.join(config.vendor_dir, '*')).each do |vendor_lib|
|
||||
platform_task = platform.downcase
|
||||
Dir.chdir(vendor_lib) do
|
||||
sh "rake #{platform_task}"
|
||||
Dir.glob(File.join('build', platform, '*.a')).each do |path|
|
||||
vendor_libs << File.expand_path(path)
|
||||
end
|
||||
Dir.glob('*.bridgesupport').each do |path|
|
||||
bs_files << File.expand_path(path)
|
||||
end
|
||||
end
|
||||
end
|
||||
config.vendor_projects.each do |vendor_project|
|
||||
vendor_project.build(platform, archs)
|
||||
vendor_libs.concat(vendor_project.libs)
|
||||
bs_files.concat(vendor_project.bs_files)
|
||||
end
|
||||
|
||||
# Build object files.
|
||||
objs = []
|
||||
|
||||
@@ -23,7 +23,7 @@ module Motion; module Project
|
||||
end
|
||||
|
||||
variable :files, :platforms_dir, :sdk_version, :frameworks,
|
||||
:delegate_class, :name, :build_dir, :resources_dir, :vendor_dir,
|
||||
:delegate_class, :name, :build_dir, :resources_dir,
|
||||
:codesign_certificate, :provisioning_profile, :device_family,
|
||||
:interface_orientations, :version, :icons
|
||||
|
||||
@@ -37,7 +37,6 @@ module Motion; module Project
|
||||
@name = 'My App'
|
||||
@build_dir = File.join(project_dir, 'build')
|
||||
@resources_dir = File.join(project_dir, 'resources')
|
||||
@vendor_dir = File.join(project_dir, 'vendor')
|
||||
@device_family = :iphone
|
||||
@bundle_signature = '????'
|
||||
@interface_orientations = [:portrait, :landscape_left, :landscape_right]
|
||||
@@ -84,6 +83,13 @@ module Motion; module Project
|
||||
end
|
||||
end
|
||||
|
||||
attr_reader :vendor_projects
|
||||
|
||||
def vendor_project(path, type, opts={})
|
||||
@vendor_projects ||= []
|
||||
@vendor_projects << Motion::Project::Vendor.new(path, type, self, opts)
|
||||
end
|
||||
|
||||
def ordered_build_files
|
||||
ary = []
|
||||
@files.each do |file|
|
||||
|
||||
77
lib/motion/project/vendor.rb
Normal file
77
lib/motion/project/vendor.rb
Normal file
@@ -0,0 +1,77 @@
|
||||
module Motion; module Project;
|
||||
class Vendor
|
||||
include Rake::DSL if Rake.const_defined?(:DSL)
|
||||
|
||||
def initialize(path, type, config, opts)
|
||||
@path = path
|
||||
@type = type
|
||||
@config = config
|
||||
@opts = opts
|
||||
@libs = []
|
||||
@bs_files = []
|
||||
end
|
||||
|
||||
attr_reader :libs, :bs_files
|
||||
|
||||
def build(platform, archs)
|
||||
send gen_method('build'), platform, archs, @opts
|
||||
end
|
||||
|
||||
def clean
|
||||
send gen_method('clean')
|
||||
end
|
||||
|
||||
def build_xcode(platform, archs, opts)
|
||||
Dir.chdir(@path) do
|
||||
build_dir = "build-#{platform}"
|
||||
if !File.exist?(build_dir)
|
||||
FileUtils.mkdir build_dir
|
||||
|
||||
# Prepare Xcode project settings.
|
||||
xcodeproj = opts.delete(:xcodeproj) || begin
|
||||
projs = Dir.glob('*.xcodeproj')
|
||||
if projs.size != 1
|
||||
$stderr.puts "Can't locate Xcode project file for vendor project #{@path}"
|
||||
exit 1
|
||||
end
|
||||
projs[0]
|
||||
end
|
||||
target = opts.delete(:target) || File.basename(xcodeproj, '.xcodeproj')
|
||||
configuration = opts.delete(:configuration) || 'Release'
|
||||
|
||||
# Build project into `build' directory. We delete the build directory each time because
|
||||
# Xcode is too stupid to be trusted to use the same build directory for different
|
||||
# platform builds.
|
||||
rm_rf 'build'
|
||||
sh "/usr/bin/xcodebuild -target #{target} -configuration #{configuration} -sdk #{platform.downcase}#{@config.sdk_version} #{archs.map { |x| '-arch ' + x }.join(' ')} CONFIGURATION_BUILD_DIR=build build"
|
||||
|
||||
# Copy .a files into the platform build directory.
|
||||
Dir.glob('build/*.a').each do |lib|
|
||||
lib = File.readlink(lib)
|
||||
sh "/bin/cp \"#{lib}\" \"#{build_dir}\""
|
||||
end
|
||||
end
|
||||
|
||||
@bs_files.clear
|
||||
@bs_files.concat(Dir.glob('*.bridgesupport').map { |x| File.expand_path(x) })
|
||||
|
||||
@libs.clear
|
||||
@libs.concat(Dir.glob("#{build_dir}/*.a").map { |x| File.expand_path(x) })
|
||||
end
|
||||
end
|
||||
|
||||
def clean_xcode
|
||||
Dir.chdir(@path) do
|
||||
rm_rf 'build', 'build-iPhoneOS', 'build-iPhoneSimulator'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def gen_method(prefix)
|
||||
method = "#{prefix}_#{@type.to_s}".intern
|
||||
raise "Invalid vendor project type: #{@type}" unless respond_to?(method)
|
||||
method
|
||||
end
|
||||
end
|
||||
end; end
|
||||
Reference in New Issue
Block a user