gembuilder 1.1.0
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.
- data/History.txt +8 -0
- data/Manifest.txt +7 -0
- data/README.txt +51 -0
- data/Rakefile +18 -0
- data/bin/gembuilder +50 -0
- data/lib/gembuilder.rb +91 -0
- data/test/test_gembuilder.rb +111 -0
- metadata +60 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
gembuilder
|
2
|
+
by Patrick Hurley
|
3
|
+
http://rubyforge.org/projects/gembuilder/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Build a binary gem from an existing gem for your platform.
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* Would be better if it could gather the gem automatically out of the gem cache.
|
12
|
+
* Should also have an option to attempt to cleanup intermediate files (.o/.obj)
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
Build your gem so that it can be deployed on machines without a build chain
|
17
|
+
|
18
|
+
== REQUIREMENTS:
|
19
|
+
|
20
|
+
* GEM and a binary build chain
|
21
|
+
|
22
|
+
== INSTALL:
|
23
|
+
|
24
|
+
* Install with gem, then just:
|
25
|
+
|
26
|
+
gembuilder <gem_file>
|
27
|
+
|
28
|
+
== LICENSE:
|
29
|
+
|
30
|
+
(The MIT License)
|
31
|
+
|
32
|
+
Copyright (c) 2007 Patrick Hurley
|
33
|
+
|
34
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
35
|
+
a copy of this software and associated documentation files (the
|
36
|
+
'Software'), to deal in the Software without restriction, including
|
37
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
38
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
39
|
+
permit persons to whom the Software is furnished to do so, subject to
|
40
|
+
the following conditions:
|
41
|
+
|
42
|
+
The above copyright notice and this permission notice shall be
|
43
|
+
included in all copies or substantial portions of the Software.
|
44
|
+
|
45
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
46
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
47
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
48
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
49
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
50
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
51
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/gembuilder.rb'
|
6
|
+
|
7
|
+
Hoe.new('gembuilder', GemBuilder::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'gembuilder'
|
9
|
+
p.author = 'Patrick Hurley'
|
10
|
+
p.email = 'phurley@gmail.com'
|
11
|
+
|
12
|
+
p.summary = 'Create a binary gem, for the current platform.'
|
13
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
14
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
15
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
# vim: syntax=Ruby
|
data/bin/gembuilder
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'gembuilder'
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
opts = OptionParser.new
|
8
|
+
|
9
|
+
conservative = false
|
10
|
+
|
11
|
+
opts.banner = "Usage: gembuilder [options] gem_file_name"
|
12
|
+
opts.on("-d", "--debug", "Enable debug output") { $DEBUG = 1 }
|
13
|
+
opts.on("-c", "--conservative", "Do not try and remove intermediate files") { conservative = true }
|
14
|
+
|
15
|
+
opts.on("-h", "--help", "Show this message") do
|
16
|
+
puts opts
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
argv = opts.parse(ARGV)
|
21
|
+
|
22
|
+
if argv.empty?
|
23
|
+
puts "You must provide the name of a gem on the command line."
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
argv.each do |gem|
|
28
|
+
unless File.exists?(gem)
|
29
|
+
puts "Skipping #{gem}, file not found."
|
30
|
+
next
|
31
|
+
end
|
32
|
+
|
33
|
+
gem_builder = GemBuilder.new(gem)
|
34
|
+
|
35
|
+
puts "Unpacking #{gem}"
|
36
|
+
gem_builder.unpack_gem
|
37
|
+
|
38
|
+
puts " building extension(s)"
|
39
|
+
gem_builder.build_extensions
|
40
|
+
|
41
|
+
puts " adjusting gemspec"
|
42
|
+
gem_builder.fix_gemspec(conservative)
|
43
|
+
|
44
|
+
puts " building binary gem"
|
45
|
+
gem_builder.build_gem
|
46
|
+
|
47
|
+
puts " cleaning up"
|
48
|
+
gem_builder.cleanup
|
49
|
+
end
|
50
|
+
|
data/lib/gembuilder.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "rbconfig"
|
4
|
+
require "rubygems"
|
5
|
+
require "tmpdir"
|
6
|
+
require "find"
|
7
|
+
require "fileutils"
|
8
|
+
Gem.manage_gems
|
9
|
+
|
10
|
+
|
11
|
+
class GemBuilder
|
12
|
+
VERSION = '1.1.0'
|
13
|
+
OBJEXT = ".#{Config::CONFIG["OBJEXT"]}"
|
14
|
+
|
15
|
+
# Helper that will do it all
|
16
|
+
def self.[](gem,conservative=false)
|
17
|
+
gem_builder = GemBuilder.new(gem)
|
18
|
+
gem_builder.unpack_gem
|
19
|
+
gem_builder.build_extensions
|
20
|
+
gem_builder.fix_gemspec(conservative)
|
21
|
+
gem_builder.build_gem
|
22
|
+
gem_builder.cleanup
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(gem)
|
26
|
+
@gem_name = gem
|
27
|
+
@installer = Gem::Installer.new(@gem_name)
|
28
|
+
@format = Gem::Format.from_file_by_path(@gem_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def tmpdir
|
32
|
+
@tmpdir ||= File.join(Dir.tmpdir, "gembuilder")
|
33
|
+
end
|
34
|
+
|
35
|
+
def installer
|
36
|
+
@installer ||= Gem::Installer.new(@gem_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def format
|
40
|
+
@format ||= Gem::Format.from_file_by_path(@gem_name)
|
41
|
+
end
|
42
|
+
|
43
|
+
def spec
|
44
|
+
@spec ||= format.spec
|
45
|
+
end
|
46
|
+
|
47
|
+
def unpack_gem
|
48
|
+
FileUtils.rm_r(tmpdir) rescue nil
|
49
|
+
FileUtils.mkdir_p(tmpdir) rescue nil
|
50
|
+
installer.unpack(tmpdir)
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_extensions
|
54
|
+
installer.build_extensions(tmpdir, format.spec)
|
55
|
+
end
|
56
|
+
|
57
|
+
def platform
|
58
|
+
# I used to use this to clean up gem names under
|
59
|
+
# darwin, not sure it was a good idea though
|
60
|
+
# Config::CONFIG['arch'].sub(/[\.0-9]*$/, '')
|
61
|
+
Config::CONFIG['arch']
|
62
|
+
end
|
63
|
+
|
64
|
+
def fix_gemspec(conservative = false)
|
65
|
+
files = []
|
66
|
+
Find.find(tmpdir) do |fname|
|
67
|
+
next if fname == tmpdir
|
68
|
+
next if !conservative && File.extname(fname) == OBJEXT
|
69
|
+
files << fname.sub(Regexp.quote(tmpdir + "/"), '')
|
70
|
+
end
|
71
|
+
|
72
|
+
spec.extensions = []
|
73
|
+
spec.files += (files - format.spec.files)
|
74
|
+
spec.platform = platform
|
75
|
+
end
|
76
|
+
|
77
|
+
def build_gem
|
78
|
+
start_dir = Dir.pwd
|
79
|
+
Dir.chdir(tmpdir) do
|
80
|
+
gb = Gem::Builder.new(spec)
|
81
|
+
gb.build
|
82
|
+
FileUtils.mv Dir.glob("*.gem"), start_dir
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def cleanup
|
87
|
+
FileUtils.rm_rf(tmpdir)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,111 @@
|
|
1
|
+
#
|
2
|
+
# Calling all interested testers -- how could I write better tests for this
|
3
|
+
# type of code? let me know at phurley@gmail.com -- Thanks!!!
|
4
|
+
#
|
5
|
+
# Could put all the tests in one methods and test them inline?
|
6
|
+
# this is an optimization, so I am holding off, the test time
|
7
|
+
# is not too bad now that I use a simple project.
|
8
|
+
#
|
9
|
+
# Add tests for complex gems (with multiple extensions)
|
10
|
+
#
|
11
|
+
# Should probably verify that the gem is installable
|
12
|
+
# as well, but I am not sure how far to go down that
|
13
|
+
# road (probably all the way, but it seems so cludgy
|
14
|
+
# already)
|
15
|
+
#
|
16
|
+
# And thanks to zenspider for ZenTest -- great stuff
|
17
|
+
#
|
18
|
+
require "test/unit"
|
19
|
+
require "gembuilder"
|
20
|
+
|
21
|
+
class TestGembuilder < Test::Unit::TestCase
|
22
|
+
GEMNAME = 'helloc-1.0.0.gem'
|
23
|
+
|
24
|
+
def setup
|
25
|
+
# find our test gem file.
|
26
|
+
# Note the nasty reliance on an external file
|
27
|
+
# and our eventual use of your file system
|
28
|
+
# slowing the tests
|
29
|
+
#
|
30
|
+
Dir.chdir "test" rescue nil
|
31
|
+
@gb = GemBuilder.new(GEMNAME)
|
32
|
+
end
|
33
|
+
|
34
|
+
def teardown
|
35
|
+
# how craptacular is this -- I am using the thing I am
|
36
|
+
# testing to cleanup -- somebody save me from my own
|
37
|
+
# insanity
|
38
|
+
@gb.cleanup
|
39
|
+
File.rm('helloc-1.0.0-*.gem') rescue nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def assert_file_exists(fname, msg = "The file #{fname} should exist and does not.")
|
43
|
+
assert(File.exists?(fname), msg)
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_file_exists_in_gem(fname, msg = "The file #{fname} should exist and does not.")
|
47
|
+
assert_file_exists(File.join(@gb.tmpdir, fname), msg)
|
48
|
+
end
|
49
|
+
|
50
|
+
def assert_files_exist_in_gem(files)
|
51
|
+
files.each { |file| assert_file_exists_in_gem(file) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_class_doit_all_method
|
55
|
+
GemBuilder[GEMNAME]
|
56
|
+
|
57
|
+
assert_file_exists("helloc-1.0.0-#{Config::CONFIG['arch']}.gem")
|
58
|
+
# not sure how to verify that the temp directory is properly cleaned up
|
59
|
+
# without adding some odd support for returning the temp directory name
|
60
|
+
# that should already be deleted at this point
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_tmpdir_does_not_exist
|
64
|
+
assert(!File.exists?(@gb.tmpdir), "Not generating a good temp directory")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_we_can_unpack_the_gem
|
68
|
+
@gb.unpack_gem
|
69
|
+
assert(File.exists?(@gb.tmpdir), "Failure message.")
|
70
|
+
|
71
|
+
assert_files_exist_in_gem ["History.txt", "Manifest.txt", "README.txt",
|
72
|
+
"Rakefile", "ext/helloc/extconf.rb", "ext/helloc/helloc.c"]
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_we_can_build_the_extensions
|
76
|
+
@gb.unpack_gem
|
77
|
+
@gb.build_extensions
|
78
|
+
assert_files_exist_in_gem [
|
79
|
+
"ext/helloc/helloc.#{Config::CONFIG['OBJEXT']}",
|
80
|
+
"lib/helloc.#{Config::CONFIG['DLEXT']}"
|
81
|
+
]
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_gemspec_changes
|
85
|
+
@gb.unpack_gem
|
86
|
+
@gb.build_extensions
|
87
|
+
@gb.fix_gemspec
|
88
|
+
|
89
|
+
assert(@gb.spec.files.include?("lib/helloc.#{Config::CONFIG['DLEXT']}"), "Shared library not found in gemspec")
|
90
|
+
assert(!@gb.spec.files.include?("ext/helloc/helloc.#{Config::CONFIG['OBJEXT']}"), "Intermediate file found in gemspec")
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_build_gem
|
94
|
+
@gb.unpack_gem
|
95
|
+
@gb.build_extensions
|
96
|
+
@gb.fix_gemspec
|
97
|
+
@gb.build_gem
|
98
|
+
|
99
|
+
# talk about self referential -- but how else to I make the
|
100
|
+
# tests work on different platforms?
|
101
|
+
assert_file_exists("helloc-1.0.0-#{Config::CONFIG['arch']}.gem")
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_cleanup
|
105
|
+
@gb.unpack_gem
|
106
|
+
@gb.build_extensions
|
107
|
+
@gb.cleanup
|
108
|
+
assert(!File.exists?(@gb.tmpdir))
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: gembuilder
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2007-05-22 00:00:00 -04:00
|
8
|
+
summary: Create a binary gem, for the current platform.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: phurley@gmail.com
|
12
|
+
homepage: " by Patrick Hurley"
|
13
|
+
rubyforge_project: gembuilder
|
14
|
+
description: "== FEATURES/PROBLEMS: * Would be better if it could gather the gem automatically out of the gem cache. * Should also have an option to attempt to cleanup intermediate files (.o/.obj) == SYNOPSIS: Build your gem so that it can be deployed on machines without a build chain == REQUIREMENTS:"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Patrick Hurley
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/gembuilder
|
37
|
+
- lib/gembuilder.rb
|
38
|
+
- test/test_gembuilder.rb
|
39
|
+
test_files:
|
40
|
+
- test/test_gembuilder.rb
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
executables:
|
46
|
+
- gembuilder
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
dependencies:
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: hoe
|
54
|
+
version_requirement:
|
55
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.2.0
|
60
|
+
version:
|