From 529458ce802899a5ed3a0314da37283ea39bf303 Mon Sep 17 00:00:00 2001 From: OliverKoo Date: Thu, 24 Mar 2022 13:00:21 -0700 Subject: [PATCH 1/2] update _GetXcodeVersionString to work with py3 --- src/TulsiGenerator/Scripts/bazel_build.py | 45 +++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/TulsiGenerator/Scripts/bazel_build.py b/src/TulsiGenerator/Scripts/bazel_build.py index 102680ad..6b3272c0 100755 --- a/src/TulsiGenerator/Scripts/bazel_build.py +++ b/src/TulsiGenerator/Scripts/bazel_build.py @@ -337,23 +337,38 @@ def _GetXcodeBuildVersionString(): @staticmethod def _GetXcodeVersionString(): - """Returns Xcode version info from the environment as a string.""" - xcodebuild_bin = os.path.join(os.environ["SYSTEM_DEVELOPER_BIN_DIR"], "xcodebuild") - # Expect something like this - # ['Xcode 11.2.1', 'Build version 11B500', ''] - # This command is a couple hundred MS to run and should be removed. On - # Xcode 11.2.1 Xcode uses the wrong # version, although version.plist is - # correct. - process = subprocess.Popen([xcodebuild_bin, "-version"], stdout=subprocess.PIPE) - process.wait() - - if process.returncode != 0: - _PrintXcodeWarning('Can\'t find xcode version') + """Returns Xcode version info from the Xcode's version.plist. + Just reading XCODE_VERSION_ACTUAL from the environment seems like + a more reasonable implementation, but has shown to be unreliable, + at least when using Xcode 11.3.1 and opening the project within an + Xcode workspace. + """ + developer_dir = os.environ['DEVELOPER_DIR'] + app_dir = developer_dir.split('.app')[0] + '.app' + version_plist_path = os.path.join(app_dir, 'Contents', 'version.plist') + try: + with open(version_plist_path, 'rb') as f: + plist = plistlib.load(f) + except IOError: + _PrintXcodeWarning('Tulsi cannot determine Xcode version, error ' + 'reading from {}'.format(version_plist_path)) + return None + try: + # Example: "11.3.1", "11.3", "11.0" + key = 'CFBundleShortVersionString' + version_string = plist[key] + except KeyError: + _PrintXcodeWarning('Tulsi cannot determine Xcode version from {}, no ' + '"{}" key'.format(version_plist_path, key)) return None - output = process.stdout.read() - lines = output.split("\n") - return lines[0].split(" ")[1] + # But we need to normalize to major.minor.patch, e.g. 11.3.0 or + # 11.0.0, so add one or two ".0" if needed (two just in case + # there is ever just a single version number like "12") + dots_count = version_string.count('.') + dot_zeroes_to_add = 2 - dots_count + version_string += '.0' * dot_zeroes_to_add + return version_string @staticmethod def _ComputeXcodeVersionFlag(): From 5f6998cb92f942333691f473d9e68a07740cb231 Mon Sep 17 00:00:00 2001 From: OliverKoo Date: Thu, 24 Mar 2022 13:16:54 -0700 Subject: [PATCH 2/2] port in https://github.com/bazelbuild/tulsi/commit/270eae09f5577517b817fa35ca2b89b7e0d89475 --- src/TulsiGenerator/Scripts/bazel_build.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TulsiGenerator/Scripts/bazel_build.py b/src/TulsiGenerator/Scripts/bazel_build.py index 6b3272c0..0f586afc 100755 --- a/src/TulsiGenerator/Scripts/bazel_build.py +++ b/src/TulsiGenerator/Scripts/bazel_build.py @@ -25,6 +25,7 @@ import json import os import pipes +import plistlib import re import shutil import signal