Skip to content

Commit

Permalink
Python 3 migration required for Android builds
Browse files Browse the repository at this point in the history
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: flutter/flutter#83043
  • Loading branch information
cbracken committed Jun 5, 2021
1 parent 60e8349 commit b720025
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions build/android/gyp/util/build_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion build/android/gyp/util/md5_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
Expand Down
2 changes: 1 addition & 1 deletion build/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b720025

Please sign in to comment.