gem-compile 0.0.3 → 0.0.4

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.
Files changed (4) hide show
  1. data/README.md +9 -5
  2. data/bin/gem-compile +30 -35
  3. data/lib/rubygems/compiler.rb +29 -31
  4. metadata +1 -1
data/README.md CHANGED
@@ -13,18 +13,19 @@ It creates pre-compiled binary gems from gems with extensions.
13
13
 
14
14
  $ gem build gem-compile.gemspec
15
15
  $ gem install gem-compile-*.gem
16
- or
16
+ or
17
17
  $ gem install gem-compile
18
18
 
19
19
 
20
20
  ## Usage
21
21
 
22
22
  $ gem compile [options] GEMFILE -- --build-flags
23
- or
23
+ or
24
24
  $ gem-compile [options] GEMFILE -- --build-flags
25
-
26
- options:
27
- -p, --platform PLATFORM Output platform name
25
+
26
+ options:
27
+ -p, --platform PLATFORM Output platform name
28
+ -f, --fat VERSION:RUBY,... Create fat binary (e.g. --fat 1.8:ruby,1.9:ruby19)
28
29
 
29
30
 
30
31
  ## Example
@@ -35,6 +36,9 @@ With above command line, **msgpack-0.3.4-x86-mingw32.gem** file will be created
35
36
  $ gem compile --platform mswin32 msgpack-0.3.4.gem
36
37
  With above command line, **msgpack-0.3.4-x86-mswin32.gem** file will be created.
37
38
 
39
+ $ gem compile --platform mswin32 --fat 1.8:/Ruby/bin/ruby,1.9:/Ruby19/bin/ruby msgpack-0.3.4.gem
40
+ With --fat option, it creates a fat-binary. It's installable on both ruby-1.8 and ruby-1.9.
41
+
38
42
 
39
43
  ## License
40
44
 
@@ -99,6 +99,9 @@ if fat
99
99
  end
100
100
  end
101
101
 
102
+ dest_path = File.join(gem_dir, spec.require_paths.first)
103
+ FileUtils.rm_rf(dest_path) if File.exists?(dest_path)
104
+
102
105
  format.file_entries.each do |entry, file_data|
103
106
  path = entry['path'].untaint
104
107
  path = File.expand_path File.join(gem_dir, path)
@@ -117,7 +120,6 @@ end
117
120
 
118
121
  ran_rake = false
119
122
  start_dir = Dir.pwd
120
- built_paths = []
121
123
 
122
124
  spec.extensions.each do |extension|
123
125
  break if ran_rake
@@ -137,51 +139,25 @@ spec.extensions.each do |extension|
137
139
  end
138
140
 
139
141
  begin
140
- dest_path = File.join(gem_dir, File.dirname(extension))
142
+ build_dir = File.join(gem_dir, File.dirname(extension))
141
143
  extension = File.expand_path(extension)
142
- Dir.chdir dest_path
144
+ Dir.chdir build_dir
143
145
 
144
146
  if fat_commands.empty?
145
147
  results = builder.build(extension, gem_dir, dest_path, results)
146
148
 
147
- built_paths.concat Dir.glob("#{dest_path}/**/*")
148
-
149
149
  else
150
- ext_files = []
151
-
152
150
  fat_commands.each_pair do |version, command|
153
- version_path = File.join(dest_path, version)
151
+ dest_version_path = File.join(dest_path, version)
154
152
 
155
- script = <<-EOF
156
- require 'rubygems/ext'
157
- puts #{builder}.build(#{extension.dump},#{gem_dir.dump},#{version_path.dump}, [])
158
- EOF
153
+ script = %'require "rubygems/ext"; puts #{builder}.build(#{extension.dump},#{gem_dir.dump},#{dest_version_path.dump}, [])'
159
154
 
160
- result = `#{command} -e #{Shellwords.escape script}`
155
+ result = `#{command} -e '#{script}'`
161
156
  results << result
162
- if $? != 0
163
- raise result
164
- end
165
-
166
- paths = Dir.glob("#{version_path}/**/*")
167
- files = paths.map {|path| path[File.join(version_path,'').length..-1] }
168
- ext_files.concat files
169
-
170
- built_paths.concat paths
171
- end
172
-
173
- ext_files.uniq.each do |ext_name|
174
- ext_basename = ext_name.sub(/\.[^\.]*$/, '')
175
- rb_path = File.join(dest_path, "#{ext_basename}.rb")
176
- File.open(rb_path, "w") do |f|
177
- f.write <<-EOF
178
- require File.join File.dirname(__FILE__), RUBY_VERSION.match(/\\d+\\.\\d+/)[0], #{ext_basename.dump}
179
- EOF
180
- end
157
+ raise result if $? != 0
181
158
 
182
- built_paths << rb_path
159
+ FileUtils.rm Dir.glob("**/*.o") # FIXME
183
160
  end
184
-
185
161
  end
186
162
 
187
163
  puts results.join("\n")
@@ -200,14 +176,33 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
200
176
  EOF
201
177
 
202
178
  puts message
179
+
203
180
  ensure
204
181
  Dir.chdir start_dir
205
182
  end
206
-
207
183
  end
208
184
 
209
185
  spec.extensions = []
210
186
 
187
+ unless fat_commands.empty?
188
+ fat_ext_files = fat_commands.keys.uniq.map do |version|
189
+ dest_version_path = File.join(dest_path, version)
190
+ fat_ext_paths = Dir.glob("#{dest_version_path}/**/*")
191
+ fat_ext_paths.map {|path| path[File.join(dest_version_path,'').length..-1] }
192
+ end.flatten.uniq
193
+
194
+ fat_ext_files.uniq.each do |ext_file|
195
+ ext_name = ext_file.sub(/\.[^\.]*$/, '')
196
+ rb_path = File.join(dest_path, "#{ext_name}.rb")
197
+ File.open(rb_path, "w") do |f|
198
+ f.write <<-EOF
199
+ require File.join File.dirname(__FILE__), RUBY_VERSION.match(/\\d+\\.\\d+/)[0], #{ext_name.dump}
200
+ EOF
201
+ end
202
+ end
203
+ end
204
+
205
+ built_paths = Dir.glob("#{dest_path}/**/*")
211
206
  built_files = built_paths.map {|path| path[File.join(gem_dir,'').length..-1] }
212
207
  built_files.reject! {|path| path =~ /\.o$/ } # FIXME
213
208
 
@@ -26,6 +26,9 @@ class Gem::Compiler
26
26
  raise Gem::Exception, "The package seems to be built already."
27
27
  end
28
28
 
29
+ dest_path = File.join(gem_dir, spec.require_paths.first)
30
+ FileUtils.rm_rf(dest_path) if File.exists?(dest_path)
31
+
29
32
  format.file_entries.each do |entry, file_data|
30
33
  path = entry['path'].untaint
31
34
  path = File.expand_path File.join(gem_dir, path)
@@ -44,7 +47,6 @@ class Gem::Compiler
44
47
 
45
48
  ran_rake = false
46
49
  start_dir = Dir.pwd
47
- built_paths = []
48
50
 
49
51
  spec.extensions.each do |extension|
50
52
  break if ran_rake
@@ -64,51 +66,27 @@ class Gem::Compiler
64
66
  end
65
67
 
66
68
  begin
67
- dest_path = File.join(gem_dir, File.dirname(extension))
68
- Dir.chdir dest_path
69
+ build_dir = File.join(gem_dir, File.dirname(extension))
70
+ extension = File.expand_path(extension)
71
+ Dir.chdir build_dir
69
72
 
70
73
  if fat_commands.empty?
71
74
  results = builder.build(extension, gem_dir, dest_path, results)
72
75
 
73
- built_paths.concat Dir.glob("#{dest_path}/**/*")
74
-
75
76
  else
76
77
  ext_files = []
77
78
 
78
79
  fat_commands.each_pair do |version, command|
79
- version_path = File.join(dest_path, version)
80
+ dest_version_path = File.join(dest_path, version)
80
81
 
81
- script = <<-EOF
82
- require "rubygems/ext"; puts #{builder}.build(#{extension.dump},#{gem_dir.dump},#{version_path.dump}, [])
83
- EOF
84
- script.strip!
82
+ script = %'require "rubygems/ext"; puts #{builder}.build(#{extension.dump},#{gem_dir.dump},#{dest_version_path.dump}, [])'
85
83
 
86
84
  result = `#{command} -e '#{script}'`
87
85
  results << result
88
- if $? != 0
89
- raise result
90
- end
91
-
92
- paths = Dir.glob("#{version_path}/**/*")
93
- files = paths.map {|path| path[File.join(version_path,'').length..-1] }
94
- ext_files.concat files
95
-
96
- built_paths.concat paths
86
+ raise result if $? != 0
97
87
 
98
88
  FileUtils.rm Dir.glob("**/*.o") # FIXME
99
89
  end
100
-
101
- ext_files.uniq.each do |ext_name|
102
- ext_basename = ext_name.sub(/\.[^\.]*$/, '')
103
- rb_path = File.join(dest_path, "#{ext_basename}.rb")
104
- File.open(rb_path, "w") do |f|
105
- f.write <<-EOF
106
- require File.join File.dirname(__FILE__), RUBY_VERSION.match(/\\d+\\.\\d+/)[0], #{ext_basename.dump}
107
- EOF
108
- end
109
- built_paths << rb_path
110
- end
111
-
112
90
  end
113
91
 
114
92
  say results.join("\n") if Gem.configuration.really_verbose
@@ -127,6 +105,7 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
127
105
  EOF
128
106
 
129
107
  raise Gem::Exception, message
108
+
130
109
  ensure
131
110
  Dir.chdir start_dir
132
111
  end
@@ -134,6 +113,25 @@ Results logged to #{File.join(Dir.pwd, 'gem_make.out')}
134
113
 
135
114
  spec.extensions = []
136
115
 
116
+ unless fat_commands.empty?
117
+ fat_ext_files = fat_commands.keys.uniq.map do |version|
118
+ dest_version_path = File.join(dest_path, version)
119
+ fat_ext_paths = Dir.glob("#{dest_version_path}/**/*")
120
+ fat_ext_paths.map {|path| path[File.join(dest_version_path,'').length..-1] }
121
+ end.flatten.uniq
122
+
123
+ fat_ext_files.uniq.each do |ext_file|
124
+ ext_name = ext_file.sub(/\.[^\.]*$/, '')
125
+ rb_path = File.join(dest_path, "#{ext_name}.rb")
126
+ File.open(rb_path, "w") do |f|
127
+ f.write <<-EOF
128
+ require File.join File.dirname(__FILE__), RUBY_VERSION.match(/\\d+\\.\\d+/)[0], #{ext_name.dump}
129
+ EOF
130
+ end
131
+ end
132
+ end
133
+
134
+ built_paths = Dir.glob("#{dest_path}/**/*")
137
135
  built_files = built_paths.map {|path| path[File.join(gem_dir,'').length..-1] }
138
136
  built_files.reject! {|path| path =~ /\.o$/ } # FIXME
139
137
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem-compile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - FURUHASHI Sadayuki