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 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, 6, 0):
20 sys
.stderr
.write("python 2.6 or later is required run this script\n")
23 class Error(Exception):
28 sys
.stderr
.write(str(msg
) + '\n')
32 usage
= 'Usage: %prog [options] <.nexe | .so>'
33 epilog
= 'Example: ncval.py my_nexe.nexe'
34 parser
= optparse
.OptionParser(usage
, description
=__doc__
, epilog
=epilog
)
35 parser
.add_option('-v', '--verbose', action
='store_true',
36 help='Verbose output')
38 # To enable bash completion for this command first install optcomplete
39 # and then add this line to your .bashrc:
40 # complete -F _optcomplete ncval.py
43 optcomplete
.autocomplete(parser
)
47 options
, args
= parser
.parse_args(argv
)
49 parser
.error('No executable file specified')
55 # TODO(binji): http://crbug.com/321791. Fix ncval upstream to reduce the
56 # amount of additional checking done here.
57 osname
= getos
.GetPlatform()
58 if not os
.path
.exists(nexe
):
59 raise Error('executable not found: %s' % nexe
)
60 if not os
.path
.isfile(nexe
):
61 raise Error('not a file: %s' % nexe
)
63 ncval
= os
.path
.join(SCRIPT_DIR
, 'ncval')
68 Log('Running %s' % ' '.join(cmd
))
69 proc
= subprocess
.Popen(cmd
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
70 proc_out
, _
= proc
.communicate()
72 # ncval doesn't print anything to stderr.
73 sys
.stderr
.write('Validating %s failed:\n' % nexe
)
74 sys
.stderr
.write(proc_out
+ '\n')
76 Log('Changing the modification time of %s to 0.' % nexe
)
77 # "untouch" the executable; that is, change the modification time to be so
78 # old that it will be remade when `make` runs.
79 statinfo
= os
.stat(nexe
)
81 os
.utime(nexe
, (statinfo
.st_atime
, mtime
))
83 return proc
.returncode
85 # By default, don't print anything on success.
89 if __name__
== '__main__':
91 sys
.exit(main(sys
.argv
[1:]))
93 sys
.stderr
.write(str(e
) + '\n')