blob: 16f1f8fdf13f740441c2755aaca17201c1fdccb9 [file] [log] [blame]
[email protected]4a3ce972012-02-03 23:12:591#!/usr/bin/python
2# Copyright (c) 2012 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""Diagnose some common system configuration problems on Linux, and
7suggest fixes."""
8
[email protected]d8333f292012-02-04 01:00:339import os
[email protected]4a3ce972012-02-03 23:12:5910import subprocess
11import sys
12
13all_checks = []
14
15def Check(name):
16 """Decorator that defines a diagnostic check."""
17 def wrap(func):
18 all_checks.append((name, func))
19 return func
20 return wrap
21
22
23@Check("/usr/bin/ld is not gold")
24def CheckSystemLd():
25 proc = subprocess.Popen(['/usr/bin/ld', '-v'], stdout=subprocess.PIPE)
26 stdout = proc.communicate()[0]
27 if 'GNU gold' in stdout:
28 return ("When /usr/bin/ld is gold, system updates can silently\n"
29 "corrupt your graphics drivers.\n"
30 "Try 'sudo apt-get remove binutils-gold'.\n")
31 return None
32
33
34@Check("random lds are not in the $PATH")
35def CheckPathLd():
36 proc = subprocess.Popen(['which', '-a', 'ld'], stdout=subprocess.PIPE)
37 stdout = proc.communicate()[0]
38 instances = stdout.split()
39 if len(instances) > 1:
40 return ("You have multiple 'ld' binaries in your $PATH:\n"
41 + '\n'.join(' - ' + i for i in instances) + "\n"
42 "You should delete all of them but your system one.\n"
43 "gold is hooked into your build via gyp.\n")
44 return None
45
46
[email protected]90740682012-02-16 16:56:2847@Check("/usr/bin/ld doesn't point to gold")
[email protected]d8333f292012-02-04 01:00:3348def CheckLocalGold():
49 # Check /usr/bin/ld* symlinks.
[email protected]90740682012-02-16 16:56:2850 for path in ('ld.bfd', 'ld'):
[email protected]d8333f292012-02-04 01:00:3351 path = '/usr/bin/' + path
52 try:
53 target = os.readlink(path)
54 except OSError, e:
55 if e.errno == 2:
56 continue # No such file
57 if e.errno == 22:
58 continue # Not a symlink
59 raise
60 if '/usr/local/gold' in target:
61 return ("%s is a symlink into /usr/local/gold.\n"
62 "It's difficult to make a recommendation, because you\n"
63 "probably set this up yourself. But you should make\n"
64 "/usr/bin/ld be the standard linker, which you likely\n"
[email protected]3a07c3a2012-02-04 06:24:5265 "renamed /usr/bin/ld.bfd or something like that.\n" % path)
[email protected]d8333f292012-02-04 01:00:3366
[email protected]d8333f292012-02-04 01:00:3367 return None
68
69
70
[email protected]4a3ce972012-02-03 23:12:5971def RunChecks():
72 for name, check in all_checks:
73 sys.stdout.write("* Checking %s: " % name)
74 sys.stdout.flush()
75 error = check()
76 if not error:
77 print "ok"
78 else:
79 print "FAIL"
80 print error
81
82
83if __name__ == '__main__':
84 RunChecks()