[recipe_modules/osx_sdk] Rewrite osx_sdk module to not rely on platform.mac_release.

Since macOS 11, the underlying python `platform.mac_vers()` call
that mac_release is populated from returns "10.16" on all versions
of macOS.

Switch this to just shell out to `sw_vers` to pick up the current
platform version instead.

Non-trivial downstream rolls are because `api.platform.mac_release`
no longer mocks the version of the SDK installed... however it would
be better to set this by just using the explicit sdk_version property.

R=yueshe@google.com

Bug: 331252586
Recipe-Nontrivial-Roll: build_limited
Recipe-Nontrivial-Roll: infra
Recipe-Nontrivial-Roll: build
Change-Id: I41a27383f67db4835ba84b7a47813884879818cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5394351
Commit-Queue: Robbie Iannucci <iannucci@chromium.org>
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
Reviewed-by: Yue She <yueshe@google.com>
changes/51/5394351/4
Robert Iannucci 2 years ago committed by LUCI CQ
parent b6f459b87c
commit 2dbb3f399a

@ -721,7 +721,7 @@ Args:
&mdash; **def [upload](/recipes/recipe_modules/gsutil/api.py#98)(self, source, bucket, dest, args=None, link_name='gsutil.upload', metadata=None, unauthenticated_url=False, \*\*kwargs):**
### *recipe_modules* / [osx\_sdk](/recipes/recipe_modules/osx_sdk)
[DEPS](/recipes/recipe_modules/osx_sdk/__init__.py#7): [recipe\_engine/cipd][recipe_engine/recipe_modules/cipd], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/step][recipe_engine/recipe_modules/step], [recipe\_engine/version][recipe_engine/recipe_modules/version]
[DEPS](/recipes/recipe_modules/osx_sdk/__init__.py#7): [recipe\_engine/cipd][recipe_engine/recipe_modules/cipd], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step], [recipe\_engine/version][recipe_engine/recipe_modules/version]
The `osx_sdk` module provides safe functions to access a semi-hermetic
@ -733,7 +733,7 @@ Available only to Google-run bots.
API for using OS X SDK distributed via CIPD.
&emsp; **@contextmanager**<br>&mdash; **def [\_\_call\_\_](/recipes/recipe_modules/osx_sdk/api.py#64)(self, kind):**
&emsp; **@contextmanager**<br>&mdash; **def [\_\_call\_\_](/recipes/recipe_modules/osx_sdk/api.py#56)(self, kind):**
Sets up the XCode SDK environment.
@ -1135,10 +1135,10 @@ Raises:
Move things around in a loop!
### *recipes* / [osx\_sdk:examples/full](/recipes/recipe_modules/osx_sdk/examples/full.py)
[DEPS](/recipes/recipe_modules/osx_sdk/examples/full.py#7): [osx\_sdk](#recipe_modules-osx_sdk), [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/step][recipe_engine/recipe_modules/step]
[DEPS](/recipes/recipe_modules/osx_sdk/examples/full.py#7): [osx\_sdk](#recipe_modules-osx_sdk), [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/raw\_io][recipe_engine/recipe_modules/raw_io], [recipe\_engine/step][recipe_engine/recipe_modules/step]
&mdash; **def [RunSteps](/recipes/recipe_modules/osx_sdk/examples/full.py#15)(api):**
&mdash; **def [RunSteps](/recipes/recipe_modules/osx_sdk/examples/full.py#16)(api):**
### *recipes* / [presubmit:examples/full](/recipes/recipe_modules/presubmit/examples/full.py)
[DEPS](/recipes/recipe_modules/presubmit/examples/full.py#7): [presubmit](#recipe_modules-presubmit), [recipe\_engine/json][recipe_engine/recipe_modules/json]

@ -10,6 +10,7 @@ DEPS = [
'recipe_engine/json',
'recipe_engine/path',
'recipe_engine/platform',
'recipe_engine/raw_io',
'recipe_engine/step',
'recipe_engine/version',
]

@ -52,14 +52,6 @@ class OSXSDKApi(recipe_api.RecipeApi):
if 'sdk_version' in self._sdk_properties:
self._sdk_version = self._sdk_properties['sdk_version'].lower()
else:
cur_os = self.m.platform.mac_release
for target_os, xcode in reversed(_DEFAULT_VERSION_MAP):
if cur_os >= self.m.version.parse(target_os):
self._sdk_version = xcode
break
else:
self._sdk_version = _DEFAULT_VERSION_MAP[0][-1]
@contextmanager
def __call__(self, kind):
@ -133,6 +125,21 @@ class OSXSDKApi(recipe_api.RecipeApi):
ef.add_package(self._tool_pkg, self._tool_ver)
self.m.cipd.ensure(cache_dir, ef)
if self._sdk_version is None:
find_os = self.m.step(
'find macOS version', ['sw_vers', '-productVersion'],
stdout=self.m.raw_io.output_text(),
step_test_data=(
lambda: self.m.raw_io.test_api.stream_output_text('14.4')))
cur_os = self.m.version.parse(find_os.stdout.strip())
find_os.presentation.step_text = f'Running on {str(cur_os)!r}.'
for target_os, xcode in reversed(_DEFAULT_VERSION_MAP):
if cur_os >= self.m.version.parse(target_os):
self._sdk_version = xcode
break
else:
self._sdk_version = _DEFAULT_VERSION_MAP[0][-1]
sdk_app = cache_dir.join('XCode.app')
self.m.step('install xcode', [
cache_dir.join('mac_toolchain'), 'install',

@ -28,6 +28,17 @@
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"cmd": [
"sw_vers",
"-productVersion"
],
"infra_step": true,
"name": "find macOS version",
"~followup_annotations": [
"@@@STEP_TEXT@Running on '10.1.0'.@@@"
]
},
{
"cmd": [
"[CACHE]/osx_sdk/mac_toolchain",

@ -28,6 +28,17 @@
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"cmd": [
"sw_vers",
"-productVersion"
],
"infra_step": true,
"name": "find macOS version",
"~followup_annotations": [
"@@@STEP_TEXT@Running on '10.15.6'.@@@"
]
},
{
"cmd": [
"[CACHE]/osx_sdk/mac_toolchain",

@ -28,6 +28,17 @@
"@@@STEP_LOG_END@json.output@@@"
]
},
{
"cmd": [
"sw_vers",
"-productVersion"
],
"infra_step": true,
"name": "find macOS version",
"~followup_annotations": [
"@@@STEP_TEXT@Running on '14.4'.@@@"
]
},
{
"cmd": [
"[CACHE]/osx_sdk/mac_toolchain",
@ -35,7 +46,7 @@
"-kind",
"mac",
"-xcode-version",
"9f2000",
"14c18",
"-output-dir",
"[CACHE]/osx_sdk/XCode.app"
],

@ -5,10 +5,11 @@
PYTHON_VERSION_COMPATIBILITY = 'PY3'
DEPS = [
'osx_sdk',
'recipe_engine/platform',
'recipe_engine/properties',
'recipe_engine/step',
'osx_sdk',
'recipe_engine/platform',
'recipe_engine/properties',
'recipe_engine/raw_io',
'recipe_engine/step',
]
@ -34,11 +35,13 @@ def GenTests(api):
yield api.test(
'automatic_version',
api.platform.name('mac'),
api.platform.mac_release('10.15.6'),
api.step_data('find macOS version',
stdout=api.raw_io.output_text('10.15.6')),
)
yield api.test(
'ancient_version',
api.platform.name('mac'),
api.platform.mac_release('10.1.0'),
api.step_data('find macOS version',
stdout=api.raw_io.output_text('10.1.0')),
)

Loading…
Cancel
Save