forked from firka/flutter
Update infrastructure python code to be compatible with python 2 and python 3 (flutter/engine#39133)
* Compatibility with python2 and python3 * Formatting * Updated to use a function instead of decoding bytes in multiple places. * Formatting and whitespace cleanup. * Fix import statement. * Linter change for docstring. * Formatting. * Remove function from run_tests.py since it is a pain to import. * Add todo message for python 2 deprecation. * Updated copyright year.
This commit is contained in:
25
engine/src/flutter/ci/compatibility_helper.py
Normal file
25
engine/src/flutter/ci/compatibility_helper.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/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.
|
||||
#
|
||||
# This script contains helper function(s) for supporting both
|
||||
# python 2 and python 3 infrastructure code.
|
||||
|
||||
ENCODING = 'UTF-8'
|
||||
|
||||
|
||||
def byte_str_decode(str_or_bytes):
|
||||
"""Returns a string if given either a string or bytes.
|
||||
|
||||
TODO: This function should be removed when the supported python
|
||||
version is only python 3.
|
||||
|
||||
Args:
|
||||
str_or_bytes (string or bytes) we want to convert or return as
|
||||
the possible value changes depending on the version of python
|
||||
used.
|
||||
"""
|
||||
return str_or_bytes if isinstance(str_or_bytes,
|
||||
str) else str_or_bytes.decode(ENCODING)
|
||||
@@ -10,6 +10,7 @@ import re
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from compatibility_helper import byte_str_decode
|
||||
|
||||
if 'STORAGE_BUCKET' not in os.environ:
|
||||
print('The GCP storage bucket must be provided as an environment variable.')
|
||||
@@ -67,6 +68,7 @@ def check_logcat(results_dir):
|
||||
'gsutil', 'cat',
|
||||
'%s/%s/*/logcat' % (BUCKET, results_dir)
|
||||
])
|
||||
logcat = byte_str_decode(logcat)
|
||||
if not logcat:
|
||||
sys.exit(1)
|
||||
|
||||
@@ -82,7 +84,9 @@ def check_timeline(results_dir):
|
||||
'gsutil', 'du',
|
||||
'%s/%s/*/game_loop_results/results_scenario_0.json' %
|
||||
(BUCKET, results_dir)
|
||||
]).strip()
|
||||
])
|
||||
gsutil_du = byte_str_decode(gsutil_du)
|
||||
gsutil_du = gsutil_du.strip()
|
||||
if gsutil_du == '0':
|
||||
print('Failed to produce a timeline.')
|
||||
sys.exit(1)
|
||||
@@ -113,8 +117,9 @@ def main():
|
||||
return 1
|
||||
|
||||
git_revision = subprocess.check_output(['git', 'rev-parse', 'HEAD'],
|
||||
cwd=script_dir).strip()
|
||||
|
||||
cwd=script_dir)
|
||||
git_revision = byte_str_decode(git_revision)
|
||||
git_revision = git_revision.strip()
|
||||
results = []
|
||||
apk = None
|
||||
for apk in apks:
|
||||
|
||||
@@ -17,6 +17,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from urllib import request
|
||||
from compatibility_helper import byte_str_decode
|
||||
|
||||
SCRIPT_DIR = os.path.dirname(sys.argv[0])
|
||||
CHECKOUT_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..'))
|
||||
@@ -206,7 +207,9 @@ def get_common_ancestor_commit(dep, deps_list):
|
||||
'git --git-dir ' + temp_dep_dir + '/.git remote show upstream ' +
|
||||
"| sed -n \'/HEAD branch/s/.*: //p\'",
|
||||
shell=True
|
||||
).decode().strip()
|
||||
)
|
||||
default_branch = byte_str_decode(default_branch)
|
||||
default_branch = default_branch.strip()
|
||||
print(
|
||||
'default_branch found: {default_branch}'.format(
|
||||
default_branch=default_branch
|
||||
@@ -223,7 +226,8 @@ def get_common_ancestor_commit(dep, deps_list):
|
||||
"--format=\'%(objectname:short)\' refs/heads/upstream",
|
||||
shell=True
|
||||
)
|
||||
commit = commit.decode().strip()
|
||||
commit = byte_str_decode(commit)
|
||||
commit = commit.strip()
|
||||
|
||||
# perform merge-base on most recent default branch commit and pinned mirror commit
|
||||
ancestor_commit = subprocess.check_output(
|
||||
@@ -232,7 +236,8 @@ def get_common_ancestor_commit(dep, deps_list):
|
||||
),
|
||||
shell=True
|
||||
)
|
||||
ancestor_commit = ancestor_commit.decode().strip()
|
||||
ancestor_commit = byte_str_decode(ancestor_commit)
|
||||
ancestor_commit = ancestor_commit.strip()
|
||||
print('Ancestor commit: ' + ancestor_commit)
|
||||
return ancestor_commit
|
||||
except subprocess.CalledProcessError as error:
|
||||
|
||||
@@ -33,6 +33,7 @@ ROBOTO_FONT_PATH = os.path.join(FONTS_DIR, 'Roboto-Regular.ttf')
|
||||
FONT_SUBSET_DIR = os.path.join(BUILDROOT_DIR, 'flutter', 'tools', 'font-subset')
|
||||
|
||||
FML_UNITTESTS_FILTER = '--gtest_filter=-*TimeSensitiveTest*'
|
||||
ENCODING = 'UTF-8'
|
||||
|
||||
|
||||
def print_divider(char='='):
|
||||
@@ -598,6 +599,11 @@ def ensure_ios_tests_are_built(ios_out_dir):
|
||||
def assert_expected_xcode_version():
|
||||
"""Checks that the user has a version of Xcode installed"""
|
||||
version_output = subprocess.check_output(['xcodebuild', '-version'])
|
||||
# TODO ricardoamador: remove this check when python 2 is deprecated.
|
||||
version_output = version_output if isinstance(
|
||||
version_output, str
|
||||
) else version_output.decode(ENCODING)
|
||||
version_output = version_output.strip()
|
||||
match = re.match(r'Xcode (\d+)', version_output)
|
||||
message = 'Xcode must be installed to run the iOS embedding unit tests'
|
||||
assert match, message
|
||||
|
||||
Reference in New Issue
Block a user