Migrate all Python hashbangs to Python 3 (flutter/engine#27838)

Migrates all `#!/usr/bin/env python` hashbang lines to use python3.

Also updates the licence tool to treat python3 scripts on par with
python 2 scripts.

Issue: https://github.com/flutter/flutter/issues/83043
This commit is contained in:
Chris Bracken
2021-07-31 11:09:12 -07:00
committed by GitHub
parent b9886cd987
commit 8803824c64
40 changed files with 95 additions and 74 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -13,9 +13,9 @@ Precondition: $CWD/../../flutter is the path to the flutter engine repo.
usage: copy_info_plist.py <src_path> <dest_path> --bitcode=<enable_bitcode>
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import subprocess
import sys

View File

@@ -1,4 +1,5 @@
#!/usr/bin/python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -81,7 +81,7 @@ def copy(from_root, to_root, filter_func=None):
os.makedirs(to_dir)
shutil.copy(from_path, to_path)
dirs[:] = filter(wrapped_filter, dirs)
dirs[:] = list(filter(wrapped_filter, dirs))
def copy_or_link(from_root, to_root, filter_func=None):
@@ -114,7 +114,7 @@ def list_files(from_root, filter_func=None):
for name in filter(wrapped_filter, files):
path = os.path.join(root, name)
file_list.append(path)
dirs[:] = filter(wrapped_filter, dirs)
dirs[:] = list(filter(wrapped_filter, dirs))
return file_list

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -84,7 +84,7 @@ def main():
RemoveIfExists(raw_profile)
print "Running test %s to gather profile." % os.path.basename(absolute_test_path)
print("Running test %s to gather profile." % os.path.basename(absolute_test_path))
test_command = [absolute_test_path]

View File

@@ -1,13 +1,13 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Get the Git HEAD revision of a specified Git repository."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
import subprocess

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,2 +1,2 @@
Signature: 17e2c7f169a5804317b8f79ab1f8a838
Signature: fdaf33383efb94fa6bbc158cbc25635c

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,11 +1,12 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import errno

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -39,7 +40,7 @@ def _find_package_pid(adb_path, package):
ps_output = subprocess.check_output([adb_path, 'shell', 'ps'])
ps_match = re.search('^\S+\s+(\d+).*\s%s' % package, ps_output, re.MULTILINE)
if not ps_match:
print 'Unable to find pid for package %s on device' % package
print('Unable to find pid for package %s on device' % package)
return None
return int(ps_match.group(1))
@@ -114,7 +115,7 @@ class GdbClient(object):
dev_null = open(os.devnull, 'w')
for lib, local_path in sorted(device_libs):
print 'Copying %s' % lib
print('Copying %s' % lib)
local_path = os.path.join(GdbClient.SYSTEM_LIBS_PATH, local_path)
if not os.path.exists(os.path.dirname(local_path)):
os.makedirs(os.path.dirname(local_path))
@@ -144,7 +145,7 @@ class GdbClient(object):
debug_out_path = os.path.join(flutter_root, 'out/%s' % local_engine)
if not os.path.exists(os.path.join(debug_out_path, 'libflutter.so')):
print 'Unable to find libflutter.so. Make sure you have completed a %s build' % local_engine
print('Unable to find libflutter.so. Make sure you have completed a %s build' % local_engine)
return 1
eval_commands = []

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -33,10 +34,10 @@ def patch(dest_dir, relative_patches_dir=os.curdir):
os.chdir(dest_dir)
for p in utils.find(["*.patch"], patches_dir):
print "applying patch %s" % os.path.basename(p)
print("applying patch %s" % os.path.basename(p))
try:
utils.system(["git", "apply", p])
utils.commit("applied patch %s" % os.path.basename(p))
except subprocess.CalledProcessError:
print "ERROR: patch %s failed to apply" % os.path.basename(p)
print("ERROR: patch %s failed to apply" % os.path.basename(p))
raise

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -8,7 +9,7 @@ import json
import os
import subprocess
import sys
import urllib2
import urllib.request, urllib.error, urllib.parse
from utils import commit
from utils import system
import patch
@@ -96,12 +97,12 @@ def rev(source_dir, dest_dir, dirs_to_rev, name, revision_file=None):
else:
d = dir_to_rev
file_subset = None
print "removing directory %s" % d
print("removing directory %s" % d)
try:
system(["git", "rm", "-r", d], cwd=dest_dir)
except subprocess.CalledProcessError:
print "Could not remove %s" % d
print "cloning directory %s" % d
print("Could not remove %s" % d)
print("cloning directory %s" % d)
if file_subset is None:
files = system(["git", "ls-files", d], cwd=source_dir).splitlines()
@@ -151,8 +152,8 @@ def main():
try:
patch.patch_and_filter(dest_dir, os.path.join('patches', 'chromium'))
except subprocess.CalledProcessError:
print "ERROR: Roll failed due to a patch not applying"
print "Fix the patch to apply, commit the result, and re-run this script"
print("ERROR: Roll failed due to a patch not applying")
print("Fix the patch to apply, commit the result, and re-run this script")
return 1
return 0

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -27,17 +28,17 @@ fml_unittests_filter = '--gtest_filter=-*TimeSensitiveTest*'
def PrintDivider(char='='):
print '\n'
for _ in xrange(4):
print(''.join([char for _ in xrange(80)]))
print '\n'
print('\n')
for _ in range(4):
print(''.join([char for _ in range(80)]))
print('\n')
def RunCmd(cmd, forbidden_output=[], expect_failure=False, env=None, **kwargs):
command_string = ' '.join(cmd)
PrintDivider('>')
print 'Running command "%s"' % command_string
print('Running command "%s"' % command_string)
start_time = time.time()
stdout_pipe = sys.stdout if not forbidden_output else subprocess.PIPE
@@ -70,7 +71,7 @@ def RunCmd(cmd, forbidden_output=[], expect_failure=False, env=None, **kwargs):
raise Exception('command "%s" contained forbidden string %s' % (command_string, forbidden_string))
PrintDivider('<')
print 'Command run successfully in %.2f seconds: %s' % (end_time - start_time, command_string)
print('Command run successfully in %.2f seconds: %s' % (end_time - start_time, command_string))
def IsMac():
@@ -146,7 +147,7 @@ def RunEngineExecutable(build_dir, executable_name, filter, flags=[],
core_path = os.path.join(cwd, 'core')
if luci_test_outputs_path and os.path.exists(core_path) and os.path.exists(unstripped_exe):
dump_path = os.path.join(luci_test_outputs_path, '%s_%s.txt' % (executable_name, sys.platform))
print 'Writing core dump analysis to %s' % dump_path
print('Writing core dump analysis to %s' % dump_path)
subprocess.call([
os.path.join(buildroot_dir, 'flutter', 'testing', 'analyze_core_dump.sh'),
buildroot_dir, unstripped_exe, core_path, dump_path,
@@ -341,12 +342,12 @@ def RunJavaTests(filter, android_variant='android_debug_unopt'):
EnsureJavaTestsAreBuilt(android_out_dir)
embedding_deps_dir = os.path.join(buildroot_dir, 'third_party', 'android_embedding_dependencies', 'lib')
classpath = map(str, [
classpath = list(map(str, [
os.path.join(buildroot_dir, 'third_party', 'android_tools', 'sdk', 'platforms', 'android-30', 'android.jar'),
os.path.join(embedding_deps_dir, '*'), # Wildcard for all jars in the directory
os.path.join(android_out_dir, 'flutter.jar'),
os.path.join(android_out_dir, 'robolectric_tests.jar')
])
]))
test_class = filter if filter else 'io.flutter.FlutterTestSuite'
command = [

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2019 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -58,7 +58,7 @@ def GatherArtifacts(src_root, dst_root, create_meta_package=True):
else:
shutil.rmtree(dst_root)
for src_rel, dst_rel in _ARTIFACT_PATH_TO_DST.iteritems():
for src_rel, dst_rel in _ARTIFACT_PATH_TO_DST.items():
src_full = os.path.join(src_root, src_rel)
dst_full = os.path.join(dst_root, dst_rel)
if not os.path.exists(src_full):

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -167,7 +167,7 @@ def main():
out_dir = args.out_dir
if os.path.exists(out_dir):
print 'Directory: %s is not empty, deleting it.' % out_dir
print('Directory: %s is not empty, deleting it.' % out_dir)
shutil.rmtree(out_dir)
os.makedirs(out_dir)

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

View File

@@ -77,7 +77,7 @@ class _RepositorySourceFile extends _RepositoryLicensedFile {
fs.TextFile get ioTextFile => super.io as fs.TextFile;
static final RegExp _hashBangPattern = RegExp(r'^#! *(?:/bin/sh|/bin/bash|/usr/bin/env +(?:python|bash))\b');
static final RegExp _hashBangPattern = RegExp(r'^#! *(?:/bin/sh|/bin/bash|/usr/bin/env +(?:python|python3|bash))\b');
@override
bool get isShellScript {