From f31cb801f2cda4ce9ac98675d439070d57c84154 Mon Sep 17 00:00:00 2001 From: Robert Iannucci Date: Wed, 27 Nov 2019 17:14:12 +0000 Subject: [PATCH] [recipe_modules/osx_sdk] Better default XCode versions depending on host OS. This uses the macOS<->XCode mapping from wikipedia to set the default XCode version to the highest supported XCode version supported by the current host OS. R=justincohen@google.com, tandrii@chromium.org Bug: 1026340 Recipe-Nontrivial-Roll: build Recipe-Nontrivial-Roll: infra Recipe-Nontrivial-Roll: build_limited_scripts_slave Change-Id: I524d08f81a7778404c60a64b1100b4386a2ed79a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1938022 Reviewed-by: Andrii Shyshkalov Commit-Queue: Robbie Iannucci --- recipes/README.recipes.md | 9 ++- recipes/recipe_modules/osx_sdk/__init__.py | 1 + recipes/recipe_modules/osx_sdk/api.py | 40 +++++++-- .../full.expected/ancient_version.json | 81 +++++++++++++++++++ .../full.expected/automatic_version.json | 81 +++++++++++++++++++ .../full.expected/explicit_version.json | 81 +++++++++++++++++++ .../osx_sdk/examples/full.expected/mac.json | 6 +- .../recipe_modules/osx_sdk/examples/full.py | 20 +++++ 8 files changed, 305 insertions(+), 14 deletions(-) create mode 100644 recipes/recipe_modules/osx_sdk/examples/full.expected/ancient_version.json create mode 100644 recipes/recipe_modules/osx_sdk/examples/full.expected/automatic_version.json create mode 100644 recipes/recipe_modules/osx_sdk/examples/full.expected/explicit_version.json diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 437ca1920..fe8378e3e 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -693,18 +693,18 @@ uses the more generic [CACHE]/git path (LUCI world). — **def [initialize](/recipes/recipe_modules/infra_paths/api.py#11)(self):** ### *recipe_modules* / [osx\_sdk](/recipes/recipe_modules/osx_sdk) -[DEPS](/recipes/recipe_modules/osx_sdk/__init__.py#5): [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] +[DEPS](/recipes/recipe_modules/osx_sdk/__init__.py#5): [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] The `osx_sdk` module provides safe functions to access a semi-hermetic XCode installation. Available only to Google-run bots. -#### **class [OSXSDKApi](/recipes/recipe_modules/osx_sdk/api.py#24)([RecipeApi][recipe_engine/wkt/RecipeApi]):** +#### **class [OSXSDKApi](/recipes/recipe_modules/osx_sdk/api.py#35)([RecipeApi][recipe_engine/wkt/RecipeApi]):** API for using OS X SDK distributed via CIPD. -  **@contextmanager**
— **def [\_\_call\_\_](/recipes/recipe_modules/osx_sdk/api.py#37)(self, kind):** +  **@contextmanager**
— **def [\_\_call\_\_](/recipes/recipe_modules/osx_sdk/api.py#61)(self, kind):** Sets up the XCode SDK environment. @@ -751,6 +751,8 @@ Args: Raises: StepFailure or InfraFailure. + +— **def [initialize](/recipes/recipe_modules/osx_sdk/api.py#46)(self):** ### *recipe_modules* / [presubmit](/recipes/recipe_modules/presubmit) [DEPS](/recipes/recipe_modules/presubmit/__init__.py#11): [bot\_update](#recipe_modules-bot_update), [depot\_tools](#recipe_modules-depot_tools), [gclient](#recipe_modules-gclient), [git](#recipe_modules-git), [tryserver](#recipe_modules-tryserver), [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/cq][recipe_engine/recipe_modules/cq], [recipe\_engine/json][recipe_engine/recipe_modules/json], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/properties][recipe_engine/recipe_modules/properties], [recipe\_engine/python][recipe_engine/recipe_modules/python], [recipe\_engine/step][recipe_engine/recipe_modules/step] @@ -1086,4 +1088,5 @@ Move things around in a loop! [recipe_engine/recipe_modules/source_manifest]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c48c77264fea1fbe3bdc8352451a91b3dd529c96/README.recipes.md#recipe_modules-source_manifest [recipe_engine/recipe_modules/step]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c48c77264fea1fbe3bdc8352451a91b3dd529c96/README.recipes.md#recipe_modules-step [recipe_engine/recipe_modules/url]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c48c77264fea1fbe3bdc8352451a91b3dd529c96/README.recipes.md#recipe_modules-url +[recipe_engine/recipe_modules/version]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c48c77264fea1fbe3bdc8352451a91b3dd529c96/README.recipes.md#recipe_modules-version [recipe_engine/wkt/RecipeApi]: https://chromium.googlesource.com/infra/luci/recipes-py.git/+/c48c77264fea1fbe3bdc8352451a91b3dd529c96/recipe_engine/recipe_api.py#871 diff --git a/recipes/recipe_modules/osx_sdk/__init__.py b/recipes/recipe_modules/osx_sdk/__init__.py index 0b4ce5ddf..01e4eab28 100644 --- a/recipes/recipe_modules/osx_sdk/__init__.py +++ b/recipes/recipe_modules/osx_sdk/__init__.py @@ -9,6 +9,7 @@ DEPS = [ 'recipe_engine/path', 'recipe_engine/platform', 'recipe_engine/step', + 'recipe_engine/version', ] from recipe_engine.recipe_api import Property diff --git a/recipes/recipe_modules/osx_sdk/api.py b/recipes/recipe_modules/osx_sdk/api.py index b5cfa1bf0..92f650b4b 100644 --- a/recipes/recipe_modules/osx_sdk/api.py +++ b/recipes/recipe_modules/osx_sdk/api.py @@ -14,25 +14,49 @@ from recipe_engine import recipe_api # TODO(iannucci): replace this with something sane when PROPERTIES is # implemented with a proto message. _PROPERTY_DEFAULTS = { - 'sdk_version': '9c40b', - 'toolchain_pkg': 'infra/tools/mac_toolchain/${platform}', - 'toolchain_ver': 'git_revision:796d2b92cff93fc2059623ce0a66284373ceea0a', + 'toolchain_ver': 'git_revision:9a1adc55bf4a1173784da3ba2f8cb06421606748', } +# Rationalized from https://en.wikipedia.org/wiki/Xcode. +# +# Maps from OS version to the maximum supported version of Xcode for that OS. +# +# Keep this sorted by OS version. +_DEFAULT_VERSION_MAP = [ + ('10.12.6', '9c40b'), + ('10.13.2', '9f2000'), + ('10.13.6', '10b61'), + ('10.14.3', '10g8'), + ('10.14.4', '11b52'), +] + class OSXSDKApi(recipe_api.RecipeApi): """API for using OS X SDK distributed via CIPD.""" def __init__(self, sdk_properties, *args, **kwargs): super(OSXSDKApi, self).__init__(*args, **kwargs) + self._sdk_properties = _PROPERTY_DEFAULTS.copy() + self._sdk_properties.update(sdk_properties) + self._sdk_version = None + self._tool_pkg = self._sdk_properties['toolchain_pkg'] + self._tool_ver = self._sdk_properties['toolchain_ver'] - actual_props = _PROPERTY_DEFAULTS.copy() - actual_props.update(sdk_properties) + def initialize(self): + if not self.m.platform.is_mac: + return - self._sdk_version = actual_props['sdk_version'].lower() - self._tool_pkg = actual_props['toolchain_pkg'] - self._tool_ver = actual_props['toolchain_ver'] + 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): 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 new file mode 100644 index 000000000..24eb19b5d --- /dev/null +++ b/recipes/recipe_modules/osx_sdk/examples/full.expected/ancient_version.json @@ -0,0 +1,81 @@ +[ + { + "cmd": [ + "cipd", + "ensure", + "-root", + "[CACHE]/osx_sdk", + "-ensure-file", + "infra/tools/mac_toolchain/${platform} git_revision:9a1adc55bf4a1173784da3ba2f8cb06421606748", + "-json-output", + "/path/to/tmp/json" + ], + "infra_step": true, + "name": "ensure_installed", + "~followup_annotations": [ + "@@@STEP_LOG_LINE@json.output@{@@@", + "@@@STEP_LOG_LINE@json.output@ \"result\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"\": [@@@", + "@@@STEP_LOG_LINE@json.output@ {@@@", + "@@@STEP_LOG_LINE@json.output@ \"instance_id\": \"resolved-instance_id-of-git_revision:9a1\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"package\": \"infra/tools/mac_toolchain/resolved-platform\"@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@ ]@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@}@@@", + "@@@STEP_LOG_END@json.output@@@" + ] + }, + { + "cmd": [ + "[CACHE]/osx_sdk/mac_toolchain", + "install", + "-kind", + "mac", + "-xcode-version", + "9c40b", + "-output-dir", + "[CACHE]/osx_sdk/XCode.app" + ], + "infra_step": true, + "name": "install xcode" + }, + { + "cmd": [ + "sudo", + "xcode-select", + "--switch", + "[CACHE]/osx_sdk/XCode.app" + ], + "infra_step": true, + "name": "select XCode" + }, + { + "cmd": [ + "gn", + "gen", + "out/Release" + ], + "name": "gn" + }, + { + "cmd": [ + "ninja", + "-C", + "out/Release" + ], + "name": "ninja" + }, + { + "cmd": [ + "sudo", + "xcode-select", + "--reset" + ], + "infra_step": true, + "name": "reset XCode" + }, + { + "name": "$result" + } +] \ No newline at end of file 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 new file mode 100644 index 000000000..5b2f4df46 --- /dev/null +++ b/recipes/recipe_modules/osx_sdk/examples/full.expected/automatic_version.json @@ -0,0 +1,81 @@ +[ + { + "cmd": [ + "cipd", + "ensure", + "-root", + "[CACHE]/osx_sdk", + "-ensure-file", + "infra/tools/mac_toolchain/${platform} git_revision:9a1adc55bf4a1173784da3ba2f8cb06421606748", + "-json-output", + "/path/to/tmp/json" + ], + "infra_step": true, + "name": "ensure_installed", + "~followup_annotations": [ + "@@@STEP_LOG_LINE@json.output@{@@@", + "@@@STEP_LOG_LINE@json.output@ \"result\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"\": [@@@", + "@@@STEP_LOG_LINE@json.output@ {@@@", + "@@@STEP_LOG_LINE@json.output@ \"instance_id\": \"resolved-instance_id-of-git_revision:9a1\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"package\": \"infra/tools/mac_toolchain/resolved-platform\"@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@ ]@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@}@@@", + "@@@STEP_LOG_END@json.output@@@" + ] + }, + { + "cmd": [ + "[CACHE]/osx_sdk/mac_toolchain", + "install", + "-kind", + "mac", + "-xcode-version", + "11b52", + "-output-dir", + "[CACHE]/osx_sdk/XCode.app" + ], + "infra_step": true, + "name": "install xcode" + }, + { + "cmd": [ + "sudo", + "xcode-select", + "--switch", + "[CACHE]/osx_sdk/XCode.app" + ], + "infra_step": true, + "name": "select XCode" + }, + { + "cmd": [ + "gn", + "gen", + "out/Release" + ], + "name": "gn" + }, + { + "cmd": [ + "ninja", + "-C", + "out/Release" + ], + "name": "ninja" + }, + { + "cmd": [ + "sudo", + "xcode-select", + "--reset" + ], + "infra_step": true, + "name": "reset XCode" + }, + { + "name": "$result" + } +] \ No newline at end of file diff --git a/recipes/recipe_modules/osx_sdk/examples/full.expected/explicit_version.json b/recipes/recipe_modules/osx_sdk/examples/full.expected/explicit_version.json new file mode 100644 index 000000000..34650dc74 --- /dev/null +++ b/recipes/recipe_modules/osx_sdk/examples/full.expected/explicit_version.json @@ -0,0 +1,81 @@ +[ + { + "cmd": [ + "cipd", + "ensure", + "-root", + "[CACHE]/osx_sdk", + "-ensure-file", + "infra/tools/mac_toolchain/${platform} git_revision:9a1adc55bf4a1173784da3ba2f8cb06421606748", + "-json-output", + "/path/to/tmp/json" + ], + "infra_step": true, + "name": "ensure_installed", + "~followup_annotations": [ + "@@@STEP_LOG_LINE@json.output@{@@@", + "@@@STEP_LOG_LINE@json.output@ \"result\": {@@@", + "@@@STEP_LOG_LINE@json.output@ \"\": [@@@", + "@@@STEP_LOG_LINE@json.output@ {@@@", + "@@@STEP_LOG_LINE@json.output@ \"instance_id\": \"resolved-instance_id-of-git_revision:9a1\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"package\": \"infra/tools/mac_toolchain/resolved-platform\"@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@ ]@@@", + "@@@STEP_LOG_LINE@json.output@ }@@@", + "@@@STEP_LOG_LINE@json.output@}@@@", + "@@@STEP_LOG_END@json.output@@@" + ] + }, + { + "cmd": [ + "[CACHE]/osx_sdk/mac_toolchain", + "install", + "-kind", + "mac", + "-xcode-version", + "deadbeef", + "-output-dir", + "[CACHE]/osx_sdk/XCode.app" + ], + "infra_step": true, + "name": "install xcode" + }, + { + "cmd": [ + "sudo", + "xcode-select", + "--switch", + "[CACHE]/osx_sdk/XCode.app" + ], + "infra_step": true, + "name": "select XCode" + }, + { + "cmd": [ + "gn", + "gen", + "out/Release" + ], + "name": "gn" + }, + { + "cmd": [ + "ninja", + "-C", + "out/Release" + ], + "name": "ninja" + }, + { + "cmd": [ + "sudo", + "xcode-select", + "--reset" + ], + "infra_step": true, + "name": "reset XCode" + }, + { + "name": "$result" + } +] \ No newline at end of file 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 07ee384c1..3257d8b22 100644 --- a/recipes/recipe_modules/osx_sdk/examples/full.expected/mac.json +++ b/recipes/recipe_modules/osx_sdk/examples/full.expected/mac.json @@ -6,7 +6,7 @@ "-root", "[CACHE]/osx_sdk", "-ensure-file", - "infra/tools/mac_toolchain/${platform} git_revision:796d2b92cff93fc2059623ce0a66284373ceea0a", + "infra/tools/mac_toolchain/${platform} git_revision:9a1adc55bf4a1173784da3ba2f8cb06421606748", "-json-output", "/path/to/tmp/json" ], @@ -17,7 +17,7 @@ "@@@STEP_LOG_LINE@json.output@ \"result\": {@@@", "@@@STEP_LOG_LINE@json.output@ \"\": [@@@", "@@@STEP_LOG_LINE@json.output@ {@@@", - "@@@STEP_LOG_LINE@json.output@ \"instance_id\": \"resolved-instance_id-of-git_revision:796\", @@@", + "@@@STEP_LOG_LINE@json.output@ \"instance_id\": \"resolved-instance_id-of-git_revision:9a1\", @@@", "@@@STEP_LOG_LINE@json.output@ \"package\": \"infra/tools/mac_toolchain/resolved-platform\"@@@", "@@@STEP_LOG_LINE@json.output@ }@@@", "@@@STEP_LOG_LINE@json.output@ ]@@@", @@ -33,7 +33,7 @@ "-kind", "mac", "-xcode-version", - "9c40b", + "9f2000", "-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 0775384f4..bdb706647 100644 --- a/recipes/recipe_modules/osx_sdk/examples/full.py +++ b/recipes/recipe_modules/osx_sdk/examples/full.py @@ -20,3 +20,23 @@ def GenTests(api): for platform in ('linux', 'mac', 'win'): yield (api.test(platform) + api.platform.name(platform)) + + yield api.test( + 'explicit_version', + api.platform.name('mac'), + api.properties(**{'$depot_tools/osx_sdk': { + 'sdk_version': 'deadbeef', + }}) + ) + + yield api.test( + 'automatic_version', + api.platform.name('mac'), + api.platform.mac_release('10.14.5'), + ) + + yield api.test( + 'ancient_version', + api.platform.name('mac'), + api.platform.mac_release('10.1.0'), + )