diff --git a/ci/compatibility_helper.py b/ci/compatibility_helper.py new file mode 100644 index 0000000000000..0d8231ca178e7 --- /dev/null +++ b/ci/compatibility_helper.py @@ -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) diff --git a/ci/firebase_testlab.py b/ci/firebase_testlab.py index 92069a7c1f584..510f582e8b82d 100755 --- a/ci/firebase_testlab.py +++ b/ci/firebase_testlab.py @@ -10,6 +10,7 @@ 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: diff --git a/ci/scan_flattened_deps.py b/ci/scan_flattened_deps.py index 2f51bdf09b683..67759b3d710a0 100644 --- a/ci/scan_flattened_deps.py +++ b/ci/scan_flattened_deps.py @@ -17,6 +17,7 @@ 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: diff --git a/testing/run_tests.py b/testing/run_tests.py index 875b0ef88ccfb..9e79e4e21e77a 100755 --- a/testing/run_tests.py +++ b/testing/run_tests.py @@ -33,6 +33,7 @@ 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