From d19589ff81c38ecc60228d0429cf39bfb4381ce6 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Fri, 29 Mar 2019 05:53:09 +0000 Subject: [PATCH] Throw error for unicode URLs in .gclient This is no longer supported to make the move to Python 3 easier. Only some very old/weird user configurations may have this, so this provides a clear actionable error message. Bug: 942522 Change-Id: I88106089c53d84b19c4f77b7e60fe251082122d7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1539957 Reviewed-by: Dirk Pranke Commit-Queue: Raul Tambre --- gclient.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/gclient.py b/gclient.py index 034314a7e2..a60d331345 100755 --- a/gclient.py +++ b/gclient.py @@ -1374,7 +1374,7 @@ it or fix the checkout. ''' % {'checkout_path': os.path.join(self.root_dir, dep.name), 'expected_url': dep.url, 'expected_scm': dep.GetScmName(), - 'mirror_string' : mirror_string, + 'mirror_string': mirror_string, 'actual_url': actual_url, 'actual_scm': dep.GetScmName()}) @@ -1387,6 +1387,21 @@ it or fix the checkout. except SyntaxError as e: gclient_utils.SyntaxErrorToError('.gclient', e) + # Supporting Unicode URLs in both Python 2 and 3 is annoying. Try to + # convert to ASCII in case the URL doesn't actually have any Unicode + # characters, otherwise raise an error. + # This isn't an issue on Python 3 because everything's Unicode anyway. + if sys.version_info.major == 2: + try: + url = config_dict['solutions'][0]['url'] + if isinstance(url, unicode): + config_dict['solutions'][0]['url'] = url.encode('ascii') + except UnicodeEncodeError: + raise gclient_utils.Error( + "Invalid .gclient file. The url mustn't be unicode.") + except KeyError: + pass + # Append any target OS that is not already being enforced to the tuple. target_os = config_dict.get('target_os', []) if config_dict.get('target_os_only', False):