From 8b5a376628e69efd16bc7ed44a8f043b18111d63 Mon Sep 17 00:00:00 2001 From: Laurent Sansonetti Date: Mon, 5 Dec 2011 12:12:20 +0100 Subject: [PATCH] new support for vendor libraries --- lib/motion/project.rb | 1 + lib/motion/project/builder.rb | 17 +++----- lib/motion/project/config.rb | 10 ++++- lib/motion/project/vendor.rb | 77 +++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 lib/motion/project/vendor.rb diff --git a/lib/motion/project.rb b/lib/motion/project.rb index 5768138c..0972eb1d 100644 --- a/lib/motion/project.rb +++ b/lib/motion/project.rb @@ -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 diff --git a/lib/motion/project/builder.rb b/lib/motion/project/builder.rb index 26e8923e..0b88aae5 100644 --- a/lib/motion/project/builder.rb +++ b/lib/motion/project/builder.rb @@ -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 = [] diff --git a/lib/motion/project/config.rb b/lib/motion/project/config.rb index dd6562a4..05dea119 100644 --- a/lib/motion/project/config.rb +++ b/lib/motion/project/config.rb @@ -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| diff --git a/lib/motion/project/vendor.rb b/lib/motion/project/vendor.rb new file mode 100644 index 00000000..32d559ea --- /dev/null +++ b/lib/motion/project/vendor.rb @@ -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