Echoe includes some optional accessors for more advanced gem configuration.
For example, a simple Rakefile might look like this:
require 'echoe' Echoe.new("uncapitalizer") do |p| p.author = "Evan Weaver" p.summary = "A library that uncapitalizes strings." p.url = "http://www.uncapitalizer.com" p.docs_host = "uncapitalizer.com:~/www/files/doc/" p.runtime_dependencies = ["string_tools >=1.4.0"] end
See below for the full list.
Echoe supports signing gems. First, create yourself a public and private key:
gem cert --build you@yourmail.com
Move them somewhere secret, and add the following environment variables in your .bash_profile or similar:
export GEM_PRIVATE_KEY='/secret/path/to/gem-private_key.pem' export GEM_CERTIFICATE_CHAIN='/secret/path/to/gem-public_cert.pem'
Make sure your environment is up-to-date:
source ~/.bash_profile
Upload your public_cert.pem file to your website or Rubyforge project, and tell your users to add that certificate to their system via:
gem cert --add /path/to/public_cert.pem
Finally, package and release your project as normal. Now users can install your gem via:
sudo gem install gemname -P HighSecurity
Note that you can also set the key and certificate locations in the Rakefile itself. Finally, you can add p.require_signed = true to your Rakefile so that you don't accidentally release an unsigned gem if your key is missing.
Echoe does not force packages to depend on Echoe itself. Instead, it generates a gemspec from your Rakefile and includes that. Downstream repackagers can use the gemspec as-is to build new versions of your gem even without Echoe.
Echoe supports platform Rake targets to allow you to cross-package your gems. Just write the spec assuming RUBY_PLATFORM will be what you need it to be for each architecture, and then invoke Rake with the platform name when you're cross-packaging.
For example, on JRuby, rake package will build a generic -ruby type gem. But if you want to include a Java-specific extension, you can do one of two things. You can package from within JRuby by checking if RUBY_PLATFORM =~ /java/ and setting p.platform = jruby, or you can run rake java package, which will set RUBY_PLATFORM and p.platform for you.
This way you can run rake java package, rake aix install, or whatever task you need and Echoe will behave just like you're packaging from within the target platform.
For some applications, you may need to setup and teardown environment state for the entire test suite. This is especially common for integration tests that may need to spawn an external daemon. To support this, you can add a file tests/setup.rb and it will be silently executed before the entire suite runs. Add a similar file tests/teardown.rb in your app to be executed at the end of the entire run.
Note; these files will only get executed if you run the tests via rake. Also, you can set the environment variable VERBOSE=1 to not hide the setup/teardown output.
Descriptive options:
author - Your name.
email - Your email address.
description - A more detailed description of the library.
summary - A shorter description of the library.
url - A url for the library.
install_message - A message to display after the gem is installed.
Versioning options:
version - A string for the version number. Parsed from CHANGELOG otherwise.
changes - A string describing the most recent changes. Parsed from CHANGELOG otherwise.
Common packaging options:
runtime_dependencies - An array of runtime dependencies for this gem. For example, ['mongrel', 'activesupport >= 2.0.2'].
development_dependencies - An array of development dependencies for this gem. For example, ['rake >=0.7.1'].
extension_pattern - A filename array, glob array, or regex for extension files that need to be run at install time. Defaults to "ext/**/extconf.rb".
Testing options:
clean_pattern - A filename array, glob array, or regex for files that should be removed when rake clean is run.
test_pattern - A filename array, glob array, or regex for test runners. Overridden by "test/test_all.rb", if it exists.
spec_pattern - A filename array, glob array, or regex for test runners.
rcov_options - Any extra flags to pass to RCov when coverage reports are run.
Uncommon packaging options:
platform - What platform this gem is for.
manifest_name - The name of the manifest file. Defaults to Manifest.
need_gem - Whether to generate a gem package. Defaults to true.
need_tar_gz - Whether to generate a .tar.gz package. Defaults to true.
need_tgz - Whether to generate a .tgz package. Defaults to false.
need_zip - Whether to generate a .zip package. Defaults to false.
include_rakefile - Include the Rakefile directly within the package. Defaults to true.
include_gemspec - Include the generated gemspec file within the package. Defaults to true.
ruby_version - Version string for which Ruby to require (for example, '>= 1.8.4'.
eval - Accepts a proc to be evaluated in the context of the Gem::Specification object. This allows you to set more unusual gemspec options.
ignore_pattern - A filename array, glob array, or regex for pathnames that should be ignored when building the manifest.
require_paths - Non-standard requirement paths to add to the gem definition.
executable_pattern - A filename array, glob array, or regex for files that should be installed as wrapped executables.
Security options:
private_key - The path to your gem private key. Defaults to ENV, if available. This accessor is not published in the resulting gemspec.
certificate_chain - An array representing your certificate authorization chain. If no one else has signed your certificate, just set it to your own cert. Defaults to ENV, if available. This accessor is not published in the resulting gemspec.
require_signed - Force Echoe to refuse to package your gem if it's not properly signed. Default false.
Publishing options:
project - The name of the Rubyforge project. Defaults to the name of the gem.
docs_host - A host and filesystem path to publish the documentation to. Defaults to the Rubyforge project.
Documentation options:
rdoc_pattern - A filename array, glob array, or regex for filenames that should be passed to RDoc.
rdoc_template - A path to an RDoc template. Defaults to the generic template.
# File lib/echoe.rb, line 165 def initialize(name, _version = nil) # Defaults self.name = name self.project = name.downcase self.changelog = "CHANGELOG" self.url = "" self.author = "" self.email = "" self.clean_pattern = ["pkg", "doc", 'build/*', '**/coverage', '**/*.o', '**/*.so', '**/*.a', '**/*.log', "{ext,lib}/*.{bundle,so,obj,pdb,lib,def,exp}", "ext/Makefile", "{ext,lib}/**/*.{bundle,so,obj,pdb,lib,def,exp}", "ext/**/Makefile", "pkg", "*.gem", ".config"] self.test_pattern = File.exist?("test/test_all.rb") ? "test/test_all.rb" : ['test/**/test_*.rb', 'test/**/*_test.rb'] self.spec_pattern = "spec/**/*_spec.rb" self.ignore_pattern = /^(pkg|doc)|\.svn|CVS|\.bzr|\.DS|\.git/ self.changelog_patterns = { :version => [ /^\s*v([\d\w\.]+)(\.|\s|$)/, /\s*\*\s*([\d\w\.]+)\s*\*\s*$/ ], :changes => [ /^\s*v([\d\.]+\. .*)/, /\*\s*[\d\.]+\s*\*\s*(.*)\*\s*[\d\.]+\s*\*$/ ] } self.description = "" self.summary = "" self.install_message = nil self.executable_pattern = /^bin\// self.require_paths = nil self.has_rdoc = true self.use_sudo = !(Platform.windows? or ENV['GEM_HOME'].to_s.include?(ENV['USER'].to_s)) self.gem_bin = "gem#{Platform.suffix}" self.rcov_options = [] self.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/ self.gemspec_format = :ruby title = (name.downcase == name ? name.capitalize : name) self.rdoc_options = ['--line-numbers', '--inline-source', '--title', title] readme = Dir['*'].detect { |filename| filename =~ /^readme/ } self.rdoc_options += ['--main', readme] if readme self.runtime_dependencies = [] self.development_dependencies = [] # These appear to not work at all self.manifest_name = "Manifest" self.extension_pattern = ["ext/**/extconf.rb", "ext/extconf.rb"] self.private_key = ENV['GEM_PRIVATE_KEY'] self.require_signed = false self.certificate_chain = ENV['GEM_CERTIFICATE_CHAIN'].to_s.split(/\,\s*/).compact self.need_gem = true self.need_tar_gz = true self.need_tgz = false self.need_zip = false self.platform = $platform self.include_rakefile = true self.include_gemspec = true self.gemspec_name = "#{name}.gemspec" self.retain_gemspec = false self.rakefile_name = "Rakefile" self.rubygems_version = ">= 1.2" yield self if block_given? # legacy compatibility self.runtime_dependencies = dependencies if dependencies and runtime_dependencies.empty? self.runtime_dependencies = extra_deps if extra_deps and runtime_dependencies.empty? self.project = rubyforge_name if rubyforge_name self.rdoc_pattern = rdoc_files if rdoc_files self.extension_pattern = extensions if extensions # read manifest begin self.files = File.readlines(manifest_name).map { |x| x.strip } + [(gemspec_name if include_gemspec)] + [(rakefile_name if include_rakefile)] self.files = files.compact.uniq rescue Errno::ENOENT unless ARGV.include? "manifest" puts "Missing manifest. You can build one with 'rake manifest'." exit 1 else self.files = [] end end # snag version and changeset self.version ||= _version unless version if File.exist? changelog parsed = Array(changelog_patterns[:version]).map do |pattern| open(changelog) do |log| log.read[pattern, 1] end end.compact.first raise "Could not parse version from #{changelog}" unless parsed self.version = parsed.chomp(".").strip else raise "No #{changelog} found, and no version supplied in Rakefile." end end unless self.changes self.changes = if File.exist? changelog Array(changelog_patterns[:changes]).map do |pattern| open(changelog) do |log| log.read[pattern, 1] end end.compact.first or "" else "" end end # set some post-defaults self.certificate_chain = Array(certificate_chain).map {|file| File.expand_path(file)} self.private_key = File.expand_path(private_key) if private_key self.description = summary if description.empty? self.summary = description if summary.empty? self.clean_pattern = apply_pattern(clean_pattern) self.extension_pattern = apply_pattern(extension_pattern, files) self.ignore_pattern = apply_pattern(ignore_pattern) honor_gitignore! if File.exist?(".git") self.rdoc_pattern = apply_pattern(rdoc_pattern, files) - [manifest_name] self.executable_pattern = apply_pattern(executable_pattern, files) self.test_pattern = apply_pattern(test_pattern) self.spec_pattern = apply_pattern(spec_pattern) define_tasks end
# File lib/echoe/extensions.rb, line 14 def self.silence if !ENV['VERBOSE'] stdout, stderr = $stdout.clone, $stderr.clone $stdout.reopen(File.new("#{Dir.tmpdir}/stdout.echoe", 'w')) $stderr.reopen(File.new("#{Dir.tmpdir}/stderr.echoe", 'w')) begin yield ensure $stdout.reopen(stdout) $stderr.reopen(stderr) end else yield end end
Generated with the Darkfish Rdoc Generator 2.