Skip to content

Make ProcessInfo.operatingSystemVersionString useful on Linux and Windows #2824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 27, 2020
Merged

Make ProcessInfo.operatingSystemVersionString useful on Linux and Windows #2824

merged 4 commits into from
Aug 27, 2020

Conversation

gwynne
Copy link
Contributor

@gwynne gwynne commented Jun 15, 2020

  • On Linux, operatingSystemVersionString was previously consulting /proc/version_signature, and giving up immediately if that failed for any reason. This file is a duplicate of the value of uname -r and has not been present for several major releases of Ubuntu or Debian. The Linux case was rewritten to return the raw value of utsname.release, which corresponds to uname -r and is the value consulted already by the Linux implementation of operatingSystemVersion.

  • On Windows, operatingSystemVersionString was effectively completely unimplemented - falling back to CFCopySystemVersionString() on any non-Darwin platform is the same as having no fallback. The only non-deprecated way to retrieve a system version on Windows that I am aware of (at least without getting into the intensely dubious proposition of trying to invoke .NET classes from Swift) is the routine already being used by operatingSystemVersion: RtlGetVersion(). The boilerplate necessary for correctly loading ntdll.dll and retrieving the symbol from it was refactored out into a private accessor invoked by both operatingSystemVersion and operatingSystemVersionString. The former's behavior remains unchanged. The latter now constructs as reasonable a string as it can, based almost entirely on the contradictory and poorly-proofread reference table provided by Microsoft (the appropriate link is provided in the code).

@gwynne gwynne requested review from millenomi, compnerd and spevans June 15, 2020 14:08
@jakepetroules
Copy link
Contributor

The only non-deprecated way to retrieve a system version on Windows that I am aware of (at least without getting into the intensely dubious proposition of trying to invoke .NET classes from Swift) is the routine already being used by operatingSystemVersion: RtlGetVersion().

I have an unfortunate amount of experience with this and can confirm this is the right API to call. :D

@spevans
Copy link
Contributor

spevans commented Jun 15, 2020

@swift-ci please test

@spevans
Copy link
Contributor

spevans commented Jun 15, 2020

@compnerd can you please test this on windows when you get the chance, thanks.

case (6, 3) where osVersionInfo.wProductType == VER_NT_WORKSTATION: versionString += "Windows 8.1"
case (6, 3): versionString += "Windows Server 2012 R2" // We assume the "10,0" numbers in the table for this are a typo
case (10, 0) where osVersionInfo.wProductType == VER_NT_WORKSTATION: versionString += "Windows 10"
case (10, 0): versionString += "Windows Server 2019" // The table gives identical values for 2016 and 2019, so we just assume 2019 here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2016 is 10.0.14393 and 10.0.16299, 2019 is 10.0.17763. Versions are also identified by year and month, for example, "Windows Server 2016, version 1709") and IIRC you can get the latter part from the registry key HKLM\Software\Microsoft\Windows\Windows NT\CurrentVersion\ReleaseID for Windows 10 and up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion.

> reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v ReleaseID

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion
    ReleaseID    REG_SZ    2004

That is 10.0.19465 though, so, the mapping seems slightly confusing.

@compnerd
Copy link
Member

@millenomi
Copy link
Contributor

@gmittert this is pending a change still, correct?

@millenomi
Copy link
Contributor

My bad — that was intended to be @gwynne.

@gwynne
Copy link
Contributor Author

gwynne commented Aug 20, 2020

My bad — that was intended to be @gwynne.

Yeah, I haven't had a chance to circle back to this to do the fixups @spevans and I discussed yet, though I still plan to.

@millenomi
Copy link
Contributor

If you do and this stalls, please @ me.

@millenomi millenomi marked this pull request as draft August 24, 2020 21:30
gwynne added 2 commits August 25, 2020 02:03
…ays includes at minimum the OS name (if known), and looks for a distro name on Linux. Slightly improve the test case.
@gwynne
Copy link
Contributor Author

gwynne commented Aug 26, 2020

@spevans @millenomi (Finally) updated this with the changes that were discussed. Please let me know if I missed anything!

@compnerd Please test on Windows when you have an opportunity!

@gwynne
Copy link
Contributor Author

gwynne commented Aug 26, 2020

@swift-ci please test

@millenomi
Copy link
Contributor

Once you're done, make sure that you un-draft this PR so that I can merge it.

…ation for Android. Return a specific platform name when on any platform `#if os()` knows about that doesn't have a more specialized implementation.
@gwynne gwynne marked this pull request as ready for review August 26, 2020 22:52
@gwynne
Copy link
Contributor Author

gwynne commented Aug 26, 2020

@millenomi @spevans Assuming I haven't missed anything, and that CI passes, I think this is ready.

@gwynne
Copy link
Contributor Author

gwynne commented Aug 26, 2020

@swift-ci test

@millenomi
Copy link
Contributor

@swift-ci please test

@spevans
Copy link
Contributor

spevans commented Aug 27, 2020

@swift-ci test linux

@millenomi millenomi merged commit 4b137c8 into swiftlang:master Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants