From b72002518176e9e1bc1fe1ea94ee7171a456191e Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Fri, 4 Jun 2021 17:28:42 -0700 Subject: [PATCH] Python 3 migration required for Android builds This migrates all Python scripts required to build Android targets to be Python 3.x compatible. Main changes: * Communication with processes now returns bytestreams by default. By specifying universal_newlines=True, these streams are decoded as UTF-8. * md5.update() takes a bytes type, but strings are now utf-8 by default. We call string.encode('utf-8') convert to bytes. * print now uses function syntax Issue: https://github.com/flutter/flutter/issues/83043 --- build/android/gyp/util/build_utils.py | 10 ++++++---- build/android/gyp/util/md5_check.py | 2 +- build/ls.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/build/android/gyp/util/build_utils.py b/build/android/gyp/util/build_utils.py index 9dbf8fab6b..755a7e015e 100644 --- a/build/android/gyp/util/build_utils.py +++ b/build/android/gyp/util/build_utils.py @@ -146,11 +146,13 @@ def CheckOutput(args, cwd=None, print_stdout=False, print_stderr=True, stdout_filter=None, stderr_filter=None, + universal_newlines=True, fail_func=lambda returncode, stderr: returncode != 0): if not cwd: cwd = os.getcwd() child = subprocess.Popen(args, + universal_newlines=universal_newlines, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd) stdout, stderr = child.communicate() @@ -260,13 +262,13 @@ def Allow(name): def PrintWarning(message): - print 'WARNING: ' + message + print('WARNING: %s' % message) def PrintBigWarning(message): - print '***** ' * 8 + print('***** ' * 8) PrintWarning(message) - print '***** ' * 8 + print('***** ' * 8) def GetSortedTransitiveDependencies(top, deps_func): @@ -312,7 +314,7 @@ def GetPythonDependencies(): src/. The paths will be relative to the current directory. """ _ForceLazyModulesToLoad() - module_paths = (m.__file__ for m in sys.modules.itervalues() + module_paths = (m.__file__ for m in sys.modules.values() if m is not None and hasattr(m, '__file__')) abs_module_paths = map(os.path.abspath, module_paths) diff --git a/build/android/gyp/util/md5_check.py b/build/android/gyp/util/md5_check.py index 9f365aa081..60e4bf7643 100644 --- a/build/android/gyp/util/md5_check.py +++ b/build/android/gyp/util/md5_check.py @@ -70,7 +70,7 @@ def __init__(self, record_path=None, input_paths=None, input_strings=None): for i in sorted(input_paths): _UpdateMd5ForPath(md5, i) for s in input_strings: - md5.update(s) + md5.update(s.encode('utf-8')) self.new_digest = md5.hexdigest() self.old_digest = '' diff --git a/build/ls.py b/build/ls.py index b94a337442..6c05ecc646 100755 --- a/build/ls.py +++ b/build/ls.py @@ -16,7 +16,7 @@ def main(target_directory, file_extension): for f in files: if file_extension is None or os.path.splitext(f)[-1] == file_extension: path = os.path.join(root, f) - print path + print(path) if __name__ == '__main__': parser = argparse.ArgumentParser(