Update tools to python3 (#85)
This updates the scripts in the tools directory to work with python3, python2
support is now deprecated.
The only significant API change is that the subprocess module works in bytes
instead of str, the rest are mainly style changes.
diff --git a/README.md b/README.md
index c1a0a7d..8d24f50 100644
--- a/README.md
+++ b/README.md
@@ -48,7 +48,7 @@
To build VIXL the following software is required:
- 1. Python 2.7
+ 1. Python 3.5+
2. SCons 2.0
3. GCC 4.8+ or Clang 4.0+
diff --git a/tools/clang_format.py b/tools/clang_format.py
index a0d000c..2b9252b 100755
--- a/tools/clang_format.py
+++ b/tools/clang_format.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
# Copyright 2016, VIXL authors
# All rights reserved.
@@ -78,7 +78,7 @@
if rc != 0:
util.abort("Failed to execute %s: %s" % (cmd, version))
m = re.search("^clang-format version (\d)\.(\d)\.\d.*$",
- version.decode(), re.M)
+ version, re.M)
if not m:
util.abort("Failed to get clang-format's version: %s" % version)
major, minor = m.groups()
diff --git a/tools/clang_tidy.py b/tools/clang_tidy.py
index 8607547..727c829 100755
--- a/tools/clang_tidy.py
+++ b/tools/clang_tidy.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
# Copyright 2019, VIXL authors
# All rights reserved.
@@ -67,7 +67,7 @@
rc, version = util.getstatusoutput(cmd)
if rc != 0:
util.abort("Failed to execute %s: %s" % (cmd, version))
- m = re.search("LLVM version (\d)\.(\d)\.\d.*$", version.decode(), re.M)
+ m = re.search("LLVM version (\d)\.(\d)\.\d.*$", version, re.M)
if not m:
util.abort("Failed to get clang-tidy's version: %s" % version)
major, minor = m.groups()
@@ -93,7 +93,7 @@
return "\n".join(out)
def FilterFiles(list_files):
- return list(filter(lambda x: x.endswith('.cc'), list_files))
+ return [x for x in list_files if x.endswith('.cc')]
def RunTest(test):
cmd = " ".join(test.args['command'])
diff --git a/tools/generate_simulator_traces.py b/tools/generate_simulator_traces.py
index 3e25b0d..66c49c3 100755
--- a/tools/generate_simulator_traces.py
+++ b/tools/generate_simulator_traces.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
# Copyright 2015, VIXL authors
# All rights reserved.
@@ -155,7 +155,7 @@
master_trace_f.write('\n\n')
# Find the AArch64 simulator tests.
- tests = sorted(filter(lambda t: 'AARCH64_SIM_' in t, test_list.split()),
+ tests = sorted([t for t in test_list.split() if 'AARCH64_SIM_' in t],
key=lambda t: GetAArch64Filename(t))
for test in tests:
@@ -164,7 +164,7 @@
trace_filename = GetAArch64Filename(test_name)
if not args.filter or re.compile(args.filter).search(test):
# Run each test.
- print 'Generating trace for ' + test;
+ print('Generating trace for ' + test);
cmd = ' '.join([args.runner, '--generate_test_trace', test])
status, output = util.getstatusoutput(cmd)
if status != 0: util.abort('Failed to run ' + cmd + '.')
@@ -207,7 +207,7 @@
for test in tests:
# Run each test.
- print 'Generating trace for ' + test;
+ print('Generating trace for ' + test);
# Strip out 'AARCH32_' to get the name of the test.
test_name = test[len('AARCH32_'):]
@@ -234,4 +234,4 @@
'\n' + "#endif // VIXL_" + test_name.upper() + "_H_" + '\n')
trace_f.close()
- print 'Trace generation COMPLETE'
+ print('Trace generation COMPLETE')
diff --git a/tools/generate_test_trace_a64_reference.py b/tools/generate_test_trace_a64_reference.py
index cef06fb..d42594d 100755
--- a/tools/generate_test_trace_a64_reference.py
+++ b/tools/generate_test_trace_a64_reference.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
# Copyright 2016, VIXL authors
# All rights reserved.
@@ -55,7 +55,7 @@
# Find the trace tests.
status, output = util.getstatusoutput(args.runner + ' --list')
if status != 0: util.abort('Failed to list all tests')
- tests = filter(lambda t: 'TRACE_' in t, output.split())
+ tests = [t for t in output.split() if 'TRACE_' in t]
tests.sort()
if not os.path.exists(args.outdir):
@@ -63,7 +63,7 @@
for test in tests:
# Run each test.
- print 'Generating trace for ' + test;
+ print('Generating trace for ' + test);
cmd = ' '.join([args.runner, '--generate_test_trace', test])
status, output = util.getstatusoutput(cmd)
if status != 0: util.abort('Failed to run ' + cmd + '.')
diff --git a/tools/git.py b/tools/git.py
deleted file mode 100644
index a133a48..0000000
--- a/tools/git.py
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright 2014, VIXL authors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright notice,
-# this list of conditions and the following disclaimer.
-# * Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-# * Neither the name of ARM Limited nor the names of its contributors may be
-# used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND ANY
-# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
-# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
-# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import re
-import util
-import os.path
-from pipes import quote
-
-def is_git_repository_root(path):
- command = 'git -C ' + quote(path) + ' rev-parse --show-toplevel'
- status, toplevel = util.getstatusoutput(command)
- if status != 0: return False
- return os.path.samefile(toplevel, path)
-
-def get_tracked_files():
- command = 'git ls-tree HEAD -r --full-tree --name-only'
-
- status, tracked = util.getstatusoutput(command)
- if status != 0: util.abort('Failed to list tracked files.')
-
- return tracked
-
-
-# Get untracked files in src/, test/, and tools/.
-def get_untracked_files():
- status, output = util.getstatusoutput('git status -s')
- if status != 0: util.abort('Failed to get git status.')
-
- untracked_regexp = re.compile('\?\?.*(src/|test/|tools/).*(.cc$|.h$)')
- files_in_watched_folder = lambda n: untracked_regexp.search(n) != None
- untracked_files = filter(files_in_watched_folder, output.split('\n'))
-
- return untracked_files
diff --git a/tools/known_test_failures.py b/tools/known_test_failures.py
index 262d6e6..791568b 100644
--- a/tools/known_test_failures.py
+++ b/tools/known_test_failures.py
@@ -76,7 +76,7 @@
'AARCH64_SIM_frsqrts_D'
}
- filtered_list = filter(lambda x: x not in known_valgrind_test_failures, tests)
+ filtered_list = [x for x in tests if x not in known_valgrind_test_failures]
return (filtered_list, len(tests) - len(filtered_list), reason)
def FilterKnownTestFailures(tests, **env):
diff --git a/tools/lint.py b/tools/lint.py
index d4c9f65..4820439 100755
--- a/tools/lint.py
+++ b/tools/lint.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
# Copyright 2015, VIXL authors
# All rights reserved.
@@ -38,7 +38,6 @@
import sys
import config
-import git
import printer
import util
@@ -143,12 +142,12 @@
return -1
# Filter out directories.
- files = filter(os.path.isfile, files)
+ files = list(filter(os.path.isfile, files))
# Filter out files for which we have a cached correct result.
if cached_results is not None and len(cached_results) != 0:
n_input_files = len(files)
- files = filter(lambda f: ShouldLint(f, cached_results), files)
+ files = [f for f in files if ShouldLint(f, cached_results)]
n_skipped_files = n_input_files - len(files)
if n_skipped_files != 0:
printer.Print(
@@ -171,7 +170,7 @@
pool.terminate()
sys.exit(1)
- n_errors = sum(map(lambda (filename, errors): errors, results))
+ n_errors = sum([filename_errors[1] for filename_errors in results])
if cached_results is not None:
for filename, errors in results:
@@ -223,7 +222,7 @@
return \
fnmatch.fnmatch(f, os.path.join(relative_aarch32_traces_path, '*.h')) or \
fnmatch.fnmatch(f, os.path.join(relative_aarch64_traces_path, '*.h'))
- return filter(lambda f: not IsTraceHeader(f), files)
+ return [f for f in files if not IsTraceHeader(f)]
def RunLinter(files, jobs=1, progress_prefix='', cached=True):
diff --git a/tools/printer.py b/tools/printer.py
index 609da7f..57e22e3 100644
--- a/tools/printer.py
+++ b/tools/printer.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
# Copyright 2014, VIXL authors
# All rights reserved.
diff --git a/tools/test.py b/tools/test.py
index 75c700d..85153c0 100755
--- a/tools/test.py
+++ b/tools/test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
# Copyright 2015, VIXL authors
# All rights reserved.
@@ -28,7 +28,6 @@
import argparse
import fcntl
-import git
import itertools
import multiprocessing
import os
@@ -220,7 +219,7 @@
t_current = t_start
t_last_indication = t_start
t_current = t_start
- process_output = ''
+ process_output = b''
# Keep looping as long as the process is running.
while p.poll() is None:
@@ -238,9 +237,9 @@
try:
line = os.read(p.stdout.fileno(), 1024)
except OSError:
- line = ''
+ line = b''
break
- if line == '': break
+ if line == b'': break
process_output += line
# The process has exited. Don't forget to retrieve the rest of its output.
@@ -253,13 +252,12 @@
printer.Print(printer.COLOUR_GREEN + printable_command + printer.NO_COLOUR)
else:
printer.Print(printer.COLOUR_RED + printable_command + printer.NO_COLOUR)
- printer.Print(process_output)
+ printer.Print(process_output.decode())
return rc
def RunLinter(jobs):
- return lint.RunLinter(map(lambda x: join(dir_root, x),
- util.get_source_files()),
+ return lint.RunLinter([join(dir_root, x) for x in util.get_source_files()],
jobs = args.jobs, progress_prefix = 'cpp lint: ')
diff --git a/tools/test_runner.py b/tools/test_runner.py
index 3a3f459..d4459ef 100644
--- a/tools/test_runner.py
+++ b/tools/test_runner.py
@@ -41,7 +41,7 @@
tests = output.split()
for f in filters:
- tests = filter(re.compile(f).search, tests)
+ tests = list(filter(re.compile(f).search, tests))
return tests
@@ -51,6 +51,7 @@
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
p_out, p_err = p.communicate()
+ p_out = p_out.decode()
rc = p.poll()
if rc == 0:
diff --git a/tools/thread_pool.py b/tools/thread_pool.py
index 60abafa..c8fd10e 100644
--- a/tools/thread_pool.py
+++ b/tools/thread_pool.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
# Copyright 2019, VIXL authors
# All rights reserved.
diff --git a/tools/util.py b/tools/util.py
index b3f4489..ed41461 100644
--- a/tools/util.py
+++ b/tools/util.py
@@ -37,8 +37,8 @@
def ListCCFilesWithoutExt(path):
- return map(lambda x : os.path.splitext(os.path.basename(x))[0],
- glob.glob(os.path.join(path, '*.cc')))
+ src_files = glob.glob(os.path.join(path, '*.cc'))
+ return [os.path.splitext(os.path.basename(x))[0] for x in src_files]
def abort(message):
@@ -46,14 +46,8 @@
sys.exit(1)
-# Emulate python3 subprocess.getstatusoutput.
def getstatusoutput(command):
- try:
- args = shlex.split(command)
- output = subprocess.check_output(args, stderr=subprocess.STDOUT)
- return 0, output.rstrip('\n')
- except subprocess.CalledProcessError as e:
- return e.returncode, e.output.rstrip('\n')
+ return subprocess.getstatusoutput(command)
def IsCommandAvailable(command):