diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 777f842c67..7030c8b9ad 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -721,7 +721,7 @@ Args: — **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. -  **@contextmanager**
— **def [\_\_call\_\_](/recipes/recipe_modules/osx_sdk/api.py#64)(self, kind):** +  **@contextmanager**
— **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] -— **def [RunSteps](/recipes/recipe_modules/osx_sdk/examples/full.py#15)(api):** +— **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] diff --git a/recipes/recipe_modules/osx_sdk/__init__.py b/recipes/recipe_modules/osx_sdk/__init__.py index ab3f27b389..b6920b4b4e 100644 --- a/recipes/recipe_modules/osx_sdk/__init__.py +++ b/recipes/recipe_modules/osx_sdk/__init__.py @@ -10,6 +10,7 @@ DEPS = [ 'recipe_engine/json', 'recipe_engine/path', 'recipe_engine/platform', + 'recipe_engine/raw_io', 'recipe_engine/step', 'recipe_engine/version', ] diff --git a/recipes/recipe_modules/osx_sdk/api.py b/recipes/recipe_modules/osx_sdk/api.py index 0b7ba3173e..a85e477fe1 100644 --- a/recipes/recipe_modules/osx_sdk/api.py +++ b/recipes/recipe_modules/osx_sdk/api.py @@ -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', diff --git a/recipes/recipe_modules/osx_sdk/examples/full.expected/ancient_version.json b/recipes/recipe_modules/osx_sdk/examples/full.expected/ancient_version.json index 36aa5b6156..abfffd6ac5 100644 --- a/recipes/recipe_modules/osx_sdk/examples/full.expected/ancient_version.json +++ b/recipes/recipe_modules/osx_sdk/examples/full.expected/ancient_version.json @@ -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", diff --git a/recipes/recipe_modules/osx_sdk/examples/full.expected/automatic_version.json b/recipes/recipe_modules/osx_sdk/examples/full.expected/automatic_version.json index 3125b4be16..ec76a1ae55 100644 --- a/recipes/recipe_modules/osx_sdk/examples/full.expected/automatic_version.json +++ b/recipes/recipe_modules/osx_sdk/examples/full.expected/automatic_version.json @@ -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", diff --git a/recipes/recipe_modules/osx_sdk/examples/full.expected/mac.json b/recipes/recipe_modules/osx_sdk/examples/full.expected/mac.json index d28cc77996..80d6067fc4 100644 --- a/recipes/recipe_modules/osx_sdk/examples/full.expected/mac.json +++ b/recipes/recipe_modules/osx_sdk/examples/full.expected/mac.json @@ -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" ], diff --git a/recipes/recipe_modules/osx_sdk/examples/full.py b/recipes/recipe_modules/osx_sdk/examples/full.py index 7db537acb2..04388820e4 100644 --- a/recipes/recipe_modules/osx_sdk/examples/full.py +++ b/recipes/recipe_modules/osx_sdk/examples/full.py @@ -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')), )