motion_blender 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66517bde47352d1d631eaf58b86b54846704e6ea
4
- data.tar.gz: cbeb710b43f03f046f0cb3ca6491322059a0e3d8
3
+ metadata.gz: 1f62586a884e6abf4b6c8ae93a1d655764f28ad8
4
+ data.tar.gz: 4e7a196e3652339c6dc76a35a0b5fd8b78d7b4e7
5
5
  SHA512:
6
- metadata.gz: 6e5f5ce23150e86b6e69381ae1a92e3c01ab2b18aec637a3b4f131d7892f8f9725c52a57553fd7943f541a4ce14aaf3f77b3f55a5d25a2355eea3bfc409dd28f
7
- data.tar.gz: cfc18c3a8c9cfd5022385a0753cb406d544c6b6f48778bc56b072c4702ec04ec032e9a52bf7ed69c8107e0c0839e3d64befb867f4edcd31deecb6eb1c01e7a0b
6
+ metadata.gz: dcd57b42e5243744ae42c1f968c22c6b507d9a4240e5011a5e66bd19e20638c6768158c09c6afa09482f7680b38ed6d04739e97be15c5c4311b87c3c5c0cc9d7
7
+ data.tar.gz: 1cb179e24b2989a47e0c9b27dbc14f4e32895e6b52dcd33a4c1aee37b8acafa95c6d878c70a3c2b225192f330b3b84e26a3f43cd88cfa6b2f149088bb7dbe873
data/README.md CHANGED
@@ -1,28 +1,125 @@
1
- # MotionBlender
1
+ # MotionBlender [![Build Status](https://travis-ci.org/kayhide/motion_blender.svg?branch=master)](https://travis-ci.org/kayhide/motion_blender)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/motion_blender`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ MotionBlender enables to:
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ - require *Ruby* files (must be RubyMotion-compatible) from RubyMotion files
6
+ - require RubyMotion files from RubyMotion files as well
7
+
8
+ and then:
9
+
10
+ - add required files to `app.files`
11
+ - resolve dependencies following require tree and put it to `app.files_dependencies`
12
+
13
+ This is a sccessor of [motion-require](https://github.com/clayallsopp/motion-require) and [MotionBundler](https://github.com/archan937/motion-bundler).
14
+
15
+ *motion-require* is to resolve dependencies between RubyMotion files with `motion_require` method.
16
+ This is only for RubyMotion files and not for using Ruby gems.
17
+
18
+ *MotionBundler* aims for using Ruby gems from RubyMotion.
19
+ This is good for making an application but not for making a gem, because it requires to setup your application Gemfile explicitly.
20
+
21
+
22
+ So, MotionBlender is good for making RubyMotion-compatible gem which depends on other RubyMotion-compatible gems.
23
+
24
+ I made a fork of MotionSupport which is based on MotionBlender:
25
+
26
+ - [motion_blender-support](https://github.com/kayhide/motion_blender-support)
27
+
28
+ This is ready to use to make RubyMotion-compatible gems.
6
29
 
7
30
  ## Installation
8
31
 
32
+ ### When making a gem
33
+
34
+ Add a dependency:
35
+
36
+ ```ruby
37
+ # in .gemspec file
38
+
39
+ Gem::Specification.new do |spec|
40
+ # ...
41
+ spec.add_runtime_dependency "motion_blender"
42
+ # ...
43
+ end
44
+ ```
45
+
46
+ ### When making an application
47
+
9
48
  Add this line to your application's Gemfile:
10
49
 
11
50
  ```ruby
12
51
  gem 'motion_blender'
13
52
  ```
14
53
 
15
- And then execute:
54
+ ## Usage
16
55
 
17
- $ bundle
56
+ Add RubyMotion-compatible gem into your project (may be an application or a gem).
18
57
 
19
- Or install it yourself as:
58
+ And just call `require` from anywhare:
20
59
 
21
- $ gem install motion_blender
60
+ ```ruby
61
+ require 'rubymotion_conpatible_gem'
22
62
 
23
- ## Usage
63
+ # your code goes on...
64
+ ```
65
+
66
+ Writing a gem (*motion_hoge*), this idiom is handy:
67
+
68
+ ```ruby
69
+ # in lib/motion_hoge.rb
70
+ require 'motion_blender'
71
+ MotionBlender.add __FILE__
72
+
73
+ require 'motion_hoge/simsim'
74
+ require 'motion_hoge/mishmish'
75
+ require 'motion_hoge/version'
76
+ # ...
77
+ ```
78
+
79
+ This makes an app or a gem which depends on *motion_hoge* to load functionalities properly, even if it is compile-time.
80
+
81
+ As a default, `motion_blender` lib files themselves are excluded for analyzing.
82
+ So don't worry about requiring `motion_blender` in compile target files.
83
+
84
+ ### Limitation
85
+
86
+ Currently, `require` has some limitation because of the way how to analyze the code.
87
+
88
+ The argument must be a string or an eval-able expression:
89
+
90
+ ```ruby
91
+ # Good
92
+ require 'something'
93
+ require File.join('path', 'to', 'feature')
94
+ require File.expand_path('../otherthing', __FILE__) # __FILE__ works properly
95
+
96
+ # Bad
97
+ # analyzer does not eval outside of require method
98
+ Dir.glob('lib/**/*.rb').each { |path| require path }
99
+ ```
100
+
101
+ And required files must exist:
102
+
103
+ ```ruby
104
+ # Bad
105
+ begin
106
+ require 'may_not_exist'
107
+ rescue LoadError
108
+ require 'alternative'
109
+ end
110
+ ```
111
+
112
+ ## How does it work?
113
+
114
+ In the RubyMotion application's Rakefile, `motion_blender` is to be required, typically via `Bundler.require`.
115
+ Then it hooks `build` tasks.
116
+ You can hit `rake -P` and see `motion_blender:analyze` task is hooked.
117
+
118
+ At the analyze task, MotionBlender runs analyzer on all `Motion::Project::Config#files`.
119
+ It uses [parser](https://github.com/whitequark/parser) and follows all `require` and `require_relative`.
120
+ After that, add the newly encountered files to the head of `Motion::Project::Config#files` and put file dependencies to `Motion::Project::Config#dependencies`.
24
121
 
25
- TODO: Write usage instructions here
122
+ When compiling, `require` and `require_relative` is overwritten as noop.
26
123
 
27
124
  ## Development
28
125
 
@@ -32,7 +129,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
129
 
33
130
  ## Contributing
34
131
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/kayhide/motion_blender. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
132
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kayhide/motion_blender. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
133
 
37
134
 
38
135
  ## License
@@ -6,9 +6,9 @@ module MotionBlender
6
6
  class Parser
7
7
  REQUIREMENT_TOKENS = %i(motion_require require_relative require)
8
8
 
9
- Require = Struct.new(:loader, :method, :arg, :file)
9
+ Require = Struct.new(:loader, :method, :arg, :file, :trace)
10
10
 
11
- attr_reader :file, :requires
11
+ attr_reader :file, :requires, :last_trace
12
12
 
13
13
  def initialize file
14
14
  @file = file.to_s
@@ -22,16 +22,16 @@ module MotionBlender
22
22
 
23
23
  def traverse ast
24
24
  if ast && ast.type == :send && require_command?(ast)
25
+ @last_trace = trace_for ast
25
26
  req = parse_arg ast
26
27
  req.file = resolve_path req.method, req.arg
28
+ req.trace = @last_trace
27
29
  @requires << req
28
30
  elsif ast
29
31
  ast.children
30
32
  .select { |node| node.is_a?(::Parser::AST::Node) }
31
33
  .each { |node| traverse node }
32
34
  end
33
- rescue LoadError => err
34
- raise err, err.message, [trace_for(ast), *caller]
35
35
  end
36
36
 
37
37
  def require_command? ast
@@ -44,7 +44,7 @@ module MotionBlender
44
44
  Require.new(@file, ast.children[1], arg)
45
45
  rescue
46
46
  exp = ast.loc.expression.source
47
- raise LoadError, "failed to parse `#{exp}'", caller(1)
47
+ raise LoadError, "failed to parse `#{exp}'"
48
48
  end
49
49
 
50
50
  def trace_for ast
@@ -9,27 +9,32 @@ module MotionBlender
9
9
 
10
10
  def initialize
11
11
  @analyzed_files = Set.new
12
+ @exclude_files = Set.new
12
13
  @files = []
13
14
  @dependencies = {}
14
- @exclude_files = []
15
15
  end
16
16
 
17
- def analyze file
17
+ def analyze file, backtrace = []
18
18
  return if @exclude_files.include? file
19
19
  return if @analyzed_files.include? file
20
20
  @analyzed_files << file
21
21
 
22
22
  parser = Parser.new file
23
- parser.parse
24
- parser.requires.reject! do |req|
23
+ begin
24
+ parser.parse
25
+ rescue LoadError => err
26
+ err.set_backtrace [parser.last_trace, *backtrace].compact
27
+ raise err
28
+ end
29
+ requires = parser.requires.reject do |req|
25
30
  @exclude_files.include? req.file
26
31
  end
27
32
 
28
- if parser.requires.any?
29
- @dependencies[file] = parser.requires.map(&:file)
33
+ if requires.any?
34
+ @dependencies[file] = requires.map(&:file)
30
35
  @files = (@files + [file] + @dependencies[file]).uniq
31
- @dependencies[file].each do |f|
32
- analyze f
36
+ requires.each do |req|
37
+ analyze req.file, [req.trace, *backtrace]
33
38
  end
34
39
  end
35
40
  end
@@ -1,3 +1,3 @@
1
1
  module MotionBlender
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -8,7 +8,7 @@ module MotionBlender
8
8
  def analyze
9
9
  Motion::Project::App.setup do |app|
10
10
  analyzer = Analyzer.new
11
- analyzer.exclude_files = Dir[File.expand_path('../**/*.rb', __FILE__)]
11
+ analyzer.exclude_files += Dir[File.expand_path('../**/*.rb', __FILE__)]
12
12
  app.files.flatten.each do |file|
13
13
  analyzer.analyze file
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion_blender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kayhide
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-24 00:00:00.000000000 Z
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser