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).
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")
23 class Error(Exception):
28 sys
.stderr
.write(str(msg
) + '\n')
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
42 optcomplete
.autocomplete(parser
)
46 options
= parser
.parse_args(args
)
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')
65 Log('Running %s' % ' '.join(cmd
))
66 proc
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
67 proc_out
, _
= proc
.communicate()
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
)
78 os
.utime(nexe
, (statinfo
.st_atime
, mtime
))
80 return proc
.returncode
82 # By default, don't print anything on success.
86 if __name__
== '__main__':
88 sys
.exit(main(sys
.argv
[1:]))
90 sys
.stderr
.write(str(e
) + '\n')