[tools] Clean up Py2 code
Bug: chromium:1292013 Change-Id: I8202fed4d59edcc98fff193f3a4b102a5c79d553 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3525136 Reviewed-by: Liviu Rau <liviurau@chromium.org> Reviewed-by: Tamer Tas <tmrts@chromium.org> Commit-Queue: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/main@{#79505}
This commit is contained in:
parent
67044edf08
commit
2c4133a0ce
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2014 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
@ -7,21 +7,16 @@
|
||||
"""This program either generates the parser files for Torque, generating
|
||||
the source and header files directly in V8's src directory."""
|
||||
|
||||
# for py2/py3 compatibility
|
||||
from __future__ import print_function
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import re
|
||||
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"):
|
||||
return arg.encode(encoding) if PYTHON3 else arg
|
||||
def encode(arg, encoding="utf-8"):
|
||||
return arg.encode(encoding)
|
||||
|
||||
kPercentEscape = r'α'; # Unicode alpha
|
||||
kDerefEscape = r'☆'; # Unicode star
|
||||
@ -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)
|
||||
else:
|
||||
p = Popen(['clang-format', '-assume-filename=.ts'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||
output, err = p.communicate(maybe_encode(preprocess(content)))
|
||||
output = postprocess(maybe_decode(output))
|
||||
output, err = p.communicate(encode(preprocess(content)))
|
||||
output = postprocess(decode(output))
|
||||
rc = p.returncode
|
||||
if (rc != 0):
|
||||
print("error code " + str(rc) + " running clang-format. Exiting...")
|
||||
@ -124,7 +119,7 @@ def process(filename, lint, should_format):
|
||||
|
||||
if should_format:
|
||||
output_file = open(filename, 'wb')
|
||||
output_file.write(maybe_encode(output))
|
||||
output_file.write(encode(output))
|
||||
output_file.close()
|
||||
|
||||
def print_usage():
|
||||
|
Loading…
Reference in New Issue
Block a user