[portability] Support unknown operating systems in gclient.

Detect the name of unknown operating systems using uname, if available,
since it doesn't append the operating system version.

Change-Id: Idab7bd0db65a8d424ec2fd48f06247405b6649e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4169240
Auto-Submit: Jonas Termansen <sortie@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
changes/40/4169240/2
Jonas Termansen 2 years ago committed by LUCI CQ
parent faf64f1f63
commit bf7eb5292c

@ -1410,7 +1410,13 @@ def merge_vars(result, new_vars):
def _detect_host_os():
return _PLATFORM_MAPPING[sys.platform]
if sys.platform in _PLATFORM_MAPPING:
return _PLATFORM_MAPPING[sys.platform]
try:
return os.uname().sysname.lower()
except AttributeError:
return sys.platform
class GitDependency(Dependency):

@ -634,7 +634,7 @@ def CheckCallAndFilter(args, print_stdout=False, filter_fn=None,
# If our stdout is a terminal, then pass in a psuedo-tty pipe to our
# subprocess when filtering its output. This makes the subproc believe
# it was launched from a terminal, which will preserve ANSI color codes.
os_type = GetMacWinAixOrLinux()
os_type = GetOperatingSystem()
if sys.stdout.isatty() and os_type != 'win' and os_type != 'aix':
pipe_reader, pipe_writer = os.openpty()
else:
@ -780,8 +780,8 @@ def FindFileUpwards(filename, path=None):
path = new_path
def GetMacWinAixOrLinux():
"""Returns 'mac', 'win', or 'linux', matching the current platform."""
def GetOperatingSystem():
"""Returns 'mac', 'win', 'linux', or the name of the current platform."""
if sys.platform.startswith(('cygwin', 'win')):
return 'win'
@ -794,7 +794,10 @@ def GetMacWinAixOrLinux():
if sys.platform.startswith('aix'):
return 'aix'
raise Error('Unknown platform: ' + sys.platform)
try:
return os.uname().sysname.lower()
except AttributeError:
return sys.platform
def GetGClientRootAndEntries(path=None):

@ -241,7 +241,7 @@ class MetricsCollector(object):
# Add metrics regarding environment information.
self.add('timestamp', int(time.time()))
self.add('python_version', metrics_utils.get_python_version())
self.add('host_os', gclient_utils.GetMacWinAixOrLinux())
self.add('host_os', gclient_utils.GetOperatingSystem())
self.add('host_arch', detect_host_arch.HostArch())
depot_tools_age = metrics_utils.get_repo_timestamp(DEPOT_TOOLS)

@ -63,7 +63,7 @@ class MetricsCollectorTest(unittest.TestCase):
mock.patch('metrics.metrics_utils.get_python_version',
lambda: '2.7.13').start()
mock.patch(
'metrics.gclient_utils.GetMacWinAixOrLinux', lambda: 'linux').start()
'metrics.gclient_utils.GetOperatingSystem', lambda: 'linux').start()
mock.patch('metrics.detect_host_arch.HostArch',
lambda: 'x86').start()
mock.patch('metrics_utils.get_repo_timestamp',

Loading…
Cancel
Save