Dirk Pranke | 4d164bb | 2021-03-24 06:52:40 | [diff] [blame] | 1 | #!/usr/bin/env python |
[email protected] | 4a3ce97 | 2012-02-03 23:12:59 | [diff] [blame] | 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 |
| 7 | suggest fixes.""" |
| 8 | |
Raul Tambre | 48f17662 | 2019-09-23 10:05:24 | [diff] [blame] | 9 | from __future__ import print_function |
| 10 | |
[email protected] | d8333f29 | 2012-02-04 01:00:33 | [diff] [blame] | 11 | import os |
[email protected] | 4a3ce97 | 2012-02-03 23:12:59 | [diff] [blame] | 12 | import subprocess |
| 13 | import sys |
| 14 | |
| 15 | all_checks = [] |
| 16 | |
| 17 | def 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") |
| 26 | def 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") |
| 37 | def 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] | 9074068 | 2012-02-16 16:56:28 | [diff] [blame] | 49 | @Check("/usr/bin/ld doesn't point to gold") |
[email protected] | d8333f29 | 2012-02-04 01:00:33 | [diff] [blame] | 50 | def CheckLocalGold(): |
| 51 | # Check /usr/bin/ld* symlinks. |
[email protected] | 9074068 | 2012-02-16 16:56:28 | [diff] [blame] | 52 | for path in ('ld.bfd', 'ld'): |
[email protected] | d8333f29 | 2012-02-04 01:00:33 | [diff] [blame] | 53 | 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] | 3a07c3a | 2012-02-04 06:24:52 | [diff] [blame] | 67 | "renamed /usr/bin/ld.bfd or something like that.\n" % path) |
[email protected] | d8333f29 | 2012-02-04 01:00:33 | [diff] [blame] | 68 | |
[email protected] | d8333f29 | 2012-02-04 01:00:33 | [diff] [blame] | 69 | return None |
| 70 | |
| 71 | |
[email protected] | 33f7293 | 2012-02-16 17:48:08 | [diff] [blame] | 72 | @Check("random ninja binaries are not in the $PATH") |
| 73 | def 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] | d8333f29 | 2012-02-04 01:00:33 | [diff] [blame] | 83 | |
[email protected] | ba48c4ca | 2013-10-25 16:11:46 | [diff] [blame] | 84 | @Check("build dependencies are satisfied") |
| 85 | def 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] | 4a3ce97 | 2012-02-03 23:12:59 | [diff] [blame] | 98 | def 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 Tambre | 48f17662 | 2019-09-23 10:05:24 | [diff] [blame] | 104 | print("ok") |
[email protected] | 4a3ce97 | 2012-02-03 23:12:59 | [diff] [blame] | 105 | else: |
Raul Tambre | 48f17662 | 2019-09-23 10:05:24 | [diff] [blame] | 106 | print("FAIL") |
| 107 | print(error) |
[email protected] | 4a3ce97 | 2012-02-03 23:12:59 | [diff] [blame] | 108 | |
| 109 | |
| 110 | if __name__ == '__main__': |
| 111 | RunChecks() |