Permalink
Browse files

Use rakegem instead of jeweler for build automation.

  • Loading branch information...
1 parent fb6b5c0 commit 6ff8e66dd5826a13278abde61b1748da689c2f25 @mojombo committed Nov 19, 2010
View
182 Rakefile
@@ -1,67 +1,155 @@
require 'rubygems'
require 'rake'
+require 'date'
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "ernie"
- gem.rubyforge_project = "ernie"
- gem.summary = %Q{Ernie is a BERT-RPC server implementation.}
- gem.description = %Q{Ernie is an Erlang/Ruby hybrid BERT-RPC server implementation packaged as a gem.}
- gem.email = "tom@mojombo.com"
- gem.homepage = "http://github.com/mojombo/ernie"
- gem.authors = ["Tom Preston-Werner"]
- gem.files.include(["ext"])
- gem.extensions << 'ext/extconf.rb'
- gem.add_dependency('bert', '>= 1.1.0')
- gem.add_dependency('bertrpc', '>= 1.0.0')
-
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
- end
-rescue LoadError
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
+#############################################################################
+#
+# Helper functions
+#
+#############################################################################
+
+def name
+ @name ||= Dir['*.gemspec'].first.split('.').first
+end
+
+def version
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
+end
+
+def date
+ Date.today.to_s
+end
+
+def rubyforge_project
+ name
+end
+
+def gemspec_file
+ "#{name}.gemspec"
end
+def gem_file
+ "#{name}-#{version}.gem"
+end
+
+def replace_header(head, header_name)
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
+end
+
+#############################################################################
+#
+# Standard tasks
+#
+#############################################################################
+
+task :default => :test
+
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
- test.pattern = 'test/**/*_test.rb'
+ test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
-begin
- require 'rcov/rcovtask'
- Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/*_test.rb'
- test.verbose = true
- end
-rescue LoadError
- task :rcov do
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
- end
+desc "Generate RCov test coverage and open in your browser"
+task :coverage do
+ require 'rcov'
+ sh "rm -fr coverage"
+ sh "rcov test/test_*.rb"
+ sh "open coverage/index.html"
end
-task :default => :test
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "#{name} #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+desc "Open an irb session preloaded with this library"
+task :console do
+ sh "irb -rubygems -r ./lib/#{name}.rb"
+end
-# require 'rake/rdoctask'
-# Rake::RDocTask.new do |rdoc|
-# if File.exist?('VERSION.yml')
-# config = YAML.load(File.read('VERSION.yml'))
-# version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
-# else
-# version = ""
-# end
-#
-# rdoc.rdoc_dir = 'rdoc'
-# rdoc.title = "ernie #{version}"
-# rdoc.rdoc_files.include('README*')
-# rdoc.rdoc_files.include('lib/**/*.rb')
-# end
+#############################################################################
+#
+# Custom tasks (add your own tasks here)
+#
+#############################################################################
task :ebuild do
ERLC_TEST_FLAGS = ""
ERLC_FLAGS = "-o ../ebin"
cd "elib"
sh "erlc #{ERLC_FLAGS} #{ERLC_TEST_FLAGS} #{Dir["**/*.erl"].join(" ")}"
-end
+end
+
+#############################################################################
+#
+# Packaging tasks
+#
+#############################################################################
+
+desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
+task :release => :build do
+ unless `git branch` =~ /^\* master$/
+ puts "You must be on the master branch to release!"
+ exit!
+ end
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
+ sh "git tag v#{version}"
+ sh "git push origin master"
+ sh "git push origin v#{version}"
+ sh "gem push pkg/#{name}-#{version}.gem"
+end
+
+desc "Build #{gem_file} into the pkg directory"
+task :build => :gemspec do
+ sh "mkdir -p pkg"
+ sh "gem build #{gemspec_file}"
+ sh "mv #{gem_file} pkg"
+end
+
+desc "Generate #{gemspec_file}"
+task :gemspec => :validate do
+ # read spec file and split out manifest section
+ spec = File.read(gemspec_file)
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
+
+ # replace name version and date
+ replace_header(head, :name)
+ replace_header(head, :version)
+ replace_header(head, :date)
+ #comment this out if your rubyforge_project has a different name
+ replace_header(head, :rubyforge_project)
+
+ # determine file list from git ls-files
+ files = `git ls-files`.
+ split("\n").
+ sort.
+ reject { |file| file =~ /^\./ }.
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
+ map { |file| " #{file}" }.
+ join("\n")
+
+ # piece file back together and write
+ manifest = " s.files = %w[\n#{files}\n ]\n"
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
+ puts "Updated #{gemspec_file}"
+end
+
+desc "Validate #{gemspec_file}"
+task :validate do
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
+ unless libfiles.empty?
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
+ exit!
+ end
+ unless Dir['VERSION*'].empty?
+ puts "A `VERSION` file at root level violates Gem best practices."
+ exit!
+ end
+end
View
5 VERSION.yml
@@ -1,5 +0,0 @@
----
-:minor: 4
-:build:
-:patch: 0
-:major: 2
View
8 bin/ernie
@@ -14,14 +14,10 @@ def code_paths
DEFAULT_ERLANG_CODEPATHS.map {|n| "-pz #{rel(n)}" }.join(" ") + " \\"
end
-def version
- yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
- "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
-end
-
require 'optparse'
require 'pp'
require 'yaml'
+require 'ernie'
help = <<HELP
Ernie is an Erlang/Ruby BERT-RPC Server.
@@ -42,7 +38,7 @@ HELP
options = {}
OptionParser.new do |opts|
opts.banner = help
- opts.version = version
+ opts.version = Ernie::VERSION
opts.on("-c CONFIG", "--config CONFIG", "Config file") do |x|
options[:config] = x
View
161 ernie.gemspec
@@ -1,95 +1,80 @@
-# Generated by jeweler
-# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in rakefile, and run the gemspec command
-# -*- encoding: utf-8 -*-
-
Gem::Specification.new do |s|
- s.name = %q{ernie}
- s.version = "2.4.0"
-
+ s.specification_version = 2 if s.respond_to? :specification_version=
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Tom Preston-Werner"]
- s.date = %q{2010-05-21}
- s.default_executable = %q{ernie}
- s.description = %q{Ernie is an Erlang/Ruby hybrid BERT-RPC server implementation packaged as a gem.}
- s.email = %q{tom@mojombo.com}
- s.executables = ["ernie"]
+ s.rubygems_version = '1.3.6'
+
+ s.name = 'ernie'
+ s.version = '2.4.0'
+ s.date = '2010-11-19'
+ s.rubyforge_project = 'ernie'
+
+ s.summary = "Ernie is a BERT-RPC server implementation."
+ s.description = "Ernie is an Erlang/Ruby hybrid BERT-RPC server implementation packaged as a gem."
+
+ s.authors = ["Tom Preston-Werner"]
+ s.email = 'tom@mojombo.com'
+ s.homepage = 'http://github.com/mojombo/ernie'
+
+ s.require_paths = %w[lib]
+
s.extensions = ["ext/extconf.rb", "ext/extconf.rb"]
- s.extra_rdoc_files = [
- "LICENSE",
- "README.md"
- ]
- s.files = [
- ".document",
- ".gitignore",
- "History.txt",
- "LICENSE",
- "README.md",
- "Rakefile",
- "VERSION.yml",
- "bin/ernie",
- "contrib/ebench.erl",
- "ebin/ernie_server_app.app",
- "elib/asset_pool.erl",
- "elib/asset_pool_sup.erl",
- "elib/bert.erl",
- "elib/ernie.hrl",
- "elib/ernie_access_logger.erl",
- "elib/ernie_access_logger_sup.erl",
- "elib/ernie_admin.erl",
- "elib/ernie_config.erl",
- "elib/ernie_native.erl",
- "elib/ernie_server.erl",
- "elib/ernie_server_app.erl",
- "elib/ernie_server_sup.erl",
- "elib/logger.erl",
- "elib/logger_sup.erl",
- "elib/port_wrapper.erl",
- "ernie.gemspec",
- "examples/example.cfg",
- "examples/example.config",
- "examples/ext.erl",
- "examples/ext.rb",
- "examples/nat.erl",
- "ext/Makefile",
- "ext/extconf.rb",
- "lib/ernie.rb",
- "test/ernie_server_test.rb",
- "test/ernie_test.rb",
- "test/helper.rb",
- "test/load.rb",
- "test/sample/ext.rb",
- "test/sample/sample.cfg"
- ]
- s.homepage = %q{http://github.com/mojombo/ernie}
+
+ s.executables = ["ernie"]
+ s.default_executable = 'ernie'
+
s.rdoc_options = ["--charset=UTF-8"]
- s.require_paths = ["lib"]
- s.rubyforge_project = %q{ernie}
- s.rubygems_version = %q{1.3.6}
- s.summary = %q{Ernie is a BERT-RPC server implementation.}
- s.test_files = [
- "test/ernie_server_test.rb",
- "test/ernie_test.rb",
- "test/helper.rb",
- "test/load.rb",
- "test/sample/ext.rb",
- "examples/ext.rb"
- ]
+ s.extra_rdoc_files = %w[LICENSE README.md]
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
+ s.add_dependency('bert', [">= 1.1.0"])
+ s.add_dependency('bertrpc', [">= 1.0.0"])
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<bert>, [">= 1.1.0"])
- s.add_runtime_dependency(%q<bertrpc>, [">= 1.0.0"])
- else
- s.add_dependency(%q<bert>, [">= 1.1.0"])
- s.add_dependency(%q<bertrpc>, [">= 1.0.0"])
- end
- else
- s.add_dependency(%q<bert>, [">= 1.1.0"])
- s.add_dependency(%q<bertrpc>, [">= 1.0.0"])
- end
-end
+ s.add_development_dependency('shoulda', [">= 2.11.3", "< 3.0.0"])
+
+ # = MANIFEST =
+ s.files = %w[
+ History.txt
+ LICENSE
+ README.md
+ Rakefile
+ VERSION.yml
+ bin/ernie
+ contrib/ebench.erl
+ ebin/ernie_server_app.app
+ elib/asset_pool.erl
+ elib/asset_pool_sup.erl
+ elib/bert.erl
+ elib/ernie.hrl
+ elib/ernie_access_logger.erl
+ elib/ernie_access_logger_sup.erl
+ elib/ernie_admin.erl
+ elib/ernie_config.erl
+ elib/ernie_native.erl
+ elib/ernie_server.erl
+ elib/ernie_server_app.erl
+ elib/ernie_server_sup.erl
+ elib/logger.erl
+ elib/logger_sup.erl
+ elib/port_wrapper.erl
+ ernie.gemspec
+ examples/example.cfg
+ examples/example.config
+ examples/ext.erl
+ examples/ext.rb
+ examples/nat.erl
+ ext/Makefile
+ ext/extconf.rb
+ lib/ernie.rb
+ test/ernie_server_test.rb
+ test/ernie_test.rb
+ test/helper.rb
+ test/load.rb
+ test/sample/ext.rb
+ test/sample/intTest.erl
+ test/sample/sample.cfg
+ test/test_ernie.rb
+ test/test_ernie_server.rb
+ ]
+ # = MANIFEST =
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
+end
View
9 lib/ernie.rb
@@ -3,6 +3,8 @@
require 'logger'
class Ernie
+ VERSION = '2.4.0'
+
class << self
attr_accessor :mods, :current_mod, :log
attr_accessor :auto_start
@@ -185,13 +187,8 @@ def self.procline(msg)
end
def self.version
- yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
- "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
- rescue
- 'unknown'
+ VERSION
end
-
- VERSION = self.version
end
class Ernie::ServerError < StandardError; end
View
0 test/ernie_test.rb → test/test_ernie.rb
File renamed without changes.
View
0 test/ernie_server_test.rb → test/test_ernie_server.rb
File renamed without changes.

0 comments on commit 6ff8e66

Please sign in to comment.