rubygems-compile 1.0.0-universal-macruby

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Mark Rada
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,58 @@
1
+ = rubygems-compile
2
+
3
+ A set of rubygems commands for <tt>macgem</tt> that interface with the
4
+ MacRuby compiler. This gem requires MacRuby 0.11 or newer.
5
+
6
+ All you need to do is:
7
+
8
+ sudo macgem install rubygems-compile --pre
9
+
10
+ And then you're off to the races!
11
+
12
+ == Commands
13
+
14
+ [+compile+] Can be used to compile, or re-compile, any gems that are already installed.
15
+
16
+ sudo macgem compile nokogiri # Compile gems based on names you provide
17
+ sudo macgem compile minitest --version 2.0.2 # Compile a specific version of a gem
18
+ sudo macgem compile --all # Compile all installed gems
19
+ sudo macgem compile rspec --no-ignore-dependencies # Also compile dependencies
20
+
21
+ [+uncompile+] Can be used to remove the compiled <tt>.rbo</tt> files if a gem does not work well when compiled.
22
+
23
+ sudo macgem uncompile nokogiri # Uncompile gems based on names you provide
24
+ sudo macgem uncompile minitest --version 2.0.2 # Compile a specific version of a gem
25
+ sudo macgem uncompile --all # Uncompile all installed gems
26
+ sudo macgem uncompile rspec --no-ignore-dependencies # Also uncompile dependencies
27
+
28
+ [+auto_compile+] Can be used to enable a post-install hook that will automatically compile gems when you install them. Call it once to turn on, call it a second time to disable it.
29
+
30
+ sudo macgem auto_compile # gems will compiled when you install them
31
+ sudo macgem auto_compile # gems will not be compiled when you install them
32
+
33
+ == Caveats
34
+
35
+ * Large gems will take a long time to compile, but these are the gems
36
+ that will benefit the most from being compiled so please be patient
37
+ * This has only been tested on a few gems, but should not break
38
+ existing gems since we leave the original files around
39
+ * At the moment, compiled gems will not provide usable backtraces
40
+ * <tt>.rbo</tt> files take up more disk space than their <tt>.rb</tt> equivalents
41
+
42
+ == Known Issues
43
+
44
+ * Source files using a non-standard suffix (e.g. <tt>mime-types</tt> has a <tt>.rb.data</tt> file) will not get compiled
45
+ * This might be addressable in a later release, but is not a big deal
46
+ * Gems that explicitly require a file with the file suffix (e.g. <tt>require 'nokogiri.rb'</tt>) will never load the compiled version of the file
47
+ * Those gems should be updated so that compiled code can be loaded
48
+
49
+ == TODO
50
+
51
+ * Code parsing to WARN about gems that will have issues when compiled
52
+ * Parallel compilation to speed up compilation of large gems
53
+ * This might require changes in the MacRuby compiler
54
+
55
+ == Copyright
56
+
57
+ Copyright (c) 2011 Mark Rada. See LICENSE.txt for further details.
58
+
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require 'rake/testtask'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/dependency_installer'
4
+
5
+ task :default => :gem
6
+
7
+ Rake::TestTask.new(:test) do |test|
8
+ test.libs << 'lib' << 'test'
9
+ test.pattern = 'test/**/test_*.rb'
10
+ test.verbose = true
11
+ test.ruby_opts = ['-rhelper']
12
+ end
13
+
14
+ eval IO.read('rubygems-compile.gemspec')
15
+
16
+ Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
17
+ pkg.need_zip = false
18
+ pkg.need_tar = true
19
+ end
20
+
21
+ desc 'Build the gem and install it'
22
+ task :install => :gem do
23
+ Gem::Installer.new("pkg/#{GEM_SPEC.file_name}").install
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'ripper'
2
+
3
+ class GemAnalyzer < Ripper::SexpBuilder
4
+
5
+ def on_command command, args
6
+ puts args.class
7
+ puts command.class
8
+ super.tap { |x| puts x.inspect }
9
+ end
10
+
11
+ end
@@ -0,0 +1,27 @@
1
+ class Gem::Commands::AutoCompileCommand < Gem::Command
2
+ include Gem::UserInteraction
3
+
4
+ def initialize
5
+ super 'auto_compile', 'Enable gem compilation at install time'
6
+ end
7
+
8
+ def description # :nodoc:
9
+ 'Toggle a setting that enables compiling gems at install time.'
10
+ end
11
+
12
+ def usage
13
+ "#{progname}"
14
+ end
15
+
16
+ def execute
17
+ Gem.configuration[:compile] = if Gem.configuration[:compile]
18
+ say 'Disabling automatic compilation'
19
+ false
20
+ else
21
+ say 'Enabling automatic compilation'
22
+ true
23
+ end
24
+ Gem.configuration.write
25
+ end
26
+
27
+ end
@@ -0,0 +1,51 @@
1
+ require 'rubygems/dependency_list'
2
+
3
+ ##
4
+ # Use the MacRuby compiler to compile installed gems.
5
+
6
+ class Gem::Commands::CompileCommand < Gem::Command
7
+ include Gem::VersionOption
8
+ include Gem::CompileMethods
9
+
10
+ def initialize
11
+ super 'compile', 'Compile (or recompile) installed gems',
12
+ ignore: true, all: false
13
+
14
+ add_version_option
15
+ add_option(
16
+ '-a', '--all', 'Compile all installed gem'
17
+ ) do |all,opts| opts[:all] = all end
18
+ add_option(
19
+ '-I', '--[no-]ignore-dependencies', 'Also compile dependencies'
20
+ ) do |value, options| options[:ignore] = value end
21
+ end
22
+
23
+ def arguments # :nodoc:
24
+ 'GEMNAME name of the gem to compile'
25
+ end
26
+
27
+ def defaults_str # :nodoc:
28
+ super + '--ignore-dependencies'
29
+ end
30
+
31
+ def usage # :nodoc:
32
+ "#{program_name} GEMNAME [GEMNAME ...]"
33
+ end
34
+
35
+ ##
36
+ # Determine which gems need to be compiled, then create and run a compiler
37
+ # object for each of them.
38
+
39
+ def execute
40
+ gems = execution_list
41
+ gems.delete_if { |spec| spec.name == 'rubygems-compile' }
42
+
43
+ if gems.count >= 10
44
+ alert 'This could take a while; you might want to take a coffee break'
45
+ end
46
+
47
+ compiler = Gem::Compiler.new
48
+ gems.each { |gem| compiler.compile(gem) }
49
+ end
50
+
51
+ end
@@ -0,0 +1,39 @@
1
+ class Gem::Commands::UncompileCommand < Gem::Command
2
+ include Gem::VersionOption
3
+ include Gem::CompileMethods
4
+
5
+ def initialize
6
+ super 'uncompile', 'Uncompile installed gems',
7
+ ignore: true, all: false
8
+
9
+ add_version_option
10
+ add_option(
11
+ '-a', '--all', 'Uncompile all installed gem'
12
+ ) do |all,opts| opts[:all] = all end
13
+ add_option(
14
+ '-I', '--[no-]ignore-dependencies', 'Also uncompile dependencies'
15
+ ) do |value, options| options[:ignore] = value end
16
+ end
17
+
18
+ def arguments # :nodoc:
19
+ 'GEMNAME name of the gem to uncompile'
20
+ end
21
+
22
+ def defaults_str # :nodoc:
23
+ super + '--ignore-dependencies'
24
+ end
25
+
26
+ def usage # :nodoc:
27
+ "#{program_name} GEMNAME [GEMNAME ...]"
28
+ end
29
+
30
+ ##
31
+ # Determine which gems need to be uncompiled, then create and run
32
+ # an uncompiler object for each of them.
33
+
34
+ def execute
35
+ uncompiler = Gem::Uncompiler.new
36
+ execution_list.each { |gem| uncompiler.uncompile(gem) }
37
+ end
38
+
39
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems-compile/commands/compile_command'
2
+ Gem::CommandManager.instance.register_command :compile
3
+
4
+ require 'rubygems-compile/commands/uncompile_command'
5
+ Gem::CommandManager.instance.register_command :uncompile
6
+
7
+ require 'rubygems-compile/commands/autocompile_command'
8
+ Gem::CommandManager.instance.register_command :auto_compile
@@ -0,0 +1,39 @@
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
+ installed_gems = Gem.source_index.all_gems
21
+ if options[:all] then
22
+ installed_gems.map { |_, spec| spec.name }
23
+ else
24
+ get_all_gem_names
25
+ end
26
+ end
27
+
28
+ def dependencies_for *specs
29
+ specs.map { |spec|
30
+ spec.runtime_dependencies.map { |dep|
31
+ deps = Gem.source_index.find_name(dep.name,dep.requirement)
32
+ deps + dependencies_for(*deps)
33
+ }
34
+ }
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,70 @@
1
+ class Gem::Compiler
2
+ include Gem::UserInteraction
3
+
4
+ def initialize
5
+ @current_directory = []
6
+ @config = Gem.configuration
7
+ end
8
+
9
+ def call gem
10
+ @spec = gem.is_a?(Gem::Specification) ? gem : gem.spec
11
+
12
+ if @spec.name == 'rubygems-compile'
13
+ alert_info 'You cannot compile rubygems-compile' if @config.really_verbose
14
+ return
15
+ end
16
+
17
+ say compilation_message if @config.verbose
18
+
19
+ gem_files.each do |file|
20
+ say compile_file_msg(file) if @config.really_verbose
21
+ absolute_file_path = File.join(@spec.full_gem_path, file)
22
+ MacRuby::Compiler.new(
23
+ bundle: true,
24
+ output: "#{absolute_file_path}o",
25
+ files: [absolute_file_path]
26
+ ).run
27
+ end
28
+ end
29
+
30
+ alias_method :compile, :call
31
+
32
+ def compilation_message
33
+ slash = @config.really_verbose ? '/' : ''
34
+ "Compiling #{@spec.full_name}#{slash}"
35
+ end
36
+
37
+ ##
38
+ # --
39
+ # TODO Get better at deciding which files to compile; right now we
40
+ # ignore the .rb.data file in the mime-types gem and probably
41
+ # some other silly edge cases that are similar.
42
+ # ++
43
+ #
44
+ # We want to find all the files in a gem to compile, but avoid compiling
45
+ # test files and other misc. files which are usually found in the top
46
+ # level or test directory.
47
+ #
48
+
49
+ def gem_files
50
+ files = @spec.files - @spec.test_files - @spec.extra_rdoc_files
51
+ files.reject { |file| file.match /^(?:test|spec)/ }
52
+ .select { |file| file.match /\.rb$/ }
53
+ end
54
+
55
+ def compile_file_msg file
56
+ name = File.basename(file)
57
+ dirs = file.chomp(name).split(File::SEPARATOR)
58
+ tabs = "\t" * dirs.count
59
+
60
+ dirs.each_with_index do |dir, index|
61
+ unless @current_directory[index] == dir
62
+ @current_directory[index] = dir
63
+ say( "\t" * (index + 1) + dir + File::SEPARATOR)
64
+ end
65
+ end
66
+
67
+ "#{tabs}#{name} => #{name}o"
68
+ end
69
+
70
+ end
@@ -0,0 +1,9 @@
1
+ ##
2
+ # The setting that we look for here is toggled using the +autocompile+
3
+ # command.
4
+
5
+ if Gem.configuration[:compile]
6
+ module Gem
7
+ @post_install_hooks << ::Gem::Compiler.new
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ class Gem::Uncompiler
2
+ include Gem::UserInteraction
3
+
4
+ def initialize
5
+ @config = Gem.configuration
6
+ end
7
+
8
+ def uncompile gem
9
+ @spec = gem.is_a?(Gem::Specification) ? gem : gem.spec
10
+
11
+ say uncompilation_message if @config.verbose
12
+
13
+ gem_files.each do |file|
14
+ say "\tAsploded #{file}" if @config.really_verbose
15
+ absolute_file_path = File.join(@spec.full_gem_path, file)
16
+ FileUtils.rm absolute_file_path
17
+ end
18
+ end
19
+
20
+ def uncompilation_message
21
+ slash = @config.really_verbose ? '/' : ''
22
+ "Uncompiling #{@spec.full_name}#{slash}"
23
+ end
24
+
25
+ def gem_files
26
+ Dir.glob(File.join(@spec.full_gem_path, '**','*.rbo')).map do |file|
27
+ file.sub /#{@spec.full_gem_path}\//, ''
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,23 @@
1
+ if RUBY_VERSION.to_f < 0.11
2
+
3
+ ui = Gem::UserInteraction.new
4
+ ui.alert_warning 'rubygems-compile requires MacRuby 0.11 or newer'
5
+ ui.alert_warning 'rubygems-compile will not be loaded'
6
+
7
+ else
8
+
9
+ require 'rbconfig'
10
+ require 'fileutils'
11
+ require 'rubygems/version_option'
12
+
13
+ unless MacRuby.const_defined?(:Compiler)
14
+ load File.join(RbConfig::CONFIG['bindir'], 'macrubyc')
15
+ end
16
+
17
+ require 'rubygems-compile/common_methods'
18
+ require 'rubygems-compile/compiler'
19
+ require 'rubygems-compile/uncompiler'
20
+ require 'rubygems-compile/commands'
21
+ require 'rubygems-compile/post_install_hook'
22
+
23
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'rubygems/command_manager'
3
+ require 'rubygems_plugin'
4
+
5
+ gem 'minitest-macruby-pride', '>= 2.2.0'
6
+ require 'minitest/autorun'
7
+ require 'minitest/pride'
@@ -0,0 +1,22 @@
1
+ class TestAutoCompile < MiniTest::Unit::TestCase
2
+
3
+ def setup
4
+ @command = Gem::Commands::AutoCompileCommand.new
5
+ end
6
+
7
+ def test_turn_on
8
+ end
9
+
10
+ def test_turn_on_when_already_on
11
+ end
12
+
13
+ def test_turn_off
14
+ end
15
+
16
+ def test_turn_off_when_already_off
17
+ end
18
+
19
+ def test_calls_compile_on_each_gem_after_installation
20
+ end
21
+
22
+ end
@@ -0,0 +1,36 @@
1
+ class TestCompileCommand < MiniTest::Unit::TestCase
2
+ def setup
3
+ @command = Gem::Commands::CompileCommand.new
4
+ end
5
+ end
6
+
7
+ class Test < TestCompileCommand
8
+ def test_finds_all_files
9
+ # gets into all require dirs
10
+ # does not compile test files
11
+ end
12
+ def test_recompiles_rbos_if_they_already_exist
13
+ # to support use on nightly builds
14
+ end
15
+ end
16
+
17
+ class TestCompileInterface < TestCompileCommand
18
+ def test_has_an_option_to_compile_all_installed_gems
19
+ # by extension, this is also needed to support nightly build users
20
+ end
21
+ end
22
+
23
+ class TestCompileSpecialCases < TestCompileCommand
24
+ def test_refuses_to_compile_itself
25
+ # obvious
26
+ end
27
+
28
+ def test_loads_rubyc_without_warning
29
+ # this might not be doable without upstream load guarding; minor issue
30
+ end
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
+ end
@@ -0,0 +1,16 @@
1
+ class TestUncompileCommand < MiniTest::Unit::TestCase
2
+
3
+ def setup
4
+ @command = Gem::Commands::UncompileCommand.new
5
+ end
6
+
7
+ def test_removes_rbo_files
8
+ end
9
+
10
+ def test_leaves_rb_files
11
+ end
12
+
13
+ def test_can_uncompile_multiple_gems_at_once
14
+ end
15
+
16
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems-compile
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: universal-macruby
7
+ authors:
8
+ - Mark Rada
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-06-02 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: minitest-macruby-pride
17
+ prerelease: false
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 2.2.0
24
+ type: :development
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 2.2.0
31
+ description: 'A set of rubygems commands that interface with the MacRuby compiler.
32
+
33
+ '
34
+ email: mrada@marketcircle.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files:
38
+ - LICENSE.txt
39
+ - README.rdoc
40
+ files:
41
+ - lib/rubygems-compile/analysis.rb
42
+ - lib/rubygems-compile/commands/autocompile_command.rb
43
+ - lib/rubygems-compile/commands/compile_command.rb
44
+ - lib/rubygems-compile/commands/uncompile_command.rb
45
+ - lib/rubygems-compile/commands.rb
46
+ - lib/rubygems-compile/common_methods.rb
47
+ - lib/rubygems-compile/compiler.rb
48
+ - lib/rubygems-compile/post_install_hook.rb
49
+ - lib/rubygems-compile/uncompiler.rb
50
+ - lib/rubygems_plugin.rb
51
+ - test/helper.rb
52
+ - test/test_autocompile_command.rb
53
+ - test/test_compile_command.rb
54
+ - test/test_uncompile_command.rb
55
+ - Rakefile
56
+ - .gemtest
57
+ - LICENSE.txt
58
+ - README.rdoc
59
+ has_rdoc: true
60
+ homepage: http://github.com/ferrous26/rubygems-compile
61
+ licenses:
62
+ - MIT
63
+ post_install_message: "\n***********************************************************\n\nPlease
64
+ uninstall previous versions of this gem, or else\nrubygems will try to load each
65
+ version of the gem.\n\nThis version of rubygems-compile requires MacRuby 0.11 or\nnewer;
66
+ the functionality has changed significantly since\npre-1.0 releases, see the README:\n\n
67
+ \ https://github.com/ferrous26/rubygems-compile\n\n***********************************************************\n\n"
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.4.2
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: A set of rubygems commands that interface with the MacRuby compiler
89
+ test_files:
90
+ - test/helper.rb
91
+ - test/test_autocompile_command.rb
92
+ - test/test_compile_command.rb
93
+ - test/test_uncompile_command.rb
94
+ - Rakefile
95
+ - .gemtest