rubygems-compile 1.0.0rc2 → 1.0.0rc3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +16 -6
- data/Rakefile +9 -12
- data/lib/rubygems-compile/analyzer.rb +23 -0
- data/lib/rubygems-compile/common_methods.rb +1 -0
- data/lib/rubygems-compile/compiler.rb +14 -1
- data/lib/rubygems_plugin.rb +1 -0
- data/test/helper.rb +1 -1
- data/test/test_analyzer.rb +13 -0
- data/test/test_autocompile_command.rb +10 -10
- data/test/test_common_methods.rb +39 -0
- data/test/test_compile_command.rb +22 -26
- data/test/test_uncompile_command.rb +6 -6
- metadata +12 -8
- data/lib/rubygems-compile/analysis.rb +0 -11
data/README.markdown
CHANGED
@@ -15,7 +15,8 @@ And then you're off to the races!
|
|
15
15
|
|
16
16
|
`compile`
|
17
17
|
|
18
|
-
Can be used to compile, or re-compile, any gems that are
|
18
|
+
Can be used to compile, or re-compile, any gems that are already
|
19
|
+
installed.
|
19
20
|
|
20
21
|
```bash
|
21
22
|
sudo macgem compile nokogiri # Compile gems based on names you provide
|
@@ -26,7 +27,11 @@ sudo macgem compile rspec --no-ignore-dependencies # Also compile dependencies
|
|
26
27
|
|
27
28
|
`uncompile`
|
28
29
|
|
29
|
-
Can be used to remove the compiled `.rbo` files if a gem does not
|
30
|
+
Can be used to remove the compiled `.rbo` files if a gem does not
|
31
|
+
work well when compiled. If you find a gem that does not work when
|
32
|
+
compiled, it would be greatly appreciated if you reported it here or
|
33
|
+
to the MacRuby project itself so that someone can look into the
|
34
|
+
problem.
|
30
35
|
|
31
36
|
```bash
|
32
37
|
sudo macgem uncompile nokogiri # Uncompile gems based on names you provide
|
@@ -35,9 +40,13 @@ sudo macgem uncompile --all # Uncompile all installed
|
|
35
40
|
sudo macgem uncompile rspec --no-ignore-dependencies # Also uncompile dependencies
|
36
41
|
```
|
37
42
|
|
38
|
-
`
|
43
|
+
`auto_compile`
|
39
44
|
|
40
|
-
|
45
|
+
If you don't like the idea of calling `compile` each time you
|
46
|
+
install a gem, then you can use `auto_compile` to enable a
|
47
|
+
post-install hook that will automatically compile gems when they are
|
48
|
+
installed. You can call `auto_compile` a second time to turn off the
|
49
|
+
feature.
|
41
50
|
|
42
51
|
```bash
|
43
52
|
sudo macgem auto_compile # gems will compiled when you install them
|
@@ -51,7 +60,7 @@ sudo macgem auto_compile # gems will not be compiled when you install them
|
|
51
60
|
* This has only been tested on a few gems, but should not break
|
52
61
|
existing gems since we leave the original files around
|
53
62
|
* At the moment, compiled gems will not provide usable backtraces
|
54
|
-
+ If you suspect a bug in the way MacRuby compiled a file, try running with pre-compiled files disabled like so: `VM_DISABLE_RBO=1
|
63
|
+
+ If you suspect a bug in the way MacRuby compiled a file, try running with pre-compiled files disabled like so: `VM_DISABLE_RBO=1 macruby my_code.rb`
|
55
64
|
* `.rbo` files take up more disk space than their `.rb` equivalents
|
56
65
|
|
57
66
|
## Known Issues
|
@@ -59,7 +68,8 @@ sudo macgem auto_compile # gems will not be compiled when you install them
|
|
59
68
|
* Source files using a non-standard suffix (e.g. `mime-types` has a `.rb.data` file) will not get compiled
|
60
69
|
+ This might be addressable in a later release, but is not a big deal
|
61
70
|
* Gems that explicitly require a file with the file suffix (e.g. `require 'nokogiri.rb'`) will never load the compiled version of the file
|
62
|
-
+
|
71
|
+
+ This issue may be addressed in MacRuby itself in the near future
|
72
|
+
+ Alternatively, those gems should be updated so that compiled code can be loaded
|
63
73
|
|
64
74
|
## TODO
|
65
75
|
|
data/Rakefile
CHANGED
@@ -1,24 +1,21 @@
|
|
1
|
-
require 'rake/testtask'
|
2
|
-
require 'rake/gempackagetask'
|
3
|
-
require 'rubygems/dependency_installer'
|
4
|
-
|
5
1
|
task :default => :gem
|
6
2
|
|
7
|
-
|
8
|
-
|
3
|
+
require 'rake/testtask'
|
4
|
+
Rake::TestTask.new do |test|
|
5
|
+
test.libs << 'test'
|
9
6
|
test.pattern = 'test/**/test_*.rb'
|
10
7
|
test.verbose = true
|
11
8
|
test.ruby_opts = ['-rhelper']
|
12
9
|
end
|
13
10
|
|
14
|
-
|
11
|
+
require 'rubygems'
|
12
|
+
spec = Gem::Specification.load('rubygems-compile.gemspec')
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
pkg.need_tar = true
|
19
|
-
end
|
14
|
+
require 'rake/gempackagetask'
|
15
|
+
Rake::GemPackageTask.new(spec) { }
|
20
16
|
|
17
|
+
require 'rubygems/dependency_installer'
|
21
18
|
desc 'Build the gem and install it'
|
22
19
|
task :install => :gem do
|
23
|
-
Gem::Installer.new("pkg/#{
|
20
|
+
Gem::Installer.new("pkg/#{spec.file_name}").install
|
24
21
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'ripper'
|
2
|
+
|
3
|
+
##
|
4
|
+
# Uses the ripper parser to analyze ruby code contained in gems
|
5
|
+
# and raises warnings if the code has potential issues.
|
6
|
+
|
7
|
+
class Gem::Analyzer < Ripper::SexpBuilder
|
8
|
+
|
9
|
+
##
|
10
|
+
# Raised in any case that the given code might display bad
|
11
|
+
# behaviours that were not intended.
|
12
|
+
|
13
|
+
class Warning < Exception
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_kw token
|
17
|
+
# Related to MacRuby ticket #721
|
18
|
+
if token == '__FILE__'
|
19
|
+
raise Warning, 'The __FILE__ keyword is used in this file'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -19,6 +19,7 @@ class Gem::Compiler
|
|
19
19
|
gem_files.each do |file|
|
20
20
|
say compile_file_msg(file) if @config.really_verbose
|
21
21
|
absolute_file_path = File.join(@spec.full_gem_path, file)
|
22
|
+
next if unsafe?(absolute_file_path)
|
22
23
|
MacRuby::Compiler.new(
|
23
24
|
bundle: true,
|
24
25
|
output: "#{absolute_file_path}o",
|
@@ -26,9 +27,21 @@ class Gem::Compiler
|
|
26
27
|
).run
|
27
28
|
end
|
28
29
|
end
|
29
|
-
|
30
30
|
alias_method :compile, :call
|
31
31
|
|
32
|
+
##
|
33
|
+
# Uses the GemAnalyzer class to determine if a given file might have
|
34
|
+
# any potential issues when compiled.
|
35
|
+
|
36
|
+
def unsafe? file
|
37
|
+
Gem::Analyzer.new(File.read(file)).parse
|
38
|
+
false
|
39
|
+
rescue Gem::Analyzer::Warning => e
|
40
|
+
say "WARNING: #{e.message}"
|
41
|
+
say 'Compilation of this file will be skipped'
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
32
45
|
def compilation_message
|
33
46
|
slash = @config.really_verbose ? '/' : ''
|
34
47
|
"Compiling #{@spec.full_name}#{slash}"
|
data/lib/rubygems_plugin.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
class TestGemAnalyzer < MiniTest::Unit::TestCase
|
2
|
+
|
3
|
+
def test_finds_usage_of___FILE__
|
4
|
+
assert_raises Gem::Analyzer::Warning do
|
5
|
+
Gem::Analyzer.new("__FILE__").parse
|
6
|
+
end
|
7
|
+
|
8
|
+
assert_block do
|
9
|
+
Gem::Analyzer.new("puts '__FILE__'").parse
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -4,19 +4,19 @@ class TestAutoCompile < MiniTest::Unit::TestCase
|
|
4
4
|
@command = Gem::Commands::AutoCompileCommand.new
|
5
5
|
end
|
6
6
|
|
7
|
-
def test_turn_on
|
8
|
-
end
|
7
|
+
# def test_turn_on
|
8
|
+
# end
|
9
9
|
|
10
|
-
def test_turn_on_when_already_on
|
11
|
-
end
|
10
|
+
# def test_turn_on_when_already_on
|
11
|
+
# end
|
12
12
|
|
13
|
-
def test_turn_off
|
14
|
-
end
|
13
|
+
# def test_turn_off
|
14
|
+
# end
|
15
15
|
|
16
|
-
def test_turn_off_when_already_off
|
17
|
-
end
|
16
|
+
# def test_turn_off_when_already_off
|
17
|
+
# end
|
18
18
|
|
19
|
-
def test_calls_compile_on_each_gem_after_installation
|
20
|
-
end
|
19
|
+
# def test_calls_compile_on_each_gem_after_installation
|
20
|
+
# end
|
21
21
|
|
22
22
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# class CommonMethodsTester
|
2
|
+
# include Gem::CompileMethods
|
3
|
+
|
4
|
+
# class Gem
|
5
|
+
# class << self
|
6
|
+
# def source_index
|
7
|
+
# GemList.new
|
8
|
+
# end
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
|
12
|
+
# end
|
13
|
+
|
14
|
+
# class GemList
|
15
|
+
# def all_gems
|
16
|
+
# ['the', 'answer', 'to', 'life', 'the', 'universe', 'and', 'everything']
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
|
20
|
+
# class TestCommonMethods < MiniTest::Unit::TestCase
|
21
|
+
|
22
|
+
# def modul
|
23
|
+
# @@modul ||= CommonMethodsTester.new
|
24
|
+
# end
|
25
|
+
|
26
|
+
# def test_execution_list
|
27
|
+
# end
|
28
|
+
|
29
|
+
# def test_gems_list
|
30
|
+
# def modul.options
|
31
|
+
# { all: true }
|
32
|
+
# end
|
33
|
+
# assert_equal GemList.new.all_gems, modul.gems_list
|
34
|
+
# end
|
35
|
+
|
36
|
+
# def test_dependencies_for
|
37
|
+
# end
|
38
|
+
|
39
|
+
# end
|
@@ -1,36 +1,32 @@
|
|
1
1
|
class TestCompileCommand < MiniTest::Unit::TestCase
|
2
|
+
|
2
3
|
def setup
|
3
4
|
@command = Gem::Commands::CompileCommand.new
|
4
5
|
end
|
5
|
-
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
7
|
+
# def test_finds_all_files
|
8
|
+
# # gets into all require dirs
|
9
|
+
# # does not compile test files
|
10
|
+
# end
|
11
|
+
# def test_recompiles_rbos_if_they_already_exist
|
12
|
+
# # to support use on nightly builds
|
13
|
+
# end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
15
|
+
# def test_has_an_option_to_compile_all_installed_gems
|
16
|
+
# # by extension, this is also needed to support nightly build users
|
17
|
+
# end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
19
|
+
# def test_refuses_to_compile_itself
|
20
|
+
# # obvious
|
21
|
+
# end
|
27
22
|
|
28
|
-
def test_loads_rubyc_without_warning
|
29
|
-
|
30
|
-
end
|
23
|
+
# def test_loads_rubyc_without_warning
|
24
|
+
# # this might not be doable without upstream load guarding; minor issue
|
25
|
+
# end
|
26
|
+
|
27
|
+
# # important to test so we don't break rubygems
|
28
|
+
# def test_skips_loading_on_older_macruby_versions
|
29
|
+
# # and prints a message
|
30
|
+
# end
|
31
31
|
|
32
|
-
# important to test so we don't break rubygems
|
33
|
-
def test_skips_loading_on_older_macruby_versions
|
34
|
-
# and prints a message
|
35
|
-
end
|
36
32
|
end
|
@@ -4,13 +4,13 @@ class TestUncompileCommand < MiniTest::Unit::TestCase
|
|
4
4
|
@command = Gem::Commands::UncompileCommand.new
|
5
5
|
end
|
6
6
|
|
7
|
-
def test_removes_rbo_files
|
8
|
-
end
|
7
|
+
# def test_removes_rbo_files
|
8
|
+
# end
|
9
9
|
|
10
|
-
def test_leaves_rb_files
|
11
|
-
end
|
10
|
+
# def test_leaves_rb_files
|
11
|
+
# end
|
12
12
|
|
13
|
-
def test_can_uncompile_multiple_gems_at_once
|
14
|
-
end
|
13
|
+
# def test_can_uncompile_multiple_gems_at_once
|
14
|
+
# end
|
15
15
|
|
16
16
|
end
|
metadata
CHANGED
@@ -2,33 +2,33 @@
|
|
2
2
|
name: rubygems-compile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 5
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.0rc3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mark Rada
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-15 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name: minitest
|
16
|
+
name: minitest
|
17
17
|
prerelease: false
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - '>='
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 2.
|
23
|
+
version: 2.6.1
|
24
24
|
type: :development
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
27
|
requirements:
|
28
28
|
- - '>='
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: 2.
|
31
|
-
description: 'A
|
30
|
+
version: 2.6.1
|
31
|
+
description: 'A trio of rubygems commands that interface with the MacRuby compiler.
|
32
32
|
|
33
33
|
'
|
34
34
|
email: mrada@marketcircle.com
|
@@ -38,7 +38,7 @@ extra_rdoc_files:
|
|
38
38
|
- LICENSE.txt
|
39
39
|
- README.markdown
|
40
40
|
files:
|
41
|
-
- lib/rubygems-compile/
|
41
|
+
- lib/rubygems-compile/analyzer.rb
|
42
42
|
- lib/rubygems-compile/commands/autocompile_command.rb
|
43
43
|
- lib/rubygems-compile/commands/compile_command.rb
|
44
44
|
- lib/rubygems-compile/commands/uncompile_command.rb
|
@@ -49,7 +49,9 @@ files:
|
|
49
49
|
- lib/rubygems-compile/uncompiler.rb
|
50
50
|
- lib/rubygems_plugin.rb
|
51
51
|
- test/helper.rb
|
52
|
+
- test/test_analyzer.rb
|
52
53
|
- test/test_autocompile_command.rb
|
54
|
+
- test/test_common_methods.rb
|
53
55
|
- test/test_compile_command.rb
|
54
56
|
- test/test_uncompile_command.rb
|
55
57
|
- Rakefile
|
@@ -85,10 +87,12 @@ rubyforge_project:
|
|
85
87
|
rubygems_version: 1.4.2
|
86
88
|
signing_key:
|
87
89
|
specification_version: 3
|
88
|
-
summary: A
|
90
|
+
summary: A trio of rubygems commands that interface with the MacRuby compiler
|
89
91
|
test_files:
|
90
92
|
- test/helper.rb
|
93
|
+
- test/test_analyzer.rb
|
91
94
|
- test/test_autocompile_command.rb
|
95
|
+
- test/test_common_methods.rb
|
92
96
|
- test/test_compile_command.rb
|
93
97
|
- test/test_uncompile_command.rb
|
94
98
|
- Rakefile
|