Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 118 lines (105 sloc) 4.59 KB
#!/usr/bin/env ruby
#/ Usage: script/bootstrap [<options>]
#/ Bootstraps the gem environment.
#/ Options are passed through to the bundle-install command. In most cases you
#/ won't need these. They're used primarily in production environments.
#/ --local use gems in vendor/cache instead of
#/ --without=<groups> do not install gems in the groups specified
# =============================================================================
# Uses bundler to install all gems specified in the Gemfile under vendor/gems,
# records the load path in config/loadpath, and generates bundler-free binstubs
# under bin.
# The basic idea is to use bundler to install necessary gems but not
# rely on it to manage the load path at runtime because it's slow. Requiring
# 'bundler/setup' takes ~500ms user CPU time in production and ~1500ms in
# development/test. This makes it unusable in scenarios that require a fast
# boot (e.g., script/gerve, proxymachine daemons, ernie/smoke, etc.). It's also
# a problem in development where it slows tools like rake command line
# completion to a crawl and adds at least a second to single-file test runs.
# There's very little reason to use bundler at runtime since everything
# is known at install time. We simply save off the result of the work done by
# bundle/setup and use it until bundle-install is run again.
# show usage message with --help
if ARGV.include?('--help')
system "grep '^#/' <'#{__FILE__}' |cut -c4-"
exit 2
# go into the project root because it makes everything easier
root = File.expand_path('../..', __FILE__)
# point bundler to the right stuff
ENV['BUNDLE_GEMFILE'] = "#{root}/Gemfile"
ENV['BUNDLE_PATH'] = "#{root}/vendor/gems"
# bring in rubygems and make sure bundler is installed.
require 'rubygems'
require 'bundler'
rescue LoadError => boom
warn "Bundler not found. Install it with `gem install bundler' and try again."
exit 0
# record the Gemfile checksum so we can tell if the Gemfile has changed
# since our loadpath was last generated. this is used in config/basic.rb
# to verify the environment is bootstrapped and up-to-date.
checksum = `cksum Gemfile`.to_i
installed ='.bundle/checksum').to_i rescue nil
# run a quick check to see if everything's installed and up-to-date so we can
# skip the install and loadpath generation step if possible.
if checksum == installed && system('bundle check 1>/dev/null 2>&1')
puts "Gem environment up-to-date."
# run bundle-install to install any missing gems
argv = ['--no-color', 'install', '--path', 'vendor/gems'] + ARGV
system("bundle", *argv) || begin
warn "bundle executable not found. Ensure bundler is installed (`gem " +
"install bundler`) and that the gem bin path is in your PATH"
# load the Gemfile
bundle = Bundler.setup
# extract load paths for each gem and write to the config/loadpath file.
load_paths = []
bundle.gems.each do |gem|
next if == 'bundler'
gem.load_paths.each do |path|
if path[0, root.size] == root
path = path[(root.size + 1), path.size]
load_paths << path
warn "external load path directory detected: #{path}"
# move the loadpath and checksum files into place if everything was installed
# okay and the load path file was written successfully.'.bundle/loadpath+', 'wb') { |fd| fd.write(load_paths.join("\n")) }
File.rename('.bundle/loadpath+', '.bundle/loadpath')'.bundle/checksum', 'wb') { |fd| fd.puts(checksum) }
# write binstubs for all executables. we can't use bundler's --binstubs option
# because the generated executables require 'bundler/setup'. the binstubs
# generated here require only config/basic.rb, which sets up the loadpath
# manually using the .bundle/loadpath file.
Dir.mkdir "bin" unless"bin")
template =
lineno ="\n") - template.count("\n")
bundle.gems.each do |spec|
spec.executables.each do |executable|
script = eval('%Q{' + template + '}', binding, __FILE__, lineno)"bin/#{executable}+", 'wb') { |fd| fd.write(script) }
File.chmod 0755, "bin/#{executable}+"
File.rename("bin/#{executable}+", "bin/#{executable}")
#!/usr/bin/env #{RbConfig::CONFIG['ruby_install_name']}
# This file was generated by script/bootstrap.
root = File.expand_path('../..', __FILE__)
require "#\{root\}/config/load"
gem_path = "#{spec.full_gem_path.sub(root, "#\{root\}")}"
load File.join(gem_path, '#{spec.bindir}', '#{executable}')
Jump to Line
Something went wrong with that request. Please try again.