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
·288 lines (251 loc) · 8.37 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
# Many Pathname operations use getwd when they shouldn't, and then throw
# odd exceptions. Reduce our support burden by showing a user-friendly error.
Dir.getwd rescue abort "The current working directory doesn't exist, cannot proceed."
HOMEBREW_BREW_FILE = ENV['HOMEBREW_BREW_FILE'] = File.expand_path(__FILE__)
require 'pathname'
$:.unshift((Pathname.new(__FILE__).realpath.dirname.parent+"Library"+"Homebrew").to_s)
require 'global'
case ARGV.first
when '--cache'
puts HOMEBREW_CACHE
exit 0
when '-h', '--help', '--usage', '-?', 'help', nil
puts ARGV.usage
exit 0
when '--version'
puts HOMEBREW_VERSION
exit 0
when '-v'
if ARGV.length > 1
puts "Homebrew #{HOMEBREW_VERSION}"
# continue in verbose mode
ARGV << ARGV.shift
else
puts HOMEBREW_VERSION
exit 0
end
end
case HOMEBREW_PREFIX.to_s when '/', '/usr'
# it may work, but I only see pain this route and don't want to support it
abort "Cowardly refusing to continue at this prefix: #{HOMEBREW_PREFIX}"
end
if MACOS_VERSION < 10.5
abort "Homebrew requires Leopard or higher, but you could fork it and fix that..."
end
def dump_config
require 'hardware'
bits = Hardware.bits
cores = Hardware.cores_as_words
llvm = llvm_build
sha = `git rev-parse --verify HEAD`.chomp
kernel_arch = `uname -m`.chomp
puts <<-EOS
HOMEBREW_VERSION: #{HOMEBREW_VERSION}
HEAD: #{sha}
HOMEBREW_PREFIX: #{HOMEBREW_PREFIX}
HOMEBREW_CELLAR: #{HOMEBREW_CELLAR}
HOMEBREW_CACHE: #{HOMEBREW_CACHE}
HOMEBREW_REPOSITORY: #{HOMEBREW_REPOSITORY}
Library Path: #{$:.first}
Hardware: #{cores}-core #{bits}-bit #{Hardware.intel_family}
OS X: #{MACOS_FULL_VERSION}
Kernel Architecture: #{kernel_arch}
Ruby: #{RUBY_VERSION}-#{RUBY_PATCHLEVEL}
GCC: 4.2 build #{gcc_build}
LLVM: #{llvm ? "build #{llvm}" : "N/A" }
MacPorts or Fink? #{macports_or_fink_installed?}
EOS
end
begin
require 'brew.h'
case arg = ARGV.shift
when '--prefix'
puts HOMEBREW_PREFIX
when '--config'
dump_config
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.flag? '--unbrewed'
dirs = HOMEBREW_PREFIX.children.select { |pn| pn.directory? }.collect { |pn| pn.basename.to_s }
dirs -= ['Library', 'Cellar', '.git']
Dir.chdir HOMEBREW_PREFIX
exec 'find', *dirs + %w[-type f ( ! -iname .ds_store ! -iname brew )]
elsif ARGV.named.empty?
ENV['CLICOLOR']=nil
exec 'ls', *ARGV.options<<HOMEBREW_CELLAR if HOMEBREW_CELLAR.exist?
elsif ARGV.verbose? or not $stdout.tty?
exec "find", *ARGV.kegs+%w[-not -type d -print]
else
ARGV.kegs.each { |keg| PrettyListing.new keg }
end
when 'search', '-S'
require "formula"
formulae = Formulary.names with_aliases=true
if ARGV.first =~ /^\/(.*)\/$/
puts_columns formulae.grep(Regexp.new($1))
else
puts_columns formulae.grep(/.*#{ARGV.first}.*/)
end
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_REPOSITORY}/Library/*"]<<
"#{HOMEBREW_REPOSITORY}/bin/brew"<<
"#{HOMEBREW_REPOSITORY}/README.md"
else
# we don't use ARGV.formulae as that will throw if the file doesn't parse
paths = ARGV.named.collect do |name|
unless File.exist? path = "#{HOMEBREW_REPOSITORY}/Library/Formula/#{name}.rb"
require 'formula'
raise FormulaUnavailableError, name
else
path
end
end
exec_editor *paths
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[0,8]} to #{updater.current_revision[0,8]}."
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
keg.unlink
end
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}"
elsif ARGV.named.empty?
raise UsageError
else
exec_editor *ARGV.named.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 'install'
require 'formula_installer'
require 'hardware'
############################################################ sanity checks
case Hardware.cpu_type when :ppc, :dunno
abort "Sorry, Homebrew does not support your computer's CPU architecture."
end
raise "Cannot write to #{HOMEBREW_CELLAR}" if HOMEBREW_CELLAR.exist? and not HOMEBREW_CELLAR.writable?
raise "Cannot write to #{HOMEBREW_PREFIX}" unless HOMEBREW_PREFIX.writable?
################################################################# warnings
if MACOS_VERSION >= 10.6
opoo "You should upgrade to Xcode 3.2.1" if llvm_build < 2206
else
opoo "You should upgrade to Xcode 3.1.4" if gcc_build < 5577
end
if macports_or_fink_installed?
opoo "It appears you have Macports or Fink installed"
puts "Although, unlikely, this can break builds or cause obscure runtime issues."
puts "If you experience problems try uninstalling these tools."
end
################################################################# install!
installer = FormulaInstaller.new
installer.install_deps = !ARGV.include?('--ignore-dependencies')
ARGV.formulae.each do |f|
if not f.installed? or ARGV.force?
installer.install f
else
puts "Formula already installed: #{f.prefix}"
end
end
when 'log'
Dir.chdir HOMEBREW_REPOSITORY
exec "git", "log", ARGV.formulae.first.path, *ARGV.options
when 'uses'
# For each formula given, show which other formulas depend on it.
# We only go one level up, direct dependencies.
require 'formula'
require 'utils'
deps = Formula.get_used_by
ARGV.formulae.each do |f|
name = f.name
our_deps = deps[name]
if our_deps == nil
puts "#{name} is not a dependency."
else
puts "#{name} is a dependency for #{our_deps.join(', ')}."
end
end
when 'pull', 'push', 'checkout', 'branch'
onoe "Unknown command: #{arg} (did you mean 'git #{arg}'?)"
else
onoe "Unknown command: #{arg}"
end
rescue FormulaUnspecifiedError
abort "This command requires a formula argument"
rescue KegUnspecifiedError
abort "This command requires a keg argument"
rescue UsageError
onoe "Invalid usage"
abort ARGV.usage
rescue SystemExit
puts "Kernel.exit" if ARGV.verbose?
raise
rescue Interrupt => e
puts # seemingly a newline is typical
exit 130
rescue BuildError => e
ohai "Backtrace"
puts e.backtrace
ohai "Environment"
dump_config
puts "Exit status: #{e.status}"
onoe e
puts PLEASE_REPORT_BUG
exit 1
rescue RuntimeError, SystemCallError => e
onoe e
puts e.backtrace if ARGV.debug?
exit 1
rescue Exception => e
onoe e
puts PLEASE_REPORT_BUG
puts e.backtrace
exit 1
end