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

Revert "[tools] Clean up py2 code"

This reverts commit 1289704a.

Reason for revert:
https://ci.chromium.org/ui/p/v8/builders/ci/V8%20Mac%20-%20arm64%20-%20release/8735/overview

Original change's description:
> [tools] Clean up py2 code
>
> Bug: chromium:1292013
> Change-Id: Ic2c3a197005a2136bb0eda4cbb36d8eb57f42a7c
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3523047
> Reviewed-by: Liviu Rau <liviurau@chromium.org>
> Commit-Queue: Michael Achenbach <machenbach@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#79507}

Bug: chromium:1292013
Change-Id: I48c38209220b775d0caa45f487ed163f78333e0c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3532228
Auto-Submit: Michael Achenbach <machenbach@chromium.org>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#79508}
parent 1289704a
...@@ -9,6 +9,5 @@ USE_PYTHON3 = True ...@@ -9,6 +9,5 @@ USE_PYTHON3 = True
def CheckChangeOnCommit(input_api, output_api): def CheckChangeOnCommit(input_api, output_api):
tests = input_api.canned_checks.GetUnitTestsInDirectory( tests = input_api.canned_checks.GetUnitTestsInDirectory(
input_api, output_api, 'unittests', files_to_check=[r'.+_test\.py$'], input_api, output_api, 'unittests', files_to_check=[r'.+_test\.py$'])
run_on_python2=False)
return input_api.RunTests(tests) return input_api.RunTests(tests)
...@@ -14,7 +14,6 @@ def _CommonChecks(input_api, output_api): ...@@ -14,7 +14,6 @@ def _CommonChecks(input_api, output_api):
input_api.os_path.join(input_api.PresubmitLocalPath()), input_api.os_path.join(input_api.PresubmitLocalPath()),
files_to_check=[r'.+_unittest\.py$'], files_to_check=[r'.+_unittest\.py$'],
files_to_skip=[], files_to_skip=[],
run_on_python2=False,
)) ))
def CheckChangeOnUpload(input_api, output_api): def CheckChangeOnUpload(input_api, output_api):
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# 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
# found in the LICENSE file. # found in the LICENSE file.
# for py2/py3 compatibility
from __future__ import print_function
from functools import reduce from functools import reduce
from collections import OrderedDict, namedtuple from collections import OrderedDict, namedtuple
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
# 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
# found in the LICENSE file. # found in the LICENSE file.
# for py2/py3 compatibility
from __future__ import print_function
from contextlib import contextmanager from contextlib import contextmanager
import os import os
import re import re
...@@ -16,6 +19,8 @@ from ..local.android import ( ...@@ -16,6 +19,8 @@ from ..local.android import (
from ..local import utils from ..local import utils
from ..objects import output from ..objects import output
PYTHON3 = sys.version_info >= (3, 0)
BASE_DIR = os.path.normpath( BASE_DIR = os.path.normpath(
os.path.join(os.path.dirname(os.path.abspath(__file__)), '..' , '..', '..')) os.path.join(os.path.dirname(os.path.abspath(__file__)), '..' , '..', '..'))
...@@ -110,11 +115,17 @@ class BaseCommand(object): ...@@ -110,11 +115,17 @@ class BaseCommand(object):
timer.cancel() timer.cancel()
def convert(stream):
if PYTHON3:
return stream.decode('utf-8', 'replace')
else:
return stream.decode('utf-8', 'replace').encode('utf-8')
return output.Output( return output.Output(
process.returncode, process.returncode,
timeout_occured[0], timeout_occured[0],
stdout.decode('utf-8', 'replace'), convert(stdout),
stderr.decode('utf-8', 'replace'), convert(stderr),
process.pid, process.pid,
duration duration
) )
......
#!/usr/bin/env python3 #!/usr/bin/env python
# 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
# found in the LICENSE file. # found in the LICENSE file.
# for py2/py3 compatibility
from __future__ import print_function
from contextlib import contextmanager from contextlib import contextmanager
from multiprocessing import Process, Queue from multiprocessing import Process, Queue
import os import os
......
#!/usr/bin/env python3 #!/usr/bin/env python
# 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
# found in the LICENSE file. # found in the LICENSE file.
...@@ -28,7 +28,7 @@ class PoolTest(unittest.TestCase): ...@@ -28,7 +28,7 @@ class PoolTest(unittest.TestCase):
# Any result can be a heartbeat due to timings. # Any result can be a heartbeat due to timings.
continue continue
results.add(result.value) results.add(result.value)
self.assertEqual(set(range(0, 10)), results) self.assertEquals(set(range(0, 10)), results)
def testException(self): def testException(self):
results = set() results = set()
...@@ -42,7 +42,7 @@ class PoolTest(unittest.TestCase): ...@@ -42,7 +42,7 @@ class PoolTest(unittest.TestCase):
results.add(result.value) results.add(result.value)
expect = set(range(0, 12)) expect = set(range(0, 12))
expect.remove(10) expect.remove(10)
self.assertEqual(expect, results) self.assertEquals(expect, results)
def testAdd(self): def testAdd(self):
results = set() results = set()
...@@ -54,8 +54,7 @@ class PoolTest(unittest.TestCase): ...@@ -54,8 +54,7 @@ class PoolTest(unittest.TestCase):
results.add(result.value) results.add(result.value)
if result.value < 30: if result.value < 30:
pool.add([result.value + 20]) pool.add([result.value + 20])
self.assertEqual( self.assertEquals(set(range(0, 10) + range(20, 30) + range(40, 50)),
set(range(0, 10)) | set(range(20, 30)) | set(range(40, 50)),
results) results)
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# for py2/py3 compatibility
from __future__ import print_function
from __future__ import absolute_import
import os import os
import re import re
......
#!/usr/bin/env python3 #!/usr/bin/env python
# Copyright 2016 the V8 project authors. All rights reserved. # Copyright 2016 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
# found in the LICENSE file. # found in the LICENSE file.
from __future__ import absolute_import
import os import os
import sys import sys
import unittest import unittest
......
#!/usr/bin/env python3 #!/usr/bin/env python
# Copyright 2016 the V8 project authors. All rights reserved. # Copyright 2016 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
# found in the LICENSE file. # found in the LICENSE file.
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# for py2/py3 compatibility
from __future__ import print_function
from os.path import exists from os.path import exists
from os.path import isdir from os.path import isdir
from os.path import join from os.path import join
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# for py2/py3 compatibility
from __future__ import print_function
import sys import sys
import time import time
......
#!/usr/bin/env python3 #!/usr/bin/env python
# #
# Copyright 2017 the V8 project authors. All rights reserved. # Copyright 2017 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
# found in the LICENSE file. # found in the LICENSE file.
# for py2/py3 compatibility
from __future__ import absolute_import
from __future__ import print_function
import random import random
import sys import sys
......
...@@ -2,7 +2,12 @@ ...@@ -2,7 +2,12 @@
# 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
# found in the LICENSE file. # found in the LICENSE file.
from itertools import zip_longest try: # Python3
from itertools import zip_longest
PYTHON3 = True
except ImportError: # Python2
from itertools import izip_longest as zip_longest
PYTHON3 = False
from ..testproc.base import ( from ..testproc.base import (
DROP_RESULT, DROP_OUTPUT, DROP_PASS_OUTPUT, DROP_PASS_STDOUT) DROP_RESULT, DROP_OUTPUT, DROP_PASS_OUTPUT, DROP_PASS_STDOUT)
...@@ -142,7 +147,9 @@ class ExpectedOutProc(OutProc): ...@@ -142,7 +147,9 @@ class ExpectedOutProc(OutProc):
if output.exit_code != 0: if output.exit_code != 0:
return True return True
with open(self._expected_filename, 'r', encoding='utf-8') as f: # TODO(https://crbug.com/1292013): Simplify after Python3 migration.
kwargs = {'encoding': 'utf-8'} if PYTHON3 else {}
with open(self._expected_filename, 'r', **kwargs) as f:
expected_lines = f.readlines() expected_lines = f.readlines()
for act_iterator in self._act_block_iterator(output): for act_iterator in self._act_block_iterator(output):
......
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
import os import os
import re import re
from itertools import zip_longest try: # Python3
from itertools import zip_longest
except ImportError: # Python2
from itertools import izip_longest as zip_longest
from . import base from . import base
......
#!/usr/bin/env python3 #!/usr/bin/env python
# #
# Copyright 2017 the V8 project authors. All rights reserved. # Copyright 2017 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
# found in the LICENSE file. # found in the LICENSE file.
# for py2/py3 compatibility
from __future__ import absolute_import
from __future__ import print_function
from functools import reduce from functools import reduce
import datetime import datetime
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
# 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
# found in the LICENSE file. # found in the LICENSE file.
# for py2/py3 compatibility
from __future__ import print_function
from collections import defaultdict from collections import defaultdict
import time import time
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
# 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
# found in the LICENSE file. # found in the LICENSE file.
# for py2/py3 compatibility
from __future__ import print_function
from __future__ import absolute_import
import datetime import datetime
import json import json
import os import os
......
#!/usr/bin/env python3 #!/usr/bin/env python
# Copyright 2021 the V8 project authors. All rights reserved. # Copyright 2021 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
# found in the LICENSE file. # found in the LICENSE file.
...@@ -87,8 +87,7 @@ class TestSequenceProc(unittest.TestCase): ...@@ -87,8 +87,7 @@ class TestSequenceProc(unittest.TestCase):
self.assertEqual(set(test.n for test in tests), results.tests) self.assertEqual(set(test.n for test in tests), results.tests)
def test_wrong_usage(self): def test_wrong_usage(self):
with self.assertRaises(Exception): self.assertRaises(lambda: SequenceProc(0))
SequenceProc(0)
def test_no_tests(self): def test_no_tests(self):
self._test([], 1, 1) self._test([], 1, 1)
......
#!/usr/bin/env python3 #!/usr/bin/env python
# Copyright 2019 the V8 project authors. All rights reserved. # Copyright 2019 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
# found in the LICENSE file. # found in the LICENSE file.
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
# 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
# found in the LICENSE file. # found in the LICENSE file.
# for py2/py3 compatibility
from __future__ import print_function
import signal import signal
from . import base from . import base
......
from __future__ import print_function
# Copyright 2018 the V8 project authors. All rights reserved. # Copyright 2018 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
# found in the LICENSE file. # found in the LICENSE file.
......
#!/usr/bin/env python3 #!/usr/bin/env python
# Copyright 2020 the V8 project authors. All rights reserved. # Copyright 2020 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
# found in the LICENSE file. # found in the LICENSE file.
......
#!/usr/bin/env python3 #!/usr/bin/env python
# Copyright 2020 the V8 project authors. All rights reserved. # Copyright 2020 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
# found in the LICENSE file. # found in the LICENSE file.
from __future__ import absolute_import
import os import os
import sys import sys
import unittest import unittest
......
#!/usr/bin/env python3 #!/usr/bin/env python
# Copyright 2019 the V8 project authors. All rights reserved. # Copyright 2019 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
# found in the LICENSE file. # found in the LICENSE file.
......
...@@ -11,6 +11,9 @@ Raw gyp values are supported - they will be tranformed into valid json. ...@@ -11,6 +11,9 @@ Raw gyp values are supported - they will be tranformed into valid json.
""" """
# TODO(machenbach): Remove this when gyp is deprecated. # TODO(machenbach): Remove this when gyp is deprecated.
# for py2/py3 compatibility
from __future__ import print_function
import json import json
import os import os
import sys import sys
......
#!/usr/bin/env python3 #!/usr/bin/env python
# Copyright 2017 the V8 project authors. All rights reserved. # Copyright 2017 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
# found in the LICENSE file. # found in the LICENSE file.
...@@ -17,6 +17,9 @@ with different test suite extensions and build configurations. ...@@ -17,6 +17,9 @@ with different test suite extensions and build configurations.
# TODO(machenbach): Coverage data from multiprocessing doesn't work. # TODO(machenbach): Coverage data from multiprocessing doesn't work.
# TODO(majeski): Add some tests for the fuzzers. # TODO(majeski): Add some tests for the fuzzers.
# for py2/py3 compatibility
from __future__ import print_function
import collections import collections
import contextlib import contextlib
import json import json
...@@ -27,7 +30,11 @@ import sys ...@@ -27,7 +30,11 @@ import sys
import tempfile import tempfile
import unittest import unittest
from io import StringIO # TODO(https://crbug.com/1292016): Remove after Python3 migration.
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) TOOLS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEST_DATA_ROOT = os.path.join(TOOLS_ROOT, 'unittests', 'testdata') TEST_DATA_ROOT = os.path.join(TOOLS_ROOT, 'unittests', 'testdata')
......
#!/usr/bin/env python3 #!/usr/bin/env python
# #
# Copyright 2012 the V8 project authors. All rights reserved. # Copyright 2012 the V8 project authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
...@@ -27,8 +27,17 @@ ...@@ -27,8 +27,17 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import hashlib
md5er = hashlib.md5 # for py2/py3 compatibility
from __future__ import absolute_import
from __future__ import print_function
try:
import hashlib
md5er = hashlib.md5
except ImportError as e:
import md5
md5er = md5.new
import json import json
...@@ -46,11 +55,13 @@ from testrunner.local import statusfile ...@@ -46,11 +55,13 @@ from testrunner.local import statusfile
from testrunner.local import testsuite from testrunner.local import testsuite
from testrunner.local import utils from testrunner.local import utils
def decode(arg, encoding="utf-8"): PYTHON3 = sys.version_info >= (3, 0)
return arg.decode(encoding)
def maybe_decode(arg, encoding="utf-8"):
return arg.decode(encoding) if PYTHON3 else arg
def encode(arg, encoding="utf-8"): def maybe_encode(arg, encoding="utf-8"):
return arg.encode(encoding) return arg.encode(encoding) if PYTHON3 else arg
# Special LINT rules diverging from default and reason. # Special LINT rules diverging from default and reason.
# build/header_guard: Our guards have the form "V8_FOO_H_", not "SRC_FOO_H_". # build/header_guard: Our guards have the form "V8_FOO_H_", not "SRC_FOO_H_".
...@@ -89,7 +100,7 @@ def CppLintWorker(command): ...@@ -89,7 +100,7 @@ def CppLintWorker(command):
out_lines = "" out_lines = ""
error_count = -1 error_count = -1
while True: while True:
out_line = decode(process.stderr.readline()) out_line = maybe_decode(process.stderr.readline())
if out_line == '' and process.poll() != None: if out_line == '' and process.poll() != None:
if error_count == -1: if error_count == -1:
print("Failed to process %s" % command.pop()) print("Failed to process %s" % command.pop())
...@@ -115,7 +126,7 @@ def TorqueLintWorker(command): ...@@ -115,7 +126,7 @@ def TorqueLintWorker(command):
out_lines = "" out_lines = ""
error_count = 0 error_count = 0
while True: while True:
out_line = decode(process.stderr.readline()) out_line = maybe_decode(process.stderr.readline())
if out_line == '' and process.poll() != None: if out_line == '' and process.poll() != None:
break break
out_lines += out_line out_lines += out_line
...@@ -145,7 +156,7 @@ def JSLintWorker(command): ...@@ -145,7 +156,7 @@ def JSLintWorker(command):
sys.stdout.write("error code " + str(rc) + " running clang-format.\n") sys.stdout.write("error code " + str(rc) + " running clang-format.\n")
return rc return rc
if decode(output) != contents: if maybe_decode(output) != contents:
return 1 return 1
return 0 return 0
...@@ -203,7 +214,7 @@ class FileContentsCache(object): ...@@ -203,7 +214,7 @@ class FileContentsCache(object):
for file in files: for file in files:
try: try:
handle = open(file, "r") handle = open(file, "r")
file_sum = md5er(encode(handle.read())).digest() file_sum = md5er(maybe_encode(handle.read())).digest()
if not file in self.sums or self.sums[file] != file_sum: if not file in self.sums or self.sums[file] != file_sum:
changed_or_new.append(file) changed_or_new.append(file)
self.sums[file] = file_sum self.sums[file] = file_sum
...@@ -487,7 +498,7 @@ class SourceProcessor(SourceFileProcessor): ...@@ -487,7 +498,7 @@ class SourceProcessor(SourceFileProcessor):
output = subprocess.Popen('git ls-files --full-name', output = subprocess.Popen('git ls-files --full-name',
stdout=PIPE, cwd=path, shell=True) stdout=PIPE, cwd=path, shell=True)
result = [] result = []
for file in decode(output.stdout.read()).split(): for file in maybe_decode(output.stdout.read()).split():
for dir_part in os.path.dirname(file).replace(os.sep, '/').split('/'): for dir_part in os.path.dirname(file).replace(os.sep, '/').split('/'):
if self.IgnoreDir(dir_part): if self.IgnoreDir(dir_part):
break break
...@@ -621,7 +632,7 @@ class SourceProcessor(SourceFileProcessor): ...@@ -621,7 +632,7 @@ class SourceProcessor(SourceFileProcessor):
for file in files: for file in files:
try: try:
handle = open(file, "rb") handle = open(file, "rb")
contents = decode(handle.read(), "ISO-8859-1") contents = maybe_decode(handle.read(), "ISO-8859-1")
if len(contents) > 0 and not self.ProcessContents(file, contents): if len(contents) > 0 and not self.ProcessContents(file, contents):
success = False success = False
violations += 1 violations += 1
......
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