• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#===----------------------------------------------------------------------===##
2#
3#                     The LLVM Compiler Infrastructure
4#
5# This file is dual licensed under the MIT and the University of Illinois Open
6# Source Licenses. See LICENSE.TXT for details.
7#
8#===----------------------------------------------------------------------===##
9
10"""not.py is a utility for inverting the return code of commands.
11It acts similar to llvm/utils/not.
12ex: python /path/to/not.py ' echo hello
13    echo $? // (prints 1)
14"""
15
16import distutils.spawn
17import subprocess
18import sys
19
20
21def main():
22    argv = list(sys.argv)
23    del argv[0]
24    if len(argv) > 0 and argv[0] == '--crash':
25        del argv[0]
26        expectCrash = True
27    else:
28        expectCrash = False
29    if len(argv) == 0:
30        return 1
31    prog = distutils.spawn.find_executable(argv[0])
32    if prog is None:
33        sys.stderr.write('Failed to find program %s' % argv[0])
34        return 1
35    rc = subprocess.call(argv)
36    if rc < 0:
37        return 0 if expectCrash else 1
38    if expectCrash:
39        return 1
40    return rc == 0
41
42
43if __name__ == '__main__':
44    exit(main())
45