blob: 06051f53d5f0f2d43b94c0726c99bf708a3c77e4 [file] [log] [blame]
Dirk Pranke4d164bb2021-03-24 06:52:401#!/usr/bin/env python
[email protected]4a3ce972012-02-03 23:12:592# 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
Raul Tambre48f176622019-09-23 10:05:249from __future__ import print_function
10
[email protected]d8333f292012-02-04 01:00:3311import os
[email protected]4a3ce972012-02-03 23:12:5912import subprocess
13import sys
14
15all_checks = []
16
17def Check(name):
18 """Decorator that defines a diagnostic check."""
19 def wrap(func):
20 all_checks.append((name, func))
21 return func
22 return wrap
23
24
25@Check("/usr/bin/ld is not gold")
26def CheckSystemLd():
27 proc = subprocess.Popen(['/usr/bin/ld', '-v'], stdout=subprocess.PIPE)
28 stdout = proc.communicate()[0]
29 if 'GNU gold' in stdout:
30 return ("When /usr/bin/ld is gold, system updates can silently\n"
31 "corrupt your graphics drivers.\n"
32 "Try 'sudo apt-get remove binutils-gold'.\n")
33 return None
34
35
36@Check("random lds are not in the $PATH")
37def CheckPathLd():
38 proc = subprocess.Popen(['which', '-a', 'ld'], stdout=subprocess.PIPE)
39 stdout = proc.communicate()[0]
40 instances = stdout.split()
41 if len(instances) > 1:
42 return ("You have multiple 'ld' binaries in your $PATH:\n"
43 + '\n'.join(' - ' + i for i in instances) + "\n"
44 "You should delete all of them but your system one.\n"
45 "gold is hooked into your build via gyp.\n")
46 return None
47
48
[email protected]90740682012-02-16 16:56:2849@Check("/usr/bin/ld doesn't point to gold")
[email protected]d8333f292012-02-04 01:00:3350def CheckLocalGold():
51 # Check /usr/bin/ld* symlinks.
[email protected]90740682012-02-16 16:56:2852 for path in ('ld.bfd', 'ld'):
[email protected]d8333f292012-02-04 01:00:3353 path = '/usr/bin/' + path
54 try:
55 target = os.readlink(path)
56 except OSError, e:
57 if e.errno == 2:
58 continue # No such file
59 if e.errno == 22:
60 continue # Not a symlink
61 raise
62 if '/usr/local/gold' in target:
63 return ("%s is a symlink into /usr/local/gold.\n"
64 "It's difficult to make a recommendation, because you\n"
65 "probably set this up yourself. But you should make\n"
66 "/usr/bin/ld be the standard linker, which you likely\n"
[email protected]3a07c3a2012-02-04 06:24:5267 "renamed /usr/bin/ld.bfd or something like that.\n" % path)
[email protected]d8333f292012-02-04 01:00:3368
[email protected]d8333f292012-02-04 01:00:3369 return None
70
71
[email protected]33f72932012-02-16 17:48:0872@Check("random ninja binaries are not in the $PATH")
73def CheckPathNinja():
74 proc = subprocess.Popen(['which', 'ninja'], stdout=subprocess.PIPE)
75 stdout = proc.communicate()[0]
76 if not 'depot_tools' in stdout:
77 return ("The ninja binary in your path isn't from depot_tools:\n"
78 + " " + stdout +
79 "Remove custom ninjas from your path so that the one\n"
80 "in depot_tools is used.\n")
81 return None
82
[email protected]d8333f292012-02-04 01:00:3383
[email protected]ba48c4ca2013-10-25 16:11:4684@Check("build dependencies are satisfied")
85def CheckBuildDeps():
86 script_path = os.path.join(
87 os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'build',
88 'install-build-deps.sh')
89 proc = subprocess.Popen([script_path, '--quick-check'],
90 stdout=subprocess.PIPE)
91 stdout = proc.communicate()[0]
92 if 'WARNING' in stdout:
93 return ("Your build dependencies are out-of-date.\n"
94 "Run '" + script_path + "' to update.")
95 return None
96
97
[email protected]4a3ce972012-02-03 23:12:5998def RunChecks():
99 for name, check in all_checks:
100 sys.stdout.write("* Checking %s: " % name)
101 sys.stdout.flush()
102 error = check()
103 if not error:
Raul Tambre48f176622019-09-23 10:05:24104 print("ok")
[email protected]4a3ce972012-02-03 23:12:59105 else:
Raul Tambre48f176622019-09-23 10:05:24106 print("FAIL")
107 print(error)
[email protected]4a3ce972012-02-03 23:12:59108
109
110if __name__ == '__main__':
111 RunChecks()