Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save farcaller/2787464 to your computer and use it in GitHub Desktop.
Save farcaller/2787464 to your computer and use it in GitHub Desktop.
From 59fc7da8ea7be513f452c82a808cbe125ea0dc96 Mon Sep 17 00:00:00 2001
From: Vladimir Pouzanov <farcaller@gmail.com>
Date: Fri, 25 May 2012 14:28:16 +0300
Subject: [PATCH 1/4] Added basic support for gems
---
gem.rb | 3 +++
gem/manager.rb | 15 +++++++++++++++
gem/motion_spec.rb | 18 ++++++++++++++++++
gem/specification.rb | 10 ++++++++++
project.rb | 1 +
project/builder.rb | 14 ++++++++++++++
project/config.rb | 4 +++-
7 files changed, 64 insertions(+), 1 deletions(-)
create mode 100644 gem.rb
create mode 100644 gem/manager.rb
create mode 100644 gem/motion_spec.rb
create mode 100644 gem/specification.rb
diff --git a/gem.rb b/gem.rb
new file mode 100644
index 0000000..8a783a9
--- /dev/null
+++ b/gem.rb
@@ -0,0 +1,3 @@
+require 'motion/gem/specification'
+require 'motion/gem/manager'
+require 'motion/gem/motion_spec'
diff --git a/gem/manager.rb b/gem/manager.rb
new file mode 100644
index 0000000..39188dd
--- /dev/null
+++ b/gem/manager.rb
@@ -0,0 +1,15 @@
+require 'singleton'
+
+module Motion; module Gem
+
+ class Manager
+ include Singleton
+
+ attr_reader :specs
+
+ def initialize
+ @specs = {}
+ end
+ end
+
+end; end
diff --git a/gem/motion_spec.rb b/gem/motion_spec.rb
new file mode 100644
index 0000000..1e3ac3f
--- /dev/null
+++ b/gem/motion_spec.rb
@@ -0,0 +1,18 @@
+module Motion; module Gem
+ # Gem class provides facilites to set up stuff for gem compilation
+ class MotionSpec
+ attr_accessor :files, :spec_files, :hooks, :frameworks, :libs
+
+ def initialize
+ @files = []
+ @spec_files = []
+ @frameworks = []
+ @libs = []
+ @hooks = {}
+ end
+
+ def pre_build(&block)
+ @hooks[:pre_build] = block
+ end
+ end
+end; end
diff --git a/gem/specification.rb b/gem/specification.rb
new file mode 100644
index 0000000..655709b
--- /dev/null
+++ b/gem/specification.rb
@@ -0,0 +1,10 @@
+
+module Gem
+ class Specification
+ def motion(name)
+ spec = Motion::Gem::MotionSpec.new
+ yield spec
+ Motion::Gem::Manager.instance.specs[name] = spec
+ end
+ end
+end
diff --git a/project.rb b/project.rb
index 7ee1c59..6cf7461 100644
--- a/project.rb
+++ b/project.rb
@@ -4,6 +4,7 @@
# Agreement accompanying the package this file is a part of.
require 'motion/version'
+require 'motion/gem.rb'
require 'motion/project/app'
require 'motion/project/config'
require 'motion/project/builder'
diff --git a/project/builder.rb b/project/builder.rb
index 9eafc6f..227cbc0 100644
--- a/project/builder.rb
+++ b/project/builder.rb
@@ -30,6 +30,20 @@ module Motion; module Project;
# Prepare the list of BridgeSupport files needed.
bs_files = config.bridgesupport_files
+
+ # Infect config with motionspecs
+ Motion::Gem::Manager.instance.specs.each do |name, spec|
+ # pre-build early as it might modify the spec
+ spec.hooks[:pre_build].call(config) if spec.hooks[:pre_build]
+
+ # files, spec_files
+ config.files = spec.files + config.files
+ config.spec_files = spec.spec_files + config.spec_files
+
+ # add missing frameworks and libs
+ config.frameworks |= spec.frameworks
+ config.libs |= spec.libs
+ end
# Build vendor libraries.
vendor_libs = []
diff --git a/project/config.rb b/project/config.rb
index 0e2fa70..bef142f 100644
--- a/project/config.rb
+++ b/project/config.rb
@@ -269,9 +269,11 @@ EOS
bs_files
end
end
+
+ attr_writer :spec_files
def spec_files
- Dir.glob(File.join(specs_dir, '**', '*.rb'))
+ @spec_files ||= Dir.glob(File.join(specs_dir, '**', '*.rb'))
end
def motiondir
--
1.7.8
From d90fa9de3649657c0467c2041d35c1797d262a25 Mon Sep 17 00:00:00 2001
From: Vladimir Pouzanov <farcaller@gmail.com>
Date: Fri, 25 May 2012 14:45:07 +0300
Subject: [PATCH 2/4] Added support vor vendor projects
---
gem/motion_spec.rb | 9 ++++++++-
project/builder.rb | 3 +++
2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/gem/motion_spec.rb b/gem/motion_spec.rb
index 1e3ac3f..8a6515d 100644
--- a/gem/motion_spec.rb
+++ b/gem/motion_spec.rb
@@ -1,7 +1,9 @@
module Motion; module Gem
# Gem class provides facilites to set up stuff for gem compilation
class MotionSpec
- attr_accessor :files, :spec_files, :hooks, :frameworks, :libs
+ attr_accessor :files, :spec_files, :frameworks, :libs
+
+ attr_reader :hooks, :vendor_projects
def initialize
@files = []
@@ -9,10 +11,15 @@ module Motion; module Gem
@frameworks = []
@libs = []
@hooks = {}
+ @vendor_projects = []
end
def pre_build(&block)
@hooks[:pre_build] = block
end
+
+ def vendor_project(*args)
+ @vendor_projects << args
+ end
end
end; end
diff --git a/project/builder.rb b/project/builder.rb
index 227cbc0..4ad00b0 100644
--- a/project/builder.rb
+++ b/project/builder.rb
@@ -43,6 +43,9 @@ module Motion; module Project;
# add missing frameworks and libs
config.frameworks |= spec.frameworks
config.libs |= spec.libs
+
+ # add vendor projects
+ spec.vendor_projects.each { |args| config.vendor_project(*args) }
end
# Build vendor libraries.
--
1.7.8
From 7a971c365857bf98f24304ed32dd080b8c65b027 Mon Sep 17 00:00:00 2001
From: Vladimir Pouzanov <farcaller@gmail.com>
Date: Fri, 25 May 2012 14:56:34 +0300
Subject: [PATCH 3/4] Added support for gem resources
---
gem/motion_spec.rb | 2 +-
project/builder.rb | 41 ++++++++++++++++++++++++++---------------
2 files changed, 27 insertions(+), 16 deletions(-)
diff --git a/gem/motion_spec.rb b/gem/motion_spec.rb
index 8a6515d..dcd4fc4 100644
--- a/gem/motion_spec.rb
+++ b/gem/motion_spec.rb
@@ -1,7 +1,7 @@
module Motion; module Gem
# Gem class provides facilites to set up stuff for gem compilation
class MotionSpec
- attr_accessor :files, :spec_files, :frameworks, :libs
+ attr_accessor :files, :spec_files, :frameworks, :libs, :resources_dir
attr_reader :hooks, :vendor_projects
diff --git a/project/builder.rb b/project/builder.rb
index 4ad00b0..5641c4d 100644
--- a/project/builder.rb
+++ b/project/builder.rb
@@ -335,21 +335,13 @@ EOS
]
resources_files = []
if File.exist?(config.resources_dir)
- resources_files = Dir.chdir(config.resources_dir) do
- Dir.glob('**/*').reject { |x| ['.xib', '.storyboard', '.xcdatamodeld', '.lproj'].include?(File.extname(x)) }
- end
- resources_files.each do |res|
- res_path = File.join(config.resources_dir, res)
- if reserved_app_bundle_files.include?(res)
- App.fail "Cannot use `#{res_path}' as a resource file because it's a reserved application bundle file"
- end
- dest_path = File.join(bundle_path, res)
- if !File.exist?(dest_path) or File.mtime(res_path) > File.mtime(dest_path)
- FileUtils.mkdir_p(File.dirname(dest_path))
- App.info 'Copy', res_path
- FileUtils.cp_r(res_path, File.dirname(dest_path))
- end
- end
+ resources_files += copy_resources(reserved_app_bundle_files, bundle_path, config.resources_dir)
+ end
+
+ # Copy resources of gems
+ # TODO: compile compilable resources
+ Motion::Gem::Manager.instance.specs.each do |name, spec|
+ resources_files += copy_resources(reserved_app_bundle_files, bundle_path, spec.resources_dir) if spec.resources_dir
end
# Delete old resource files.
@@ -376,6 +368,25 @@ EOS
sh "#{config.locate_binary('strip')} \"#{main_exec}\""
end
end
+
+ def copy_resources(reserved_app_bundle_files, bundle_path, resources_dir)
+ resources_files = Dir.chdir(resources_dir) do
+ Dir.glob('**/*').reject { |x| ['.xib', '.storyboard', '.xcdatamodeld', '.lproj'].include?(File.extname(x)) }
+ end
+ resources_files.each do |res|
+ res_path = File.join(resources_dir, res)
+ if reserved_app_bundle_files.include?(res)
+ App.fail "Cannot use `#{res_path}' as a resource file because it's a reserved application bundle file"
+ end
+ dest_path = File.join(bundle_path, res)
+ if !File.exist?(dest_path) or File.mtime(res_path) > File.mtime(dest_path)
+ FileUtils.mkdir_p(File.dirname(dest_path))
+ App.info 'Copy', res_path
+ FileUtils.cp_r(res_path, File.dirname(dest_path))
+ end
+ end
+ resources_files
+ end
def codesign(config, platform)
bundle_path = config.app_bundle(platform)
--
1.7.8
From 025971918577ef26039506b04b73b01e008a330d Mon Sep 17 00:00:00 2001
From: Vladimir Pouzanov <farcaller@gmail.com>
Date: Fri, 25 May 2012 15:10:12 +0300
Subject: [PATCH 4/4] Recalculate framework dependencies when frameworks
change
---
project/config.rb | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/project/config.rb b/project/config.rb
index bef142f..7b5da72 100644
--- a/project/config.rb
+++ b/project/config.rb
@@ -236,6 +236,11 @@ EOS
end
def frameworks_dependencies
+ if @frameworks_dependencies_frozen && @frameworks_dependencies_frozen != frameworks.to_s
+ @frameworks_dependencies = nil
+ end
+ @frameworks_dependencies_frozen = frameworks.to_s
+
@frameworks_dependencies ||= begin
# Compute the list of frameworks, including dependencies, that the project uses.
deps = []
--
1.7.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment