Eric Fiselier | a9e91f3 | 2016-01-19 21:58:49 +0000 | [diff] [blame] | 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 | |
Eric Fiselier | dd7a483 | 2015-01-22 18:05:58 +0000 | [diff] [blame] | 10 | """not.py is a utility for inverting the return code of commands. |
| 11 | It acts similar to llvm/utils/not. |
| 12 | ex: python /path/to/not.py ' echo hello |
| 13 | echo $? // (prints 1) |
| 14 | """ |
| 15 | |
| 16 | import distutils.spawn |
| 17 | import subprocess |
| 18 | import sys |
| 19 | |
| 20 | |
| 21 | def 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 | |
| 43 | if __name__ == '__main__': |
| 44 | exit(main()) |