Don't wrap stdout and stderr in UTF-8 wrapper

This is no longer needed as we only print ASCII text directly

Signed-off-by: David Horstmann <david.horstmann@arm.com>
This commit is contained in:
David Horstmann 2023-01-24 18:36:41 +00:00
parent ce42cc24d1
commit 6b3ce309ad

View file

@ -18,7 +18,6 @@ This script must be run from the root of a Git work tree containing Mbed TLS.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import argparse import argparse
import io
import os import os
import re import re
import subprocess import subprocess
@ -29,12 +28,10 @@ UNCRUSTIFY_SUPPORTED_VERSION = "0.75.1"
CONFIG_FILE = ".uncrustify.cfg" CONFIG_FILE = ".uncrustify.cfg"
UNCRUSTIFY_EXE = "uncrustify" UNCRUSTIFY_EXE = "uncrustify"
UNCRUSTIFY_ARGS = ["-c", CONFIG_FILE] UNCRUSTIFY_ARGS = ["-c", CONFIG_FILE]
STDOUT_UTF8 = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
STDERR_UTF8 = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8')
CHECK_GENERATED_FILES = "tests/scripts/check-generated-files.sh" CHECK_GENERATED_FILES = "tests/scripts/check-generated-files.sh"
def print_err(*args): def print_err(*args):
print("Error: ", *args, file=STDERR_UTF8) print("Error: ", *args, file=sys.stderr)
# Match FILENAME(s) in "check SCRIPT (FILENAME...)" # Match FILENAME(s) in "check SCRIPT (FILENAME...)"
CHECK_CALL_RE = re.compile(r"\n\s*check\s+[^\s#$&*?;|]+([^\n#$&*?;|]+)", CHECK_CALL_RE = re.compile(r"\n\s*check\s+[^\s#$&*?;|]+([^\n#$&*?;|]+)",
@ -67,8 +64,8 @@ def get_src_files() -> List[str]:
"tests/suites/*.function", "tests/suites/*.function",
"scripts/data_files/*.fmt"] "scripts/data_files/*.fmt"]
result = subprocess.run(git_ls_files_cmd, stdout=subprocess.PIPE, \ result = subprocess.run(git_ls_files_cmd, stdout=subprocess.PIPE,
stderr=STDERR_UTF8, check=False) check=False)
if result.returncode != 0: if result.returncode != 0:
print_err("git ls-files returned: " + str(result.returncode)) print_err("git ls-files returned: " + str(result.returncode))
@ -118,7 +115,7 @@ def check_style_is_correct(src_file_list: List[str]) -> bool:
cp = subprocess.run(diff_cmd, check=False) cp = subprocess.run(diff_cmd, check=False)
if cp.returncode == 1: if cp.returncode == 1:
print(src_file + " changed - code style is incorrect.", file=STDOUT_UTF8) print(src_file + " changed - code style is incorrect.")
style_correct = False style_correct = False
elif cp.returncode != 0: elif cp.returncode != 0:
raise subprocess.CalledProcessError(cp.returncode, cp.args, raise subprocess.CalledProcessError(cp.returncode, cp.args,
@ -136,8 +133,7 @@ def fix_style_single_pass(src_file_list: List[str]) -> bool:
code_change_args = UNCRUSTIFY_ARGS + ["--no-backup"] code_change_args = UNCRUSTIFY_ARGS + ["--no-backup"]
for src_file in src_file_list: for src_file in src_file_list:
uncrustify_cmd = [UNCRUSTIFY_EXE] + code_change_args + [src_file] uncrustify_cmd = [UNCRUSTIFY_EXE] + code_change_args + [src_file]
result = subprocess.run(uncrustify_cmd, check=False, \ result = subprocess.run(uncrustify_cmd, check=False)
stdout=STDOUT_UTF8, stderr=STDERR_UTF8)
if result.returncode != 0: if result.returncode != 0:
print_err("Uncrustify with file returned: " + \ print_err("Uncrustify with file returned: " + \
str(result.returncode) + " correcting file " + \ str(result.returncode) + " correcting file " + \
@ -169,9 +165,9 @@ def main() -> int:
uncrustify_version = get_uncrustify_version().strip() uncrustify_version = get_uncrustify_version().strip()
if UNCRUSTIFY_SUPPORTED_VERSION not in uncrustify_version: if UNCRUSTIFY_SUPPORTED_VERSION not in uncrustify_version:
print("Warning: Using unsupported Uncrustify version '" + print("Warning: Using unsupported Uncrustify version '" +
uncrustify_version + "'", file=STDOUT_UTF8) uncrustify_version + "'")
print("Note: The only supported version is " + print("Note: The only supported version is " +
UNCRUSTIFY_SUPPORTED_VERSION, file=STDOUT_UTF8) UNCRUSTIFY_SUPPORTED_VERSION)
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-f', '--fix', action='store_true', parser.add_argument('-f', '--fix', action='store_true',
@ -200,8 +196,7 @@ def main() -> int:
else: else:
# Check mode # Check mode
if check_style_is_correct(src_files): if check_style_is_correct(src_files):
print("Checked {} files, style ok.".format(len(src_files)), print("Checked {} files, style ok.".format(len(src_files)))
file=STDOUT_UTF8)
return 0 return 0
else: else:
return 1 return 1