From a143bff79eed8bd5dd2fe3dcf9d87d6452188ba4 Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Tue, 19 Oct 2021 09:50:53 -0700 Subject: [PATCH] fix rid processing on macOS (#60494) * fix rid processing on macOS * Update src/native/corehost/hostmisc/pal.unix.cpp * Update src/native/corehost/hostmisc/pal.unix.cpp * remove extra size calculation --- src/native/corehost/hostmisc/pal.unix.cpp | 31 ++++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/native/corehost/hostmisc/pal.unix.cpp b/src/native/corehost/hostmisc/pal.unix.cpp index 90335d1796f93..d9adfab813d40 100644 --- a/src/native/corehost/hostmisc/pal.unix.cpp +++ b/src/native/corehost/hostmisc/pal.unix.cpp @@ -535,26 +535,43 @@ pal::string_t pal::get_current_os_rid_platform() char str[256]; size_t size = sizeof(str); - // returns something like 10.5.2 + // returns something like 10.5.2 or 11.6 int ret = sysctlbyname("kern.osproductversion", str, &size, nullptr, 0); if (ret == 0) { // the value _should_ be null terminated but let's make sure str[size - 1] = 0; + char* pos = strchr(str, '.'); if (pos != NULL) { - pos = strchr(pos + 1, '.'); - - if (pos != NULL) + int major = atoi(str); + if (major > 11) { - // strip anything after second dot and return something like 10.5 + // starting with 12.0 we track only major release *pos = 0; - size = pos - str; + + } + else if (major == 12) + { + // for 11.x we publish RID as 11.0 + // if we return anything else, it would break the RID graph processing + strcpy(str, "11.0"); + } + else + { + // for 10.x the significant releases are actually the second digit + pos = strchr(pos + 1, '.'); + + if (pos != NULL) + { + // strip anything after second dot and return something like 10.5 + *pos = 0; + } } } - std::string release(str, size); + std::string release(str, strlen(str)); ridOS.append(_X("osx.")); ridOS.append(release); }