Pārlūkot izejas kodu

[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>
Robert Iannucci 1 gadu atpakaļ
vecāks
revīzija
2dbb3f399a

+ 4 - 4
recipes/README.recipes.md

@@ -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):**
 &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)
 ### *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
 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.
 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.
 Sets up the XCode SDK environment.
 
 
@@ -1135,10 +1135,10 @@ Raises:
 Move things around in a loop!
 Move things around in a loop!
 ### *recipes* / [osx\_sdk:examples/full](/recipes/recipe_modules/osx_sdk/examples/full.py)
 ### *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)
 ### *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]
 [DEPS](/recipes/recipe_modules/presubmit/examples/full.py#7): [presubmit](#recipe_modules-presubmit), [recipe\_engine/json][recipe_engine/recipe_modules/json]

+ 1 - 0
recipes/recipe_modules/osx_sdk/__init__.py

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

+ 15 - 8
recipes/recipe_modules/osx_sdk/api.py

@@ -52,14 +52,6 @@ class OSXSDKApi(recipe_api.RecipeApi):
 
 
     if 'sdk_version' in self._sdk_properties:
     if 'sdk_version' in self._sdk_properties:
       self._sdk_version = self._sdk_properties['sdk_version'].lower()
       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
   @contextmanager
   def __call__(self, kind):
   def __call__(self, kind):
@@ -133,6 +125,21 @@ class OSXSDKApi(recipe_api.RecipeApi):
     ef.add_package(self._tool_pkg, self._tool_ver)
     ef.add_package(self._tool_pkg, self._tool_ver)
     self.m.cipd.ensure(cache_dir, ef)
     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')
     sdk_app = cache_dir.join('XCode.app')
     self.m.step('install xcode', [
     self.m.step('install xcode', [
         cache_dir.join('mac_toolchain'), 'install',
         cache_dir.join('mac_toolchain'), 'install',

+ 11 - 0
recipes/recipe_modules/osx_sdk/examples/full.expected/ancient_version.json

@@ -28,6 +28,17 @@
       "@@@STEP_LOG_END@json.output@@@"
       "@@@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": [
     "cmd": [
       "[CACHE]/osx_sdk/mac_toolchain",
       "[CACHE]/osx_sdk/mac_toolchain",

+ 11 - 0
recipes/recipe_modules/osx_sdk/examples/full.expected/automatic_version.json

@@ -28,6 +28,17 @@
       "@@@STEP_LOG_END@json.output@@@"
       "@@@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": [
     "cmd": [
       "[CACHE]/osx_sdk/mac_toolchain",
       "[CACHE]/osx_sdk/mac_toolchain",

+ 12 - 1
recipes/recipe_modules/osx_sdk/examples/full.expected/mac.json

@@ -28,6 +28,17 @@
       "@@@STEP_LOG_END@json.output@@@"
       "@@@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": [
     "cmd": [
       "[CACHE]/osx_sdk/mac_toolchain",
       "[CACHE]/osx_sdk/mac_toolchain",
@@ -35,7 +46,7 @@
       "-kind",
       "-kind",
       "mac",
       "mac",
       "-xcode-version",
       "-xcode-version",
-      "9f2000",
+      "14c18",
       "-output-dir",
       "-output-dir",
       "[CACHE]/osx_sdk/XCode.app"
       "[CACHE]/osx_sdk/XCode.app"
     ],
     ],

+ 9 - 6
recipes/recipe_modules/osx_sdk/examples/full.py

@@ -5,10 +5,11 @@
 PYTHON_VERSION_COMPATIBILITY = 'PY3'
 PYTHON_VERSION_COMPATIBILITY = 'PY3'
 
 
 DEPS = [
 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(
   yield api.test(
       'automatic_version',
       'automatic_version',
       api.platform.name('mac'),
       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(
   yield api.test(
       'ancient_version',
       'ancient_version',
       api.platform.name('mac'),
       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')),
   )
   )