Eric Fiselier | 120ec47 | 2016-01-19 21:58:49 +0000 | [diff] [blame] | 1 | #===----------------------------------------------------------------------===## |
| 2 | # |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame^] | 3 | # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | # See https://llvm.org/LICENSE.txt for license information. |
| 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Eric Fiselier | 120ec47 | 2016-01-19 21:58:49 +0000 | [diff] [blame] | 6 | # |
| 7 | #===----------------------------------------------------------------------===## |
| 8 | |
Eric Fiselier | 7ca90ed | 2015-01-22 18:05:58 +0000 | [diff] [blame] | 9 | """not.py is a utility for inverting the return code of commands. |
| 10 | It acts similar to llvm/utils/not. |
| 11 | ex: python /path/to/not.py ' echo hello |
| 12 | echo $? // (prints 1) |
| 13 | """ |
| 14 | |
| 15 | import distutils.spawn |
| 16 | import subprocess |
| 17 | import sys |
| 18 | |
| 19 | |
| 20 | def main(): |
| 21 | argv = list(sys.argv) |
| 22 | del argv[0] |
| 23 | if len(argv) > 0 and argv[0] == '--crash': |
| 24 | del argv[0] |
| 25 | expectCrash = True |
| 26 | else: |
| 27 | expectCrash = False |
| 28 | if len(argv) == 0: |
| 29 | return 1 |
| 30 | prog = distutils.spawn.find_executable(argv[0]) |
| 31 | if prog is None: |
| 32 | sys.stderr.write('Failed to find program %s' % argv[0]) |
| 33 | return 1 |
| 34 | rc = subprocess.call(argv) |
| 35 | if rc < 0: |
| 36 | return 0 if expectCrash else 1 |
| 37 | if expectCrash: |
| 38 | return 1 |
| 39 | return rc == 0 |
| 40 | |
| 41 | |
| 42 | if __name__ == '__main__': |
| 43 | exit(main()) |