Add more checks to investigate SupervisedUserPrefStore crash at startup.
[chromium-blink-merge.git] / native_client_sdk / src / tools / ncval.py
blob84903991c2d5e8ec5628c34666fb61c222f20198
1 #!/usr/bin/env python
2 # Copyright 2013 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.
6 """Wrapper script for running the Native Client validator (ncval).
7 """
9 import argparse
10 import os
11 import subprocess
12 import sys
14 import getos
16 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
17 NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR)
19 if sys.version_info < (2, 7, 0):
20 sys.stderr.write("python 2.7 or later is required run this script\n")
21 sys.exit(1)
23 class Error(Exception):
24 pass
26 def Log(msg):
27 if Log.verbose:
28 sys.stderr.write(str(msg) + '\n')
29 Log.verbose = False
31 def main(args):
32 parser = argparse.ArgumentParser(description=__doc__)
33 parser.add_argument('-v', '--verbose', action='store_true',
34 help='Verbose output')
35 parser.add_argument('nexe', metavar="EXE", help='Executable to validate')
37 # To enable bash completion for this command first install optcomplete
38 # and then add this line to your .bashrc:
39 # complete -F _optcomplete ncval.py
40 try:
41 import optcomplete
42 optcomplete.autocomplete(parser)
43 except ImportError:
44 pass
46 options = parser.parse_args(args)
47 nexe = options.nexe
49 if options.verbose:
50 Log.verbose = True
52 # TODO(binji): http://crbug.com/321791. Fix ncval upstream to reduce the
53 # amount of additional checking done here.
54 osname = getos.GetPlatform()
55 if not os.path.exists(nexe):
56 raise Error('executable not found: %s' % nexe)
57 if not os.path.isfile(nexe):
58 raise Error('not a file: %s' % nexe)
60 ncval = os.path.join(SCRIPT_DIR, 'ncval')
61 if osname == 'win':
62 ncval += '.exe'
64 cmd = [ncval, nexe]
65 Log('Running %s' % ' '.join(cmd))
66 proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
67 proc_out, _ = proc.communicate()
68 if proc.returncode:
69 # ncval doesn't print anything to stderr.
70 sys.stderr.write('Validating %s failed:\n' % nexe)
71 sys.stderr.write(proc_out + '\n')
73 Log('Changing the modification time of %s to 0.' % nexe)
74 # "untouch" the executable; that is, change the modification time to be so
75 # old that it will be remade when `make` runs.
76 statinfo = os.stat(nexe)
77 mtime = 0
78 os.utime(nexe, (statinfo.st_atime, mtime))
80 return proc.returncode
81 elif options.verbose:
82 # By default, don't print anything on success.
83 Log(proc_out)
86 if __name__ == '__main__':
87 try:
88 sys.exit(main(sys.argv[1:]))
89 except Error as e:
90 sys.stderr.write(str(e) + '\n')
91 sys.exit(1)