blob: 2ebf5088d5160157c9bec14dd0e8615310f3289e [file] [log] [blame]
Eric Fiselier120ec472016-01-19 21:58:49 +00001#===----------------------------------------------------------------------===##
2#
Chandler Carruthd2012102019-01-19 10:56:40 +00003# 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 Fiselier120ec472016-01-19 21:58:49 +00006#
7#===----------------------------------------------------------------------===##
8
Eric Fiselier7ca90ed2015-01-22 18:05:58 +00009"""not.py is a utility for inverting the return code of commands.
10It acts similar to llvm/utils/not.
11ex: python /path/to/not.py ' echo hello
12 echo $? // (prints 1)
13"""
14
15import distutils.spawn
16import subprocess
17import sys
18
19
20def 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
42if __name__ == '__main__':
43 exit(main())