rubygems-compile 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -3
- data/lib/rubygems-compile/analyzer.rb +17 -4
- data/lib/rubygems-compile/commands/compile_command.rb +3 -6
- data/lib/rubygems-compile/commands/uncompile_command.rb +2 -3
- data/lib/rubygems-compile/compile_methods.rb +74 -0
- data/lib/rubygems-compile/compiler.rb +37 -28
- data/lib/rubygems-compile/post_install_hook.rb +1 -1
- data/lib/rubygems-compile/uncompiler.rb +7 -1
- metadata +4 -6
- data/lib/rubygems-compile/common_methods.rb +0 -40
data/README.markdown
CHANGED
@@ -6,7 +6,7 @@ MacRuby compiler. This gem requires MacRuby 0.11 or newer.
|
|
6
6
|
All you need to do is:
|
7
7
|
|
8
8
|
```bash
|
9
|
-
sudo macgem install rubygems-compile
|
9
|
+
sudo macgem install rubygems-compile
|
10
10
|
```
|
11
11
|
|
12
12
|
And then you're off to the races!
|
@@ -73,11 +73,10 @@ sudo macgem auto_compile # gems will not be compiled when you install them
|
|
73
73
|
|
74
74
|
## TODO
|
75
75
|
|
76
|
-
* Code parsing to WARN about gems that will have issues when compiled
|
77
76
|
* Parallel compilation to speed up compilation of large gems
|
78
77
|
+ This might require changes in the MacRuby compiler
|
79
78
|
|
80
79
|
## Copyright
|
81
80
|
|
82
|
-
Copyright (c) 2011 Mark Rada. See LICENSE.txt for further details.
|
81
|
+
Copyright (c) 2011-2012 Mark Rada. See LICENSE.txt for further details.
|
83
82
|
|
@@ -7,16 +7,29 @@ require 'ripper'
|
|
7
7
|
class Gem::Analyzer < Ripper::SexpBuilder
|
8
8
|
|
9
9
|
##
|
10
|
-
#
|
11
|
-
# behaviours that were not intended.
|
10
|
+
# Cache of issues found for the current session.
|
12
11
|
|
13
|
-
|
12
|
+
attr_reader :warnings
|
13
|
+
|
14
|
+
##
|
15
|
+
# Check the given string of code for potential issues when compiled.
|
16
|
+
# Returns the analyzer instance afterwards.
|
17
|
+
|
18
|
+
def self.check code
|
19
|
+
@parser ||= Gem::Analyzer.new(code)
|
20
|
+
@parser.parse
|
21
|
+
@parser
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse
|
25
|
+
@warnings = []
|
26
|
+
super
|
14
27
|
end
|
15
28
|
|
16
29
|
def on_kw token
|
17
30
|
# Related to MacRuby ticket #721
|
18
31
|
if token == '__FILE__'
|
19
|
-
|
32
|
+
@warnings << '__FILE__ keyword is used (MacRuby ticket #721)'
|
20
33
|
end
|
21
34
|
end
|
22
35
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rubygems/dependency_list'
|
2
2
|
require 'rubygems/version_option'
|
3
|
-
require 'rubygems-compile/
|
3
|
+
require 'rubygems-compile/compile_methods'
|
4
4
|
|
5
5
|
|
6
6
|
##
|
@@ -41,15 +41,12 @@ class Gem::Commands::CompileCommand < Gem::Command
|
|
41
41
|
|
42
42
|
def execute
|
43
43
|
gems = execution_list
|
44
|
-
gems.delete_if { |spec| spec.name == 'rubygems-compile' }
|
45
|
-
|
46
44
|
if gems.count >= 10
|
47
|
-
alert 'This could take a while
|
45
|
+
alert 'This could take a while...'
|
48
46
|
end
|
49
47
|
|
50
48
|
require 'rubygems-compile/compiler'
|
51
|
-
|
52
|
-
gems.each { |gem| compiler.compile(gem) }
|
49
|
+
gems.each { |gem| Gem::Compiler.compile gem }
|
53
50
|
end
|
54
51
|
|
55
52
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems/version_option'
|
2
|
-
require 'rubygems-compile/
|
2
|
+
require 'rubygems-compile/compile_methods'
|
3
3
|
|
4
4
|
class Gem::Commands::UncompileCommand < Gem::Command
|
5
5
|
include Gem::VersionOption
|
@@ -36,8 +36,7 @@ class Gem::Commands::UncompileCommand < Gem::Command
|
|
36
36
|
|
37
37
|
def execute
|
38
38
|
require 'rubygems-compile/uncompiler'
|
39
|
-
|
40
|
-
execution_list.each { |gem| uncompiler.uncompile(gem) }
|
39
|
+
execution_list.each { |gem| Gem::Uncompiler.uncompile(gem) }
|
41
40
|
end
|
42
41
|
|
43
42
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Gem::CompileMethods
|
2
|
+
if Gem::VERSION.to_f < 1.8
|
3
|
+
|
4
|
+
def execution_list
|
5
|
+
return all_gemspecs if options[:all]
|
6
|
+
|
7
|
+
specs = get_all_gem_names.map do |gem|
|
8
|
+
candidates = Gem.source_index.find_name(gem, options[:version])
|
9
|
+
|
10
|
+
if candidates.empty?
|
11
|
+
alert_error "#{gem} is not installed. Skipping."
|
12
|
+
next
|
13
|
+
end
|
14
|
+
|
15
|
+
candidates << dependencies_for(candidates) unless options[:ignore]
|
16
|
+
candidates
|
17
|
+
end
|
18
|
+
specs.flatten!
|
19
|
+
specs.uniq!
|
20
|
+
specs.delete_if { |spec| spec.name == 'rubygems-compile' }
|
21
|
+
specs
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def all_gemspecs
|
28
|
+
specs = Gem.source_index.all_gems.map(&:last)
|
29
|
+
specs.select { |spec| spec.name != 'rubygems-compile' }
|
30
|
+
end
|
31
|
+
|
32
|
+
def dependencies_for specs
|
33
|
+
specs.map { |spec|
|
34
|
+
spec.runtime_dependencies.map { |dep|
|
35
|
+
deps = Gem.source_index.find_name(dep.name, dep.requirement)
|
36
|
+
deps + dependencies_for(deps)
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
else
|
42
|
+
|
43
|
+
def execution_list
|
44
|
+
return all_gemspecs if options[:all]
|
45
|
+
|
46
|
+
specs = get_all_gem_names.map { |gem|
|
47
|
+
gems = Gem::Specification.find_all_by_name(gem, options[:version])
|
48
|
+
gems << dependencies_for(gems) unless options[:ignore]
|
49
|
+
gems
|
50
|
+
}
|
51
|
+
specs.flatten!
|
52
|
+
specs.uniq!
|
53
|
+
specs.delete_if { |spec| spec.name == 'rubygems_compile' }
|
54
|
+
specs
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def all_gemspecs
|
61
|
+
Gem::Specification.select { |spec| spec.name != 'rubygems-compile' }
|
62
|
+
end
|
63
|
+
|
64
|
+
def dependencies_for specs
|
65
|
+
specs.map { |spec|
|
66
|
+
spec.runtime_dependencies.map { |dep|
|
67
|
+
deps = Gem::Specification.find_all_by_name(dep.name, dep.requirement)
|
68
|
+
deps + dependencies_for(deps)
|
69
|
+
}
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
@@ -1,6 +1,14 @@
|
|
1
1
|
class Gem::Compiler
|
2
2
|
include Gem::UserInteraction
|
3
3
|
|
4
|
+
class << self
|
5
|
+
def compile gem
|
6
|
+
@instance ||= Gem::Compiler.new
|
7
|
+
@instance.compile gem
|
8
|
+
end
|
9
|
+
alias_method :call, :compile
|
10
|
+
end
|
11
|
+
|
4
12
|
def initialize
|
5
13
|
require 'rbconfig'
|
6
14
|
unless MacRuby.const_defined?(:Compiler)
|
@@ -12,45 +20,34 @@ class Gem::Compiler
|
|
12
20
|
@config = Gem.configuration
|
13
21
|
end
|
14
22
|
|
15
|
-
def
|
23
|
+
def compile gem
|
16
24
|
@spec = gem.is_a?(Gem::Specification) ? gem : gem.spec
|
17
25
|
|
18
|
-
if
|
19
|
-
|
20
|
-
return
|
21
|
-
end
|
22
|
-
|
23
|
-
say compilation_message if verbose
|
26
|
+
return if trying_to_compile_self?
|
27
|
+
say gem_compilation_message if verbose
|
24
28
|
|
25
29
|
gem_files.each do |file|
|
26
|
-
message
|
27
|
-
|
28
|
-
if
|
29
|
-
message << "\t\t\tSKIPPED: #{
|
30
|
+
message = compile_file_message(file)
|
31
|
+
full_path = File.join(@spec.full_gem_path, file)
|
32
|
+
if unsafe? full_path
|
33
|
+
message << "\t\t\tSKIPPED: #{@parser.warnings.join(', ')}"
|
30
34
|
else
|
31
|
-
MacRuby::Compiler.
|
32
|
-
bundle: true,
|
33
|
-
output: "#{absolute_file_path}o",
|
34
|
-
files: [absolute_file_path]
|
35
|
-
).run
|
35
|
+
MacRuby::Compiler.compile_file full_path
|
36
36
|
end
|
37
37
|
say message if really_verbose
|
38
38
|
end
|
39
39
|
end
|
40
|
-
alias_method :compile, :call
|
41
40
|
|
42
41
|
##
|
43
42
|
# Uses the GemAnalyzer class to determine if a given file might have
|
44
43
|
# any potential issues when compiled.
|
45
44
|
|
46
45
|
def unsafe? file
|
47
|
-
Gem::Analyzer.
|
48
|
-
|
49
|
-
rescue Gem::Analyzer::Warning => e
|
50
|
-
e
|
46
|
+
@parser = Gem::Analyzer.check File.read(file)
|
47
|
+
!@parser.warnings.empty?
|
51
48
|
end
|
52
49
|
|
53
|
-
def
|
50
|
+
def gem_compilation_message
|
54
51
|
slash = really_verbose ? '/' : ''
|
55
52
|
"Compiling #{@spec.full_name}#{slash}"
|
56
53
|
end
|
@@ -67,14 +64,19 @@ class Gem::Compiler
|
|
67
64
|
# level or test directory.
|
68
65
|
#
|
69
66
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
if Gem::VERSION.to_f < 1.8
|
68
|
+
def gem_files
|
69
|
+
@spec.lib_files.select { |file| File.extname(file) == '.rb' }
|
70
|
+
end
|
71
|
+
else
|
72
|
+
def gem_files
|
73
|
+
Dir.glob("#{@spec.lib_dirs_glob}/**/*.rb").map { |file|
|
74
|
+
file.sub(Regexp.new(Regexp.escape(@spec.full_gem_path)), '')
|
75
|
+
}
|
76
|
+
end
|
75
77
|
end
|
76
78
|
|
77
|
-
def
|
79
|
+
def compile_file_message file
|
78
80
|
name = File.basename(file)
|
79
81
|
dirs = file.chomp(name).split(File::SEPARATOR)
|
80
82
|
tabs = "\t" * dirs.count
|
@@ -97,4 +99,11 @@ class Gem::Compiler
|
|
97
99
|
@config.really_verbose
|
98
100
|
end
|
99
101
|
|
102
|
+
def trying_to_compile_self?
|
103
|
+
if @spec.name == 'rubygems-compile'
|
104
|
+
alert 'You cannot compile rubygems-compile' if really_verbose
|
105
|
+
true
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
100
109
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
class Gem::Uncompiler
|
2
2
|
include Gem::UserInteraction
|
3
3
|
|
4
|
+
def self.uncompile gem
|
5
|
+
@instance ||= Gem::Uncompiler.new
|
6
|
+
@instance.uncompile gem
|
7
|
+
end
|
8
|
+
|
4
9
|
def initialize
|
10
|
+
require 'fileutils'
|
5
11
|
@config = Gem.configuration
|
6
12
|
end
|
7
13
|
|
@@ -11,9 +17,9 @@ class Gem::Uncompiler
|
|
11
17
|
say uncompilation_message if @config.verbose
|
12
18
|
|
13
19
|
gem_files.each do |file|
|
14
|
-
say "\tAsploded #{file}" if @config.really_verbose
|
15
20
|
absolute_file_path = File.join(@spec.full_gem_path, file)
|
16
21
|
FileUtils.rm absolute_file_path
|
22
|
+
say "\tAsploded #{file}" if @config.really_verbose
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
metadata
CHANGED
@@ -2,15 +2,14 @@
|
|
2
2
|
name: rubygems-compile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0
|
5
|
+
version: 1.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Mark Rada
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
13
|
-
default_executable:
|
12
|
+
date: 2012-02-12 00:00:00 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: minitest
|
@@ -42,7 +41,7 @@ files:
|
|
42
41
|
- lib/rubygems-compile/commands/autocompile_command.rb
|
43
42
|
- lib/rubygems-compile/commands/compile_command.rb
|
44
43
|
- lib/rubygems-compile/commands/uncompile_command.rb
|
45
|
-
- lib/rubygems-compile/
|
44
|
+
- lib/rubygems-compile/compile_methods.rb
|
46
45
|
- lib/rubygems-compile/compiler.rb
|
47
46
|
- lib/rubygems-compile/post_install_hook.rb
|
48
47
|
- lib/rubygems-compile/uncompiler.rb
|
@@ -57,7 +56,6 @@ files:
|
|
57
56
|
- .gemtest
|
58
57
|
- LICENSE.txt
|
59
58
|
- README.markdown
|
60
|
-
has_rdoc: true
|
61
59
|
homepage: http://github.com/ferrous26/rubygems-compile
|
62
60
|
licenses:
|
63
61
|
- MIT
|
@@ -83,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
81
|
version: "0"
|
84
82
|
requirements: []
|
85
83
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.
|
84
|
+
rubygems_version: 1.8.15
|
87
85
|
signing_key:
|
88
86
|
specification_version: 3
|
89
87
|
summary: A trio of rubygems commands that interface with the MacRuby compiler
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Gem
|
2
|
-
|
3
|
-
module CompileMethods
|
4
|
-
|
5
|
-
def execution_list
|
6
|
-
gems_list.map do |gem|
|
7
|
-
candidates = Gem.source_index.find_name(gem, options[:version])
|
8
|
-
|
9
|
-
if candidates.empty?
|
10
|
-
alert_error "#{gem} is not installed. Skipping."
|
11
|
-
next
|
12
|
-
end
|
13
|
-
|
14
|
-
candidates << dependencies_for(*candidates) unless options[:ignore]
|
15
|
-
candidates
|
16
|
-
end.flatten.uniq
|
17
|
-
end
|
18
|
-
|
19
|
-
def gems_list
|
20
|
-
# @todo Gem.source_index is going away...
|
21
|
-
installed_gems = Gem.source_index.all_gems
|
22
|
-
if options[:all] then
|
23
|
-
installed_gems.map { |_, spec| spec.name }
|
24
|
-
else
|
25
|
-
get_all_gem_names
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def dependencies_for *specs
|
30
|
-
specs.map { |spec|
|
31
|
-
spec.runtime_dependencies.map { |dep|
|
32
|
-
deps = Gem.source_index.find_name(dep.name,dep.requirement)
|
33
|
-
deps + dependencies_for(*deps)
|
34
|
-
}
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|