[PDNCF] Python 3.12 compatibility
[platform/framework/web/chromium-efl.git] / tools / diagnose-me.py
1 #!/usr/bin/env python3
2 # Copyright 2012 The Chromium Authors
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
9 from __future__ import print_function
10
11 import os
12 import subprocess
13 import sys
14
15 all_checks = []
16
17 def Check(name):
18   """Decorator that defines a diagnostic check."""
19
20   def wrap(func):
21     all_checks.append((name, func))
22     return func
23
24   return wrap
25
26
27 @Check("/usr/bin/ld is not gold")
28 def CheckSystemLd():
29   proc = subprocess.Popen(['/usr/bin/ld', '-v'], stdout=subprocess.PIPE)
30   stdout = proc.communicate()[0].decode('utf-8')
31   if 'GNU gold' in stdout:
32     return ("When /usr/bin/ld is gold, system updates can silently\n"
33             "corrupt your graphics drivers.\n"
34             "Try 'sudo apt-get remove binutils-gold'.\n")
35   return None
36
37
38 @Check("random lds are not in the $PATH")
39 def CheckPathLd():
40   proc = subprocess.Popen(['which', '-a', 'ld'], stdout=subprocess.PIPE)
41   stdout = proc.communicate()[0].decode('utf-8')
42   instances = stdout.split()
43   if len(instances) > 1:
44     return ("You have multiple 'ld' binaries in your $PATH:\n" +
45             '\n'.join(' - ' + i for i in instances) + "\n"
46             "You should delete all of them but your system one.\n"
47             "gold is hooked into your build via depot tools.\n")
48   return None
49
50
51 @Check("/usr/bin/ld doesn't point to gold")
52 def CheckLocalGold():
53   # Check /usr/bin/ld* symlinks.
54   for path in ('ld.bfd', 'ld'):
55     path = '/usr/bin/' + path
56     try:
57       target = os.readlink(path)
58     except OSError as e:
59       if e.errno == 2:
60         continue  # No such file
61       if e.errno == 22:
62         continue  # Not a symlink
63       raise
64     if '/usr/local/gold' in target:
65       return ("%s is a symlink into /usr/local/gold.\n"
66               "It's difficult to make a recommendation, because you\n"
67               "probably set this up yourself.  But you should make\n"
68               "/usr/bin/ld be the standard linker, which you likely\n"
69               "renamed /usr/bin/ld.bfd or something like that.\n" % path)
70
71   return None
72
73
74 @Check("random ninja binaries are not in the $PATH")
75 def CheckPathNinja():
76   proc = subprocess.Popen(['which', 'ninja'], stdout=subprocess.PIPE)
77   stdout = proc.communicate()[0].decode('utf-8')
78   if not 'depot_tools' in stdout:
79     return ("The ninja binary in your path isn't from depot_tools:\n" + "    " +
80             stdout + "Remove custom ninjas from your path so that the one\n"
81             "in depot_tools is used.\n")
82   return None
83
84
85 @Check("build dependencies are satisfied")
86 def CheckBuildDeps():
87   script_path = os.path.join(
88       os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'build',
89       'install-build-deps.sh')
90   proc = subprocess.Popen([script_path, '--quick-check'],
91                           stdout=subprocess.PIPE)
92   stdout = proc.communicate()[0].decode('utf-8')
93   if 'WARNING' in stdout:
94     return ("Your build dependencies are out-of-date.\n"
95             "Run '" + script_path + "' to update.")
96   return None
97
98
99 def RunChecks():
100   for name, check in all_checks:
101     sys.stdout.write("* Checking %s: " % name)
102     sys.stdout.flush()
103     error = check()
104     if not error:
105       print("ok")
106     else:
107       print("FAIL")
108       print(error)
109
110
111 if __name__ == '__main__':
112   RunChecks()