Chromium Code Reviews| Index: recipe_modules/platform/api.py |
| diff --git a/recipe_modules/platform/api.py b/recipe_modules/platform/api.py |
| index ecd5f673cc345f4165edc7bc51bf8313e44e5bfa..35799e773b49c9adcaac419a0994585a0ac67968 100644 |
| --- a/recipe_modules/platform/api.py |
| +++ b/recipe_modules/platform/api.py |
| @@ -2,27 +2,9 @@ |
| # Use of this source code is governed under the Apache License, Version 2.0 |
| # that can be found in the LICENSE file. |
| -import sys |
| -import platform |
| - |
| from recipe_engine import recipe_api |
| -def norm_plat(plat): |
| - if plat.startswith('linux'): |
| - return 'linux' |
| - elif plat.startswith(('win', 'cygwin')): |
| - return 'win' |
| - elif plat.startswith(('darwin', 'mac')): |
| - return 'mac' |
| - else: # pragma: no cover |
| - raise ValueError('Don\'t understand platform "%s"' % plat) |
| - |
| - |
| -def norm_bits(arch): |
| - return 64 if '64' in str(arch) else 32 |
| - |
| - |
| class PlatformApi(recipe_api.RecipeApi): |
| """ |
| Provides host-platform-detection properties. |
| @@ -33,32 +15,7 @@ class PlatformApi(recipe_api.RecipeApi): |
| bits (int): Either 32 or 64. |
| """ |
| - def __init__(self, **kwargs): |
| - super(PlatformApi, self).__init__(**kwargs) |
| - self._name = norm_plat(sys.platform) |
| - |
| - self._arch = 'intel' |
| - self._bits = norm_bits(platform.machine()) |
| - |
| - if self._test_data.enabled: |
| - # Default to linux/64, unless test case says otherwise. |
| - self._name = norm_plat(self._test_data.get('name', 'linux')) |
| - self._bits = norm_bits(self._test_data.get('bits', 64)) |
| - else: # pragma: no cover |
| - # platform.machine is based on running kernel. It's possible to use 64-bit |
| - # kernel with 32-bit userland, e.g. to give linker slightly more memory. |
| - # Distinguish between different userland bitness by querying |
| - # the python binary. |
| - if (self._name == 'linux' and |
| - self._bits == 64 and |
| - platform.architecture()[0] == '32bit'): |
| - self._bits = 32 |
| - # On Mac, the inverse of the above is true: the kernel is 32-bit but the |
| - # CPU and userspace both are capable of running 64-bit programs. |
| - elif (self._name == 'mac' and |
| - self._bits == 32 and |
| - platform.architecture()[0] == '64bit'): |
| - self._bits = 64 |
| + platform_client = recipe_api.RequireClient('platform') |
| @property |
| def is_win(self): |
| @@ -74,19 +31,25 @@ class PlatformApi(recipe_api.RecipeApi): |
| @property |
| def name(self): |
| - return self._name |
| + if self._test_data.enabled: |
| + # Default to linux, unless test case says otherwise. |
| + return self.platform_client.norm_plat( |
| + self._test_data.get('name', 'linux')) |
|
iannucci
2016/10/15 00:39:45
Hm... I think you need to move this up a level; if
dnj
2016/10/15 00:59:27
Yeah. I think that would be a good manifestation o
iannucci
2016/10/15 01:04:09
fair enough, but I wouldn't leave this gap open to
|
| + return self.platform_client.name # pragma: no cover |
| @property |
| def bits(self): |
| # The returned bitness corresponds to the userland. If anyone ever wants |
| # to query for bitness of the kernel, another accessor should be added. |
| - return self._bits |
| + if self._test_data.enabled: |
| + # Default to 64-bit, unless test case says otherwise. |
| + return self.platform_client.norm_bits(self._test_data.get('bits', 64)) |
| + return self.platform_client.bits # pragma: no cover |
| @property |
| def arch(self): |
| - return self._arch |
| + return self.platform_client.arch |
| - @staticmethod |
| def normalize_platform_name(platform): |
| """One of python's sys.platform values -> 'win', 'linux' or 'mac'.""" |
| - return norm_plat(platform) # pragma: no cover |
| + return self.platform_client.norm_plat(platform) # pragma: no cover |