This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
/
brew
executable file
·246 lines (214 loc) · 7.65 KB
/
brew
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
ENV['RUBYLIB']=HOMEBREW_RUBYLIB=File.expand_path(__FILE__+'/../../Library/Homebrew')
$:.unshift HOMEBREW_RUBYLIB
require 'global'
require 'brew.h'
if %w[/ /usr].include? HOMEBREW_PREFIX.to_s then abort <<-EOS
You have placed Homebrew at the prefix: #{HOMEBREW_PREFIX}
This is not currently supported. Voice your support for this feature at:
#{HOMEBREW_WWW}
EOS
end
# remove MacPorts and Fink from the PATH, this prevents issues like:
# http://github.com/mxcl/homebrew/issues/#issue/13
# http://github.com/mxcl/homebrew/issues/#issue/48
fix_PATH
if `/usr/bin/sw_vers -productVersion` =~ /10\.(\d)\.(\d+)/ and $1.to_i < 5
onoe "Homebrew requires Leopard or higher"
abort "But thanks for your interest anyway!"
end
if Hardware.cpu_type == :ppc or Hardware.cpu_type == :dunno
abort "Sorry, Homebrew does not support your computer's CPU architecture."
end
unless system "/usr/bin/which -s gcc-4.2"
abort "Sorry, Homebrew requires gcc 4.2, which is provided by Xcode 3.1"
end
begin
case ARGV.shift
when '--prefix' then puts HOMEBREW_PREFIX
when '--cache' then puts HOMEBREW_CACHE
when '-h', '--help', '--usage', '-?' then puts ARGV.usage
when '-v', '--version' then puts HOMEBREW_VERSION
when 'home', 'homepage'
if ARGV.named_empty?
exec "open", HOMEBREW_WWW
else
exec "open", *ARGV.formulae.collect {|f| f.homepage}
end
when 'ls', 'list'
if ARGV.named_empty?
ENV['CLICOLOR']=nil
exec 'ls', *ARGV.options<<HOMEBREW_CELLAR
elsif ARGV.verbose?
exec "find", *ARGV.kegs+%w[-not -type d -print]
else
ARGV.kegs.each { |keg| PrettyListing.new keg }
end
when 'search', '-S'
formulae = (HOMEBREW_PREFIX+'Library'+'Formula').children.sort.map{|f| f.basename('.rb') }
puts_columns formulae.grep(Regexp.new(ARGV.first || ''))
when 'edit'
if ARGV.named_empty?
# EDITOR isn't a good fit here, we need a GUI client that actually has
# a UI for projects, so apologies if this wasn't what you expected,
# please improve it! :)
exec 'mate', *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
"#{HOMEBREW_PREFIX}/bin/brew"<<
"#{HOMEBREW_PREFIX}/README.md"
else
exec_editor *ARGV.formulae.collect {|f| f.path}
end
when 'install'
if ARGV.named_empty?
puts "You must specify a formula. Search for available formulae with `brew search'."
exit 0
end
raise "Cannot write to #{HOMEBREW_PREFIX}" unless HOMEBREW_PREFIX.writable?
require 'brewkit'
if ARGV.verbose?
ohai "Build Environment"
%w[CFLAGS LDFLAGS CPPFLAGS MAKEFLAGS CC CXX MACOSX_DEPLOYMENT_TARGET].each do |f|
puts "#{f}: #{ENV[f]}" unless ENV[f].to_s.empty?
end
end
if ARGV.interactive? and ARGV.formulae.length > 1
# the reason for this is interactive mode is a little tricky to do
# with more than one formula, AND I can't think of a time where you'd
# want to do it anyway. If someone comes up with a legitimate use for
# this we will adapt the code. "But I might want it!" is not a
# legitimate use!
raise "Interactive mode can only be used with one formula argument"
end
unless ARGV.force?
unless system "/usr/bin/which -s #{ENV.cc}"
raise "We cannot find a c compiler, have you installed the latest Xcode?"
end
formulae = ARGV.formulae.reject do |f|
if f.installed?
message = "Formula already installed: #{f.prefix}"
if ARGV.formulae.length > 1
opoo message
else
puts message # if only one is being installed a warning looks severe
end
true
end
end
exit 0 if formulae.empty?
else
formulae = ARGV.formulae
end
unless ARGV.include? '--ignore-dependencies'
deps = []
formulae.each { |f| deps += expand_deps f }
formulae = deps.reject { |f| f.installed? }
end
require 'set'
done = Set.new
require 'beer_events'
watch_out_for_spill do
formulae.each do |f|
next if done.include? f.class
done << f.class
# 1. formulae can modify ENV, so we must ensure that each
# installation has a pristine ENV when it starts, forking now is
# the easiest way to do this
# 2. formulae have access to __END__ the only way to allow this is
# to make the formula script the executed script
pid=fork
if pid.nil?
exec 'ruby', '-r', "#{HOMEBREW_RUBYLIB}/install", f.path, '--', *ARGV.options
else
Process.wait pid
end
#FIXME I don't think $? represents the exit code from the child fork…
exit! $? if $? != 0 # exception in other brew will be visible on screen
end
end
when 'up', 'update'
require 'update'
updater = RefreshBrew.new
old_revision = updater.current_revision
unless updater.update_from_masterbrew!
puts "Already up-to-date."
else
puts "Updated Homebrew from #{old_revision} to #{updater.current_revision}."
if updater.pending_formulae_changes?
ohai "The following formulae were updated:"
puts_columns updater.updated_formulae
else
puts "No formulae were updated." unless updater.pending_formulae_changes?
end
end
when 'ln', 'link'
ARGV.kegs.each {|keg| puts "#{keg.link} links created for #{keg}"}
when 'unlink'
ARGV.kegs.each {|keg| puts "#{keg.unlink} links removed for #{keg}"}
when 'rm', 'uninstall', 'remove'
ARGV.kegs.each do |keg|
puts "Uninstalling #{keg}..."
keg.uninstall
end
prune
when 'prune'
prune
# 'make' supported until 0.7 for historic reasons
when 'mk', 'make'
opoo "`brew make' has changed to `brew create'"
puts "This is because make can be confused with the `make' tool."
puts "brew make will continue working until Homebrew 0.7"
exec __FILE__, "create", *ARGV
when 'create'
if ARGV.include? '--macports'
exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
else
exec_editor *ARGV.collect {|name| make name}
end
when 'diy', 'configure'
puts diy
when 'info', 'abv'
if ARGV.named_empty?
puts `ls #{HOMEBREW_CELLAR} | wc -l`.strip+" kegs, "+HOMEBREW_CELLAR.abv
elsif ARGV[0][0..6] == 'http://'
puts Pathname.new(ARGV.shift).version
else
ARGV.named.each {|name| info name}
end
when 'log'
Dir.chdir HOMEBREW_PREFIX
exec "git", "log", ARGV.formulae.first.path, *ARGV.options
else
puts ARGV.usage
end
rescue UsageError
onoe "Invalid usage"
puts ARGV.usage
exit 1
rescue SystemExit
ohai "Kernel.exit" if ARGV.verbose?
exit 1
rescue Interrupt => e
# puts # seemingly a newline is typical
# Above is now commented out because the system() call forks and then forks
# again, so there are two of "us" so we get two exceptions raising and thus
# two newlines, which buggers up the shell. FIXME!
exit 130
rescue SystemCallError, RuntimeError => e
if ARGV.debug?
onoe e.inspect
puts e.backtrace
else
onoe e
end
exit 1
rescue Exception => e
onoe "Homebrew has failed you :("
puts "Please report this bug at: #{HOMEBREW_WWW}"
puts "Please include the following information:"
ohai "Environment"
puts "Mac OS X: "+`sw_vers -productVersion`
ohai e.inspect
puts e.backtrace
exit 1
end