2 # //===----------------------------------------------------------------------===//
4 # // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 # // See https://llvm.org/LICENSE.txt for license information.
6 # // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 # //===----------------------------------------------------------------------===//
16 class ScriptError(Exception):
17 """Convenience class for user errors generated"""
19 def __init__(self
, msg
):
20 super(Exception, self
).__init
__(msg
)
24 raise ScriptError(msg
)
27 def print_line(msg
, form
="i"):
28 print("{}: ({}) {}".format(os
.path
.basename(sys
.argv
[0]), form
, msg
))
31 def print_info_line(msg
):
35 def print_error_line(msg
):
36 print_line(msg
, form
="x")
41 Auxiliary class for execute_command() containing the
42 results of running a command
45 def __init__(self
, args
, stdout
, stderr
, returncode
):
46 self
.executable
= args
[0]
47 self
.stdout
= stdout
.decode("utf-8")
48 self
.stderr
= stderr
.decode("utf-8")
49 self
.returncode
= returncode
50 self
.command
= " ".join(args
)
53 def execute_command(args
):
55 Run a command with arguments: args
57 Return RunResult containing stdout, stderr, returncode
59 handle
= subprocess
.Popen(args
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.PIPE
)
60 stdout
, stderr
= handle
.communicate()
61 returncode
= handle
.wait()
62 return RunResult(args
, stdout
, stderr
, returncode
)