This repository was archived by the owner on Feb 13, 2024. It is now read-only.
forked from github/github-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap
More file actions
executable file
·121 lines (107 loc) · 4.7 KB
/
bootstrap
File metadata and controls
executable file
·121 lines (107 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/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 rubygems.org
#/ --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
end
# go into the project root because it makes everything easier
root = File.expand_path('../..', __FILE__)
Dir.chdir(root)
# 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'
begin
require 'bundler'
rescue LoadError => boom
warn "Bundler not found. Install it with `gem install bundler' and try again."
exit 0
end
FileUtils.mkdir_p('.bundle')
# 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 = File.read('.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."
else
# run bundle-install to install any missing gems
argv = ['install', '--no-color', '--path', File.join(root, 'vendor/gems')]
argv += ['--standalone', '--binstubs', 'bin', '--shebang'] + 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"
exit($?.exitstatus)
end
# 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 gem.name == 'bundler'
gem.load_paths.each do |path|
if path[0, root.size] == root
path = path[(root.size + 1), path.size]
load_paths << path
else
warn "external load path directory detected: #{path}"
end
end
end
# move the loadpath and checksum files into place if everything was installed
# okay and the load path file was written successfully.
File.open('.bundle/loadpath+', 'wb') { |fd| fd.write(load_paths.join("\n")) }
File.rename('.bundle/loadpath+', '.bundle/loadpath')
File.open('.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 File.directory?("bin")
template = DATA.read
lineno = File.read(__FILE__).count("\n") - template.count("\n")
bundle.gems.each do |spec|
spec.executables.each do |executable|
script = eval('%Q{' + template + '}', binding, __FILE__, lineno)
File.open("bin/#{executable}+", 'wb') { |fd| fd.write(script) }
File.chmod 0755, "bin/#{executable}+"
File.rename("bin/#{executable}+", "bin/#{executable}")
end
end
end
__END__
#!/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}')