lib/hoe.rb in hoe-1.3.0 vs lib/hoe.rb in hoe-1.4.0
- old
+ new
@@ -94,12 +94,32 @@
#
# data.tar.gz
# data.tar.gz.sig
# metadata.gz
# metadata.gz.sig
+#
+# === Platform awareness
+#
+# Hoe allows bundling of pre-compiled extensions in the +package+ task.
+#
+# To create a package for your current platform:
+#
+# rake package INLINE=1
+#
+# This will force Hoe analize your +Inline+ already compiled
+# extensions and include them in your gem.
+#
+# If somehow you need to force a specific platform:
+#
+# rake package INLINE=1 FORCE_PLATFORM=mswin32
+#
+# This will set the +Gem::Specification+ platform to the one indicated in
+# +FORCE_PLATFORM+ (instead of default Gem::Platform::CURRENT)
+#
+
class Hoe
- VERSION = '1.3.0'
+ VERSION = '1.4.0'
ruby_prefix = Config::CONFIG['prefix']
sitelibdir = Config::CONFIG['sitelibdir']
##
@@ -131,12 +151,14 @@
sitelibdir
else
File.join(PREFIX, sitelibdir[ruby_prefix.size..-1])
end
- WINDOZE = /win32/ =~ RUBY_PLATFORM unless defined? WINDOZE
+ DLEXT = Config::CONFIG['DLEXT']
+ WINDOZE = /djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WINDOZE
+
DIFF = if WINDOZE
'diff.exe'
else
if system("gdiff", __FILE__, __FILE__)
'gdiff' # solaris and kin suck
@@ -385,9 +407,41 @@
end
if signing_key and cert_chain then
s.signing_key = signing_key
s.cert_chain = cert_chain
+ end
+
+ ############################################################
+ # Allow automatic inclusion of compiled extensions
+ if ENV['INLINE'] then
+ s.platform = ENV['FORCE_PLATFORM'] || Gem::Platform::CURRENT
+ # name of the extension is CamelCase
+ if name =~ /[A-Z]/
+ # ClassName => class_name
+ alternate_name = name.reverse.scan(%r/[A-Z]+|[^A-Z]*[A-Z]+?/).reverse.map { |word| word.reverse.downcase }.join('_')
+ elsif name =~ /_/
+ # class_name = ClassName
+ alternate_name = name.strip.split(/\s*_+\s*/).map! { |w| w.downcase.sub(/^./) { |c| c.upcase } }.join
+ end
+
+ # Try collecting Inline extensions for +name+
+ if defined?(Inline) then
+ directory 'lib/inline'
+
+ extensions = Dir.chdir(Inline::directory) {
+ Dir["Inline_{#{name},#{alternate_name}}_*.#{DLEXT}"]
+ }
+ extensions.each do |ext|
+ # add the inlined extension to the spec files
+ s.files += ["lib/inline/#{ext}"]
+
+ # include the file in the tasks
+ file "lib/inline/#{ext}" => ["lib/inline"] do
+ cp File.join(Inline::directory, ext), "lib/inline"
+ end
+ end
+ end
end
# Do any extra stuff the user wants
spec_extras.each do |msg, val|
case val