Class | Echoe |
In: |
lib/echoe.rb
lib/echoe/extensions.rb lib/echoe.rb lib/echoe/extensions.rb |
Parent: | Object |
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.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:
Versioning options:
Common packaging options:
Testing options:
Uncommon packaging options:
Security options:
Publishing options:
Documentation options:
author | [RW] | user-configurable |
author | [RW] | user-configurable |
bin_files | [RW] | best left alone |
bin_files | [RW] | best left alone |
certificate_chain | [RW] | user-configurable |
certificate_chain | [RW] | user-configurable |
changelog | [RW] | user-configurable |
changelog | [RW] | user-configurable |
changelog_patterns | [RW] | best left alone |
changelog_patterns | [RW] | best left alone |
changes | [RW] | user-configurable |
changes | [RW] | user-configurable |
clean_pattern | [RW] | user-configurable |
clean_pattern | [RW] | user-configurable |
dependencies | [RW] | legacy |
dependencies | [RW] | legacy |
description | [RW] | user-configurable |
description | [RW] | user-configurable |
development_dependencies | [RW] | user-configurable |
development_dependencies | [RW] | user-configurable |
docs_host | [RW] | user-configurable |
docs_host | [RW] | user-configurable |
[RW] | user-configurable | |
[RW] | user-configurable | |
eval | [RW] | best left alone |
eval | [RW] | best left alone |
executable_pattern | [RW] | user-configurable |
executable_pattern | [RW] | user-configurable |
extension_pattern | [RW] | user-configurable |
extension_pattern | [RW] | user-configurable |
extensions | [RW] | legacy |
extensions | [RW] | legacy |
extra_deps | [RW] | legacy |
extra_deps | [RW] | legacy |
files | [RW] | best left alone |
files | [RW] | best left alone |
gem_bin | [RW] | best left alone |
gem_bin | [RW] | best left alone |
gemspec_format | [RW] | user-configurable |
gemspec_format | [RW] | user-configurable |
gemspec_name | [RW] | best left alone |
gemspec_name | [RW] | best left alone |
has_rdoc | [RW] | best left alone |
has_rdoc | [RW] | best left alone |
ignore_pattern | [RW] | user-configurable |
ignore_pattern | [RW] | user-configurable |
include_gemspec | [RW] | best left alone |
include_gemspec | [RW] | best left alone |
include_rakefile | [RW] | best left alone |
include_rakefile | [RW] | best left alone |
install_message | [RW] | user-configurable |
install_message | [RW] | user-configurable |
lib_files | [RW] | best left alone |
lib_files | [RW] | best left alone |
manifest_name | [RW] | user-configurable |
manifest_name | [RW] | user-configurable |
name | [RW] | best left alone |
name | [RW] | best left alone |
need_gem | [RW] | user-configurable |
need_gem | [RW] | user-configurable |
need_tar_gz | [RW] | user-configurable |
need_tar_gz | [RW] | user-configurable |
need_tgz | [RW] | user-configurable |
need_tgz | [RW] | user-configurable |
need_zip | [RW] | user-configurable |
need_zip | [RW] | user-configurable |
platform | [RW] | user-configurable |
platform | [RW] | user-configurable |
private_key | [RW] | user-configurable |
private_key | [RW] | user-configurable |
project | [RW] | user-configurable |
project | [RW] | user-configurable |
rakefile_name | [RW] | best left alone |
rakefile_name | [RW] | best left alone |
rcov_options | [RW] | user-configurable |
rcov_options | [RW] | user-configurable |
rdoc_files | [RW] | legacy |
rdoc_files | [RW] | legacy |
rdoc_options | [RW] | best left alone |
rdoc_options | [RW] | best left alone |
rdoc_pattern | [RW] | user-configurable |
rdoc_pattern | [RW] | user-configurable |
rdoc_template | [RW] | user-configurable |
rdoc_template | [RW] | user-configurable |
require_paths | [RW] | user-configurable |
require_paths | [RW] | user-configurable |
require_signed | [RW] | user-configurable |
require_signed | [RW] | user-configurable |
retain_gemspec | [RW] | best left alone |
retain_gemspec | [RW] | best left alone |
ruby_version | [RW] | user-configurable |
ruby_version | [RW] | user-configurable |
rubygems_version | [RW] | best left alone |
rubygems_version | [RW] | best left alone |
runtime_dependencies | [RW] | user-configurable |
runtime_dependencies | [RW] | user-configurable |
spec | [RW] | best left alone |
spec | [RW] | best left alone |
spec_pattern | [RW] | user-configurable |
spec_pattern | [RW] | user-configurable |
summary | [RW] | user-configurable |
summary | [RW] | user-configurable |
test_files | [RW] | best left alone |
test_files | [RW] | best left alone |
test_pattern | [RW] | user-configurable |
test_pattern | [RW] | user-configurable |
url | [RW] | user-configurable |
url | [RW] | user-configurable |
use_sudo | [RW] | best left alone |
use_sudo | [RW] | best left alone |
version | [RW] | user-configurable |
version | [RW] | user-configurable |
# File lib/echoe.rb, line 164 164: def initialize(name, _version = nil) 165: # Defaults 166: 167: self.name = name 168: self.project = name.downcase 169: self.changelog = "CHANGELOG" 170: self.author = "" 171: self.email = "" 172: 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"] 173: self.test_pattern = File.exist?("test/test_all.rb") ? "test/test_all.rb" : ['test/**/test_*.rb', 'test/**/*_test.rb'] 174: self.spec_pattern = "spec/**/*_spec.rb" 175: 176: self.ignore_pattern = /^(pkg|doc)|\.svn|CVS|\.bzr|\.DS|\.git/ 177: 178: self.changelog_patterns = { 179: :version => [ 180: /^\s*v([\d\w\.]+)(\.|\s|$)/, 181: /\s*\*\s*([\d\w\.]+)\s*\*\s*$/ 182: ], 183: :changes => [ 184: /^\s*v([\d\.]+\. .*)/, 185: /\*\s*[\d\.]+\s*\*\s*(.*)\*\s*[\d\.]+\s*\*$/m 186: ] 187: } 188: 189: self.description = "" 190: self.summary = "" 191: self.install_message = nil 192: self.executable_pattern = /^bin\// 193: self.require_paths = nil 194: self.has_rdoc = true 195: self.use_sudo = !(Platform.windows? or ENV['GEM_HOME'].to_s.include?(ENV['USER'].to_s)) 196: self.gem_bin = "gem#{Platform.suffix}" 197: self.rcov_options = [] 198: self.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/ 199: 200: self.gemspec_format = :ruby 201: 202: title = (name.downcase == name ? name.capitalize : name) 203: self.rdoc_options = ['--line-numbers', '--inline-source', '--title', title] 204: 205: readme = Dir['*'].detect { |filename| filename =~ /^readme/i } 206: self.rdoc_options += ['--main', readme] if readme 207: 208: self.runtime_dependencies = [] 209: self.development_dependencies = [] # These appear to not work at all 210: self.manifest_name = "Manifest" 211: self.extension_pattern = ["ext/**/extconf.rb", "ext/extconf.rb"] 212: self.private_key = ENV['GEM_PRIVATE_KEY'] 213: self.require_signed = false 214: self.certificate_chain = ENV['GEM_CERTIFICATE_CHAIN'].to_s.split(/\,\s*/).compact 215: 216: self.need_gem = true 217: self.need_tar_gz = true 218: self.need_tgz = false 219: self.need_zip = false 220: self.platform = $platform 221: 222: self.include_rakefile = true 223: self.include_gemspec = true 224: self.gemspec_name = "#{name}.gemspec" 225: self.retain_gemspec = false 226: self.rakefile_name = "Rakefile" 227: self.rubygems_version = ">= 1.2" 228: 229: yield self if block_given? 230: 231: self.docs_host ||= "git@github.com:#{self.project}/#{self.project}.github.com" 232: if self.docs_host =~ /git@github.com/ 233: self.url ||= "http://#{self.project}.github.com/#{self.project}/#{(self.name + '/') if project != name}" 234: end 235: 236: # legacy compatibility 237: self.runtime_dependencies = dependencies if dependencies and runtime_dependencies.empty? 238: self.runtime_dependencies = extra_deps if extra_deps and runtime_dependencies.empty? 239: self.rdoc_pattern = rdoc_files if rdoc_files 240: self.extension_pattern = extensions if extensions 241: 242: # read manifest 243: begin 244: self.files = File.readlines(manifest_name).map { |x| x.strip } + 245: [(gemspec_name if include_gemspec)] + 246: [(rakefile_name if include_rakefile)] 247: self.files = files.compact.uniq 248: rescue Errno::ENOENT 249: unless ARGV.include? "manifest" 250: puts "Missing manifest. You can build one with 'rake manifest'." 251: exit 1 252: else 253: self.files = [] 254: end 255: end 256: 257: # snag version and changeset 258: self.version ||= _version 259: unless version 260: if File.exist? changelog 261: parsed = Array(changelog_patterns[:version]).map do |pattern| 262: open(changelog) do |log| 263: log.read[pattern, 1] 264: end 265: end.compact.first 266: raise "Could not parse version from #{changelog}" unless parsed 267: self.version = parsed.chomp(".").strip 268: else 269: raise "No #{changelog} found, and no version supplied in Rakefile." 270: end 271: end 272: 273: unless self.changes 274: self.changes = if File.exist? changelog 275: Array(changelog_patterns[:changes]).map do |pattern| 276: open(changelog) do |log| 277: log.read[pattern, 1] 278: end 279: end.compact.first or "" 280: else 281: "" 282: end 283: end 284: 285: # set some post-defaults 286: self.certificate_chain = Array(certificate_chain).map {|file| File.expand_path(file)} 287: self.private_key = File.expand_path(private_key) if private_key 288: self.description = summary if description.empty? 289: self.summary = description if summary.empty? 290: self.clean_pattern = apply_pattern(clean_pattern) 291: self.extension_pattern = apply_pattern(extension_pattern, files) 292: 293: self.ignore_pattern = apply_pattern(ignore_pattern) 294: honor_gitignore! if File.exist?(".git") 295: 296: self.rdoc_pattern = apply_pattern(rdoc_pattern, files) - [manifest_name] 297: self.executable_pattern = apply_pattern(executable_pattern, files) 298: self.test_pattern = apply_pattern(test_pattern) 299: self.spec_pattern = apply_pattern(spec_pattern) 300: 301: define_tasks 302: end
# File lib/echoe.rb, line 164 164: def initialize(name, _version = nil) 165: # Defaults 166: 167: self.name = name 168: self.project = name.downcase 169: self.changelog = "CHANGELOG" 170: self.author = "" 171: self.email = "" 172: 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"] 173: self.test_pattern = File.exist?("test/test_all.rb") ? "test/test_all.rb" : ['test/**/test_*.rb', 'test/**/*_test.rb'] 174: self.spec_pattern = "spec/**/*_spec.rb" 175: 176: self.ignore_pattern = /^(pkg|doc)|\.svn|CVS|\.bzr|\.DS|\.git/ 177: 178: self.changelog_patterns = { 179: :version => [ 180: /^\s*v([\d\w\.]+)(\.|\s|$)/, 181: /\s*\*\s*([\d\w\.]+)\s*\*\s*$/ 182: ], 183: :changes => [ 184: /^\s*v([\d\.]+\. .*)/, 185: /\*\s*[\d\.]+\s*\*\s*(.*)\*\s*[\d\.]+\s*\*$/m 186: ] 187: } 188: 189: self.description = "" 190: self.summary = "" 191: self.install_message = nil 192: self.executable_pattern = /^bin\// 193: self.require_paths = nil 194: self.has_rdoc = true 195: self.use_sudo = !(Platform.windows? or ENV['GEM_HOME'].to_s.include?(ENV['USER'].to_s)) 196: self.gem_bin = "gem#{Platform.suffix}" 197: self.rcov_options = [] 198: self.rdoc_pattern = /^(lib|bin|tasks|ext)|^README|^CHANGELOG|^TODO|^LICENSE|^COPYING$/ 199: 200: self.gemspec_format = :ruby 201: 202: title = (name.downcase == name ? name.capitalize : name) 203: self.rdoc_options = ['--line-numbers', '--inline-source', '--title', title] 204: 205: readme = Dir['*'].detect { |filename| filename =~ /^readme/i } 206: self.rdoc_options += ['--main', readme] if readme 207: 208: self.runtime_dependencies = [] 209: self.development_dependencies = [] # These appear to not work at all 210: self.manifest_name = "Manifest" 211: self.extension_pattern = ["ext/**/extconf.rb", "ext/extconf.rb"] 212: self.private_key = ENV['GEM_PRIVATE_KEY'] 213: self.require_signed = false 214: self.certificate_chain = ENV['GEM_CERTIFICATE_CHAIN'].to_s.split(/\,\s*/).compact 215: 216: self.need_gem = true 217: self.need_tar_gz = true 218: self.need_tgz = false 219: self.need_zip = false 220: self.platform = $platform 221: 222: self.include_rakefile = true 223: self.include_gemspec = true 224: self.gemspec_name = "#{name}.gemspec" 225: self.retain_gemspec = false 226: self.rakefile_name = "Rakefile" 227: self.rubygems_version = ">= 1.2" 228: 229: yield self if block_given? 230: 231: self.docs_host ||= "git@github.com:#{self.project}/#{self.project}.github.com" 232: if self.docs_host =~ /git@github.com/ 233: self.url ||= "http://#{self.project}.github.com/#{self.project}/#{(self.name + '/') if project != name}" 234: end 235: 236: # legacy compatibility 237: self.runtime_dependencies = dependencies if dependencies and runtime_dependencies.empty? 238: self.runtime_dependencies = extra_deps if extra_deps and runtime_dependencies.empty? 239: self.rdoc_pattern = rdoc_files if rdoc_files 240: self.extension_pattern = extensions if extensions 241: 242: # read manifest 243: begin 244: self.files = File.readlines(manifest_name).map { |x| x.strip } + 245: [(gemspec_name if include_gemspec)] + 246: [(rakefile_name if include_rakefile)] 247: self.files = files.compact.uniq 248: rescue Errno::ENOENT 249: unless ARGV.include? "manifest" 250: puts "Missing manifest. You can build one with 'rake manifest'." 251: exit 1 252: else 253: self.files = [] 254: end 255: end 256: 257: # snag version and changeset 258: self.version ||= _version 259: unless version 260: if File.exist? changelog 261: parsed = Array(changelog_patterns[:version]).map do |pattern| 262: open(changelog) do |log| 263: log.read[pattern, 1] 264: end 265: end.compact.first 266: raise "Could not parse version from #{changelog}" unless parsed 267: self.version = parsed.chomp(".").strip 268: else 269: raise "No #{changelog} found, and no version supplied in Rakefile." 270: end 271: end 272: 273: unless self.changes 274: self.changes = if File.exist? changelog 275: Array(changelog_patterns[:changes]).map do |pattern| 276: open(changelog) do |log| 277: log.read[pattern, 1] 278: end 279: end.compact.first or "" 280: else 281: "" 282: end 283: end 284: 285: # set some post-defaults 286: self.certificate_chain = Array(certificate_chain).map {|file| File.expand_path(file)} 287: self.private_key = File.expand_path(private_key) if private_key 288: self.description = summary if description.empty? 289: self.summary = description if summary.empty? 290: self.clean_pattern = apply_pattern(clean_pattern) 291: self.extension_pattern = apply_pattern(extension_pattern, files) 292: 293: self.ignore_pattern = apply_pattern(ignore_pattern) 294: honor_gitignore! if File.exist?(".git") 295: 296: self.rdoc_pattern = apply_pattern(rdoc_pattern, files) - [manifest_name] 297: self.executable_pattern = apply_pattern(executable_pattern, files) 298: self.test_pattern = apply_pattern(test_pattern) 299: self.spec_pattern = apply_pattern(spec_pattern) 300: 301: define_tasks 302: end
# File lib/echoe/extensions.rb, line 14 14: def self.silence 15: if !ENV['VERBOSE'] 16: stdout, stderr = $stdout.clone, $stderr.clone 17: $stdout.reopen(File.new("#{Dir.tmpdir}/stdout.echoe", 'w')) 18: $stderr.reopen(File.new("#{Dir.tmpdir}/stderr.echoe", 'w')) 19: begin 20: yield 21: ensure 22: $stdout.reopen(stdout) 23: $stderr.reopen(stderr) 24: end 25: else 26: yield 27: end 28: end
# File lib/echoe/extensions.rb, line 14 14: def self.silence 15: if !ENV['VERBOSE'] 16: stdout, stderr = $stdout.clone, $stderr.clone 17: $stdout.reopen(File.new("#{Dir.tmpdir}/stdout.echoe", 'w')) 18: $stderr.reopen(File.new("#{Dir.tmpdir}/stderr.echoe", 'w')) 19: begin 20: yield 21: ensure 22: $stdout.reopen(stdout) 23: $stderr.reopen(stderr) 24: end 25: else 26: yield 27: end 28: end