gem-compile 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1 @@
1
+ FURUHASHI Sadayuki <frsyuki _at_ users.sourceforge.jp>
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ gem-compile
2
+ ===========
3
+ Create binary gems from gems with extensions.
4
+
5
+
6
+ ## Overview
7
+
8
+ gem-compile is a RubyGem command plugin that adds 'complie' command.
9
+ It creates binary gems from gems with extensions.
10
+
11
+
12
+ ## Installation
13
+
14
+ $ gem build gem-compile.gemspec
15
+ $ gem install gem-compile-*.gem
16
+ or
17
+ $ gem install gem-compile
18
+
19
+
20
+ ## Usage
21
+
22
+ $ gem compile [options] GEMFILE -- --build-flags
23
+ or
24
+ $ gem-compile [options] GEMFILE -- --build-flags
25
+
26
+ options:
27
+ -p, --platform PLATFORM Output platform name
28
+
29
+
30
+ ## Example
31
+
32
+ $ gem compile msgpack-0.3.4.gem
33
+ With above command line, msgpack-0.3.4-x86-mingw32.gem file will be created on MinGW environment.
34
+
35
+ $ gem compile --platform mswin32 msgpack-0.3.4.gem
36
+ With above command line, msgpack-0.3.4-x86-mswin32.gem file will be created.
37
+
38
+
39
+ ## License
40
+
41
+ Copyright (c) 2010 FURUHASHI Sadayuki
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining a copy
44
+ of this software and associated documentation files (the "Software"), to deal
45
+ in the Software without restriction, including without limitation the rights
46
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
47
+ copies of the Software, and to permit persons to whom the Software is
48
+ furnished to do so, subject to the following conditions:
49
+
50
+ The above copyright notice and this permission notice shall be included in
51
+ all copies or substantial portions of the Software.
52
+
53
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
55
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
56
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
58
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
59
+ THE SOFTWARE.
60
+
data/bin/gem-compile ADDED
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # gem-compile
4
+ #
5
+ # Copyright (c) 2010 FURUHASHI Sadayuki
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in
15
+ # all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ # THE SOFTWARE.
24
+ #
25
+ require 'optparse'
26
+ require 'fileutils'
27
+
28
+ args = ARGV.dup
29
+
30
+ if ARGV.include?('--')
31
+ build_args = args[args.index("--") + 1...args.length]
32
+ args = args[0...args.index("--")]
33
+ end
34
+
35
+ config = {
36
+ :platform => nil
37
+ }
38
+
39
+ op = OptionParser.new
40
+ op.on('-p', '--platform PLATFORM',
41
+ 'Output platform name') {|s| config[:platform] = s }
42
+
43
+ op.banner += " GEMFILE -- --build-flags"
44
+
45
+ op.parse!(args)
46
+
47
+ if args.length != 1
48
+ puts op.to_s
49
+ exit 0
50
+ end
51
+
52
+
53
+ require 'rubygems/format'
54
+ require 'rubygems/ext'
55
+ require 'rubygems/builder'
56
+
57
+ Gem::Command.build_args = build_args if build_args
58
+
59
+ gem = args.first
60
+ platform = config[:platform] || Gem::Platform::RUBY
61
+
62
+
63
+ gem_dir = "#{File.basename(gem)}.build"
64
+ gem_dir = File.expand_path(gem_dir)
65
+
66
+ begin
67
+ format = Gem::Format.from_file_by_path(gem)
68
+ rescue => ex
69
+ puts ex
70
+ exit 1
71
+ end
72
+
73
+ spec = format.spec
74
+
75
+ if spec.extensions.empty?
76
+ puts "There are no extensions to build."
77
+ exit 1
78
+ end
79
+
80
+ if spec.platform != Gem::Platform::RUBY
81
+ puts "The package seems to be built already."
82
+ exit 1
83
+ end
84
+
85
+
86
+ format.file_entries.each do |entry, file_data|
87
+ path = entry['path'].untaint
88
+ path = File.expand_path File.join(gem_dir, path)
89
+
90
+ FileUtils.rm_rf(path) if File.exists?(path)
91
+ FileUtils.mkdir_p File.dirname(path)
92
+
93
+ File.open(path, "wb") do |out|
94
+ out.write file_data
95
+ end
96
+
97
+ FileUtils.chmod entry['mode'], path
98
+
99
+ puts path
100
+ end
101
+
102
+ ran_rake = false
103
+ start_dir = Dir.pwd
104
+ dest_path = File.join gem_dir, spec.require_paths.first
105
+
106
+ spec.extensions.each do |extension|
107
+ break if ran_rake
108
+ results = []
109
+
110
+ builder = case extension
111
+ when /extconf/ then
112
+ Gem::Ext::ExtConfBuilder
113
+ when /configure/ then
114
+ Gem::Ext::ConfigureBuilder
115
+ when /rakefile/i, /mkrf_conf/i then
116
+ ran_rake = true
117
+ Gem::Ext::RakeBuilder
118
+ else
119
+ results = ["No builder for extension '#{extension}'"]
120
+ nil
121
+ end
122
+
123
+ begin
124
+ Dir.chdir File.join(gem_dir, File.dirname(extension))
125
+ results = builder.build(extension, gem_dir, dest_path, results)
126
+
127
+ puts results.join("\n")
128
+
129
+ rescue => ex
130
+ results = results.join "\n"
131
+
132
+ File.open('gem_make.out', 'wb') { |f| f.puts results }
133
+
134
+ mesage = <<-EOF
135
+ ERROR: Failed to build gem native extension."
136
+
137
+ #{results}
138
+
139
+ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
140
+ EOF
141
+
142
+ puts message
143
+ ensure
144
+ Dir.chdir start_dir
145
+ end
146
+
147
+ end
148
+
149
+ spec.extensions = []
150
+
151
+ built_files = Dir.glob("#{dest_path}/**/*")
152
+ basedir = File.join gem_dir, ""
153
+ built_files.each {|path| path.slice!(0, basedir.length) }
154
+
155
+ spec.files = (spec.files + built_files).sort.uniq
156
+ spec.platform = platform if platform
157
+
158
+ Dir.chdir gem_dir
159
+ out_fname = Gem::Builder.new(spec).build
160
+
161
+ FileUtils.mv(out_fname, start_dir)
162
+
@@ -0,0 +1,33 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/compiler'
3
+
4
+ class Gem::Commands::CompileCommand < Gem::Command
5
+ def initialize
6
+ super 'compile', 'Create binary gems from gems with extensions',
7
+ :platform => Gem::Platform::CURRENT
8
+
9
+ add_option('-p', '--platform PLATFORM', 'Output platform name') do |value, options|
10
+ options[:platform] = value
11
+ end
12
+ end
13
+
14
+ def arguments # :nodoc:
15
+ "GEMFILE name of gem to compile"
16
+ end
17
+
18
+ def usage # :nodoc:
19
+ "#{program_name} GEMFILE"
20
+ end
21
+
22
+ def execute
23
+ gem = options[:args].shift
24
+
25
+ unless gem then
26
+ raise Gem::CommandLineError,
27
+ "Please specify a gem name or file on the command line"
28
+ end
29
+
30
+ Gem::Compiler.compile(gem, options[:platform])
31
+ end
32
+ end
33
+
@@ -0,0 +1,108 @@
1
+ require 'rubygems/format'
2
+ require 'rubygems/ext'
3
+ require 'rubygems/builder'
4
+ require 'rubygems/exceptions'
5
+ require 'rubygems/user_interaction'
6
+ require 'fileutils'
7
+
8
+ class Gem::Compiler
9
+
10
+ extend Gem::UserInteraction
11
+
12
+ def self.compile(gem, platform = Gem::Platform::CURRENT)
13
+ gem_dir = "#{File.basename(gem)}.build"
14
+ gem_dir = File.expand_path(gem_dir)
15
+
16
+ format = Gem::Format.from_file_by_path(gem)
17
+
18
+ spec = format.spec
19
+
20
+ if spec.extensions.empty?
21
+ raise Gem::Exception, "There are no extensions to build."
22
+ end
23
+
24
+ if spec.platform != Gem::Platform::RUBY
25
+ raise Gem::Exception, "The package seems to be built already."
26
+ end
27
+
28
+ format.file_entries.each do |entry, file_data|
29
+ path = entry['path'].untaint
30
+ path = File.expand_path File.join(gem_dir, path)
31
+
32
+ FileUtils.rm_rf(path) if File.exists?(path)
33
+ FileUtils.mkdir_p File.dirname(path)
34
+
35
+ File.open(path, "wb") do |out|
36
+ out.write file_data
37
+ end
38
+
39
+ FileUtils.chmod entry['mode'], path
40
+
41
+ say path if Gem.configuration.really_verbose
42
+ end
43
+
44
+ ran_rake = false
45
+ start_dir = Dir.pwd
46
+ dest_path = File.join gem_dir, spec.require_paths.first
47
+
48
+ spec.extensions.each do |extension|
49
+ break if ran_rake
50
+ results = []
51
+
52
+ builder = case extension
53
+ when /extconf/ then
54
+ Gem::Ext::ExtConfBuilder
55
+ when /configure/ then
56
+ Gem::Ext::ConfigureBuilder
57
+ when /rakefile/i, /mkrf_conf/i then
58
+ ran_rake = true
59
+ Gem::Ext::RakeBuilder
60
+ else
61
+ results = ["No builder for extension '#{extension}'"]
62
+ nil
63
+ end
64
+
65
+ begin
66
+ Dir.chdir File.join(gem_dir, File.dirname(extension))
67
+ results = builder.build(extension, gem_dir, dest_path, results)
68
+
69
+ say results.join("\n") if Gem.configuration.really_verbose
70
+
71
+ rescue => ex
72
+ results = results.join "\n"
73
+
74
+ File.open('gem_make.out', 'wb') { |f| f.puts results }
75
+
76
+ mesage = <<-EOF
77
+ ERROR: Failed to build gem native extension."
78
+
79
+ #{results}
80
+
81
+ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
82
+ EOF
83
+
84
+ raise ExtensionBuildError, message
85
+ ensure
86
+ Dir.chdir start_dir
87
+ end
88
+ end
89
+
90
+ spec.extensions = []
91
+
92
+ built_files = Dir.glob("#{dest_path}/**/*")
93
+ basedir = File.join gem_dir, ""
94
+ built_files.each {|path| path.slice!(0, basedir.length) }
95
+
96
+ spec.files = (spec.files + built_files).sort.uniq
97
+ spec.platform = platform if platform
98
+
99
+ Dir.chdir gem_dir
100
+ begin
101
+ out_fname = Gem::Builder.new(spec).build
102
+ FileUtils.mv(out_fname, start_dir)
103
+ ensure
104
+ Dir.chdir start_dir
105
+ end
106
+ end
107
+ end
108
+
@@ -0,0 +1,4 @@
1
+ require 'rubygems/commands/compile_command'
2
+ require 'rubygems/command_manager'
3
+ Gem::CommandManager.instance.register_command :compile
4
+
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem-compile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - FURUHASHI Sadayuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-31 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: frsyuki@users.sourceforge.jp
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.md
24
+ - AUTHORS
25
+ files:
26
+ - lib/rubygems/commands/compile_command.rb
27
+ - lib/rubygems/compiler.rb
28
+ - lib/rubygems_plugin.rb
29
+ - bin/gem-compile
30
+ - README.md
31
+ - AUTHORS
32
+ has_rdoc: true
33
+ homepage: http://github.com/frsyuki/gem-compile
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.3.5
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: gem-compile, create binary gems from gems with extensions
60
+ test_files: []
61
+