Commit 2c4133a0 authored by Michael Achenbach's avatar Michael Achenbach Committed by V8 LUCI CQ

[tools] Clean up Py2 code

Bug: chromium:1292013
Change-Id: I8202fed4d59edcc98fff193f3a4b102a5c79d553
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3525136Reviewed-by: 's avatarLiviu Rau <liviurau@chromium.org>
Reviewed-by: 's avatarTamer Tas <tmrts@chromium.org>
Commit-Queue: Michael Achenbach <machenbach@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79505}
parent 67044edf
#!/usr/bin/env python #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2014 the V8 project authors. All rights reserved. # Copyright 2014 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
...@@ -7,21 +7,16 @@ ...@@ -7,21 +7,16 @@
"""This program either generates the parser files for Torque, generating """This program either generates the parser files for Torque, generating
the source and header files directly in V8's src directory.""" the source and header files directly in V8's src directory."""
# for py2/py3 compatibility
from __future__ import print_function
import subprocess import subprocess
import sys import sys
import re import re
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
PYTHON3 = sys.version_info >= (3, 0) def decode(arg, encoding="utf-8"):
return arg.decode(encoding)
def maybe_decode(arg, encoding="utf-8"):
return arg.decode(encoding) if PYTHON3 else arg
def maybe_encode(arg, encoding="utf-8"): def encode(arg, encoding="utf-8"):
return arg.encode(encoding) if PYTHON3 else arg return arg.encode(encoding)
kPercentEscape = r'α'; # Unicode alpha kPercentEscape = r'α'; # Unicode alpha
kDerefEscape = r'☆'; # Unicode star kDerefEscape = r'☆'; # Unicode star
...@@ -111,8 +106,8 @@ def process(filename, lint, should_format): ...@@ -111,8 +106,8 @@ def process(filename, lint, should_format):
p = Popen(['clang-format', '-assume-filename=.ts'], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True) p = Popen(['clang-format', '-assume-filename=.ts'], stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
else: else:
p = Popen(['clang-format', '-assume-filename=.ts'], stdin=PIPE, stdout=PIPE, stderr=PIPE) p = Popen(['clang-format', '-assume-filename=.ts'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = p.communicate(maybe_encode(preprocess(content))) output, err = p.communicate(encode(preprocess(content)))
output = postprocess(maybe_decode(output)) output = postprocess(decode(output))
rc = p.returncode rc = p.returncode
if (rc != 0): if (rc != 0):
print("error code " + str(rc) + " running clang-format. Exiting...") print("error code " + str(rc) + " running clang-format. Exiting...")
...@@ -124,7 +119,7 @@ def process(filename, lint, should_format): ...@@ -124,7 +119,7 @@ def process(filename, lint, should_format):
if should_format: if should_format:
output_file = open(filename, 'wb') output_file = open(filename, 'wb')
output_file.write(maybe_encode(output)) output_file.write(encode(output))
output_file.close() output_file.close()
def print_usage(): def print_usage():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment