winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 5598f7f6a1399e7b0d09255042563ea7058e3b1e
parent e4c1f25ffd6273c5d38a5a799d4399deba91e447
Author: JohnMcPMS <johnmcp@microsoft.com>
Date:   Sat,  9 May 2020 15:56:48 -0700

Change winget version determination and show OS and package info in --info (#115)

To make the version information that we display more consistent with our GitHub releases, this change updates the major & minor build numbers to be based solely on the version.h file that is used to set the actual binary version.  This is automatically updated for the GitHub builds by the script, but will need to be kept in sync to enable direct source pulls for now.  When inside a package, we do pull its build version as our own, to enable forward progress on the version number to be maintained in that manner.

Also changes the build script to use a two part version number, to put the build into the third part.

Finally, 'winget --info' will now print out the OS and package information, to better enable users to give debugging information.
Diffstat:
Mazure-pipelines.yml | 4++--
Msrc/AppInstallerCLICore/Commands/RootCommand.cpp | 14++++++++++++--
Msrc/AppInstallerCLIPackage/Package.appxmanifest | 2+-
Msrc/AppInstallerCommonCore/AppInstallerTelemetry.cpp | 13++++++++++++-
Msrc/AppInstallerCommonCore/Public/AppInstallerRuntime.h | 6++++++
Msrc/AppInstallerCommonCore/Runtime.cpp | 104++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Msrc/AppInstallerCommonCore/pch.h | 1+
Msrc/binver/Update-BinVer.ps1 | 12+++---------
Msrc/binver/binver/version.h | 8++++----
9 files changed, 134 insertions(+), 30 deletions(-)

diff --git a/azure-pipelines.yml b/azure-pipelines.yml @@ -78,8 +78,8 @@ jobs: inputs: targetType: 'inline' script: | - Add-AppxPackage AppInstallerCLIPackage_0.0.0.2_Test\Dependencies\x86\Microsoft.VCLibs.x86.14.00.Desktop.appx - Add-AppxPackage AppInstallerCLIPackage_0.0.0.2_Test\Dependencies\x64\Microsoft.VCLibs.x64.14.00.Desktop.appx + Add-AppxPackage AppInstallerCLIPackage_0.0.2.0_Test\Dependencies\x86\Microsoft.VCLibs.x86.14.00.Desktop.appx + Add-AppxPackage AppInstallerCLIPackage_0.0.2.0_Test\Dependencies\x64\Microsoft.VCLibs.x64.14.00.Desktop.appx workingDirectory: $(appxPackageDir) - task: VisualStudioTestPlatformInstaller@1 diff --git a/src/AppInstallerCLICore/Commands/RootCommand.cpp b/src/AppInstallerCLICore/Commands/RootCommand.cpp @@ -50,7 +50,17 @@ namespace AppInstaller::CLI { OutputIntroHeader(context.Reporter); - context.Reporter.Info() << std::endl << + auto info = context.Reporter.Info(); + + info << std::endl << + "Windows: " << Runtime::GetOSVersion() << std::endl; + + if (Runtime::IsRunningInPackagedContext()) + { + info << "Package: " << Runtime::GetPackageVersion() << std::endl; + }; + + info << std::endl << "Links:" << std::endl << " Privacy Statement: https://aka.ms/winget-privacy" << std::endl << " License agreement: https://aka.ms/winget-license" << std::endl << @@ -59,7 +69,7 @@ namespace AppInstaller::CLI } else if (context.Args.Contains(Execution::Args::Type::ListVersions)) { - context.Reporter.Info() << 'v' << Runtime::GetClientVersion() << ' ' << Resources::GetInstance().ResolveWingetString(L"PreviewVersion").c_str() << std::endl; + context.Reporter.Info() << 'v' << Runtime::GetClientVersion() << ' ' << Resources::GetInstance().ResolveWingetString(L"PreviewVersion"); } else { diff --git a/src/AppInstallerCLIPackage/Package.appxmanifest b/src/AppInstallerCLIPackage/Package.appxmanifest @@ -6,7 +6,7 @@ xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap uap3 uap5 rescap"> - <Identity Name="WinGetDevCLI" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" Version="0.0.0.2" /> + <Identity Name="WinGetDevCLI" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" Version="0.0.2.0" /> <Properties> <DisplayName>WinGet Dev CLI</DisplayName> <PublisherDisplayName>Microsoft Corporation</PublisherDisplayName> diff --git a/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp b/src/AppInstallerCommonCore/AppInstallerTelemetry.cpp @@ -95,6 +95,11 @@ namespace AppInstaller::Logging void TelemetryTraceLogger::LogStartup() noexcept { std::string version = Runtime::GetClientVersion(); + std::string packageVersion; + if (Runtime::IsRunningInPackagedContext()) + { + packageVersion = Runtime::GetPackageVersion(); + } if (g_IsTelemetryProviderEnabled) { @@ -103,12 +108,18 @@ namespace AppInstaller::Logging GetActivityId(), nullptr, TraceLoggingCountedString(version.c_str(), static_cast<ULONG>(version.size()), "Version"), + TraceLoggingCountedString(packageVersion.c_str(), static_cast<ULONG>(packageVersion.size()), "PackageVersion"), TraceLoggingWideString(GetCommandLineW(), "CommandlineArgs"), TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance|PDT_ProductAndServiceUsage), TraceLoggingKeyword(MICROSOFT_KEYWORD_CRITICAL_DATA)); } - AICLI_LOG(CLI, Info, << "WinGet, version [" << version << "], activity [" << *GetActivityId() << ']'); + AICLI_LOG(Core, Info, << "WinGet, version [" << version << "], activity [" << *GetActivityId() << ']'); + AICLI_LOG(Core, Info, << "OS: " << Runtime::GetOSVersion()); + if (Runtime::IsRunningInPackagedContext()) + { + AICLI_LOG(Core, Info, << "Package: " << packageVersion); + } } void TelemetryTraceLogger::LogCommand(std::string_view commandName) noexcept diff --git a/src/AppInstallerCommonCore/Public/AppInstallerRuntime.h b/src/AppInstallerCommonCore/Public/AppInstallerRuntime.h @@ -16,6 +16,12 @@ namespace AppInstaller::Runtime // Determines the current version of the client and returns it. std::string GetClientVersion(); + // Determines the current version of the package if running in a packaged context. + std::string GetPackageVersion(); + + // Gets a string representation of the OS version for debugging purposes. + std::string GetOSVersion(); + // Gets the path to the temp location. std::filesystem::path GetPathToTemp(); diff --git a/src/AppInstallerCommonCore/Runtime.cpp b/src/AppInstallerCommonCore/Runtime.cpp @@ -24,6 +24,49 @@ namespace AppInstaller::Runtime return (result != APPMODEL_ERROR_NO_PACKAGE); } + std::unique_ptr<byte[]> GetPACKAGE_ID() + { + UINT32 bufferLength = 0; + LONG gcpiResult = GetCurrentPackageId(&bufferLength, nullptr); + THROW_HR_IF(E_UNEXPECTED, gcpiResult != ERROR_INSUFFICIENT_BUFFER); + + std::unique_ptr<byte[]> buffer = std::make_unique<byte[]>(bufferLength); + + gcpiResult = GetCurrentPackageId(&bufferLength, buffer.get()); + if (FAILED_WIN32_LOG(gcpiResult)) + { + return {}; + } + + return buffer; + } + + // Gets the package name; only succeeds if running in a packaged context. + std::string GetPackageName() + { + std::unique_ptr<byte[]> buffer = GetPACKAGE_ID(); + if (!buffer) + { + return {}; + } + + PACKAGE_ID* packageId = reinterpret_cast<PACKAGE_ID*>(buffer.get()); + return Utility::ConvertToUTF8(packageId->name); + } + + // Gets the package version; only succeeds if running in a packaged context. + std::optional<PACKAGE_VERSION> GetPACKAGE_VERSION() + { + std::unique_ptr<byte[]> buffer = GetPACKAGE_ID(); + if (!buffer) + { + return {}; + } + + PACKAGE_ID* packageId = reinterpret_cast<PACKAGE_ID*>(buffer.get()); + return packageId->version; + } + #ifndef AICLI_DISABLE_TEST_HOOKS static std::filesystem::path s_Settings_TestHook_ForcedContainerPrepend; #endif @@ -144,32 +187,71 @@ namespace AppInstaller::Runtime if (IsRunningInPackagedContext()) { - UINT32 bufferLength = 0; - LONG gcpiResult = GetCurrentPackageId(&bufferLength, nullptr); - THROW_HR_IF(E_UNEXPECTED, gcpiResult != ERROR_INSUFFICIENT_BUFFER); + auto version = GetPACKAGE_VERSION(); - std::unique_ptr<byte[]> buffer = std::make_unique<byte[]>(bufferLength); - - gcpiResult = GetCurrentPackageId(&bufferLength, buffer.get()); - if (FAILED_WIN32_LOG(gcpiResult)) + if (!version) { return "error"s; } - PACKAGE_ID* packageId = reinterpret_cast<PACKAGE_ID*>(buffer.get()); - PACKAGE_VERSION& version = packageId->version; + std::ostringstream strstr; + strstr << VERSION_MAJOR << '.' << VERSION_MINOR << '.' << version->Build; + + return strstr.str(); + } + else + { + std::ostringstream strstr; + strstr << VERSION_MAJOR << '.' << VERSION_MINOR << '.' << VERSION_BUILD; + + return strstr.str(); + } + } + + std::string GetPackageVersion() + { + using namespace std::string_literals; + + if (IsRunningInPackagedContext()) + { + auto version = GetPACKAGE_VERSION(); + + if (!version) + { + return "error"s; + } std::ostringstream strstr; - strstr << version.Major << '.' << version.Minor << '.' << version.Build << '.' << version.Revision; + strstr << GetPackageName() << " v" << version->Major << '.' << version->Minor << '.' << version->Build << '.' << version->Revision; return strstr.str(); } else { - return VER_FILE_VERSION_STR; + return "none"; } } + std::string GetOSVersion() + { + winrt::Windows::System::Profile::AnalyticsInfo analyticsInfo{}; + auto versionInfo = analyticsInfo.VersionInfo(); + + uint64_t version = std::stoull(Utility::ConvertToUTF8(versionInfo.DeviceFamilyVersion())); + uint16_t parts[4]; + + for (size_t i = 0; i < ARRAYSIZE(parts); ++i) + { + parts[i] = version & 0xFFFF; + version = version >> 16; + } + + std::ostringstream strstr; + strstr << Utility::ConvertToUTF8(versionInfo.DeviceFamily()) << " v" << parts[3] << '.' << parts[2] << '.' << parts[1] << '.' << parts[0]; + + return strstr.str(); + } + std::filesystem::path GetPathToTemp() { std::filesystem::path result; diff --git a/src/AppInstallerCommonCore/pch.h b/src/AppInstallerCommonCore/pch.h @@ -23,6 +23,7 @@ #include <winrt/Windows.Security.Cryptography.h> #include <winrt/Windows.Storage.h> #include <winrt/Windows.Storage.Streams.h> +#include <winrt/Windows.System.Profile.h> #include <winrt/Windows.Web.Http.h> #include <winrt/Windows.Web.Http.Headers.h> #include <winrt/Windows.Web.Http.Filters.h> diff --git a/src/binver/Update-BinVer.ps1 b/src/binver/Update-BinVer.ps1 @@ -28,24 +28,22 @@ Write-Host "Git describe: $Local:GitDescribeText" $Local:Major = 0; $Local:Minor = 0; -$Local:Revision = 0; -if ($Local:GitDescribeText -match "v([0-9]+)\.([0-9]+)\.([0-9]+)") +if ($Local:GitDescribeText -match "v([0-9]+)\.([0-9]+)") { $Local:Major = $Matches[1] $Local:Minor = $Matches[2] - $Local:Revision = $Matches[3] } else { Write-Host "Describe did not match regex; using zeros" } -Write-Host "Using version: $Local:Major.$Local:Minor.$Local:Revision.$BuildVersion" +Write-Host "Using version: $Local:Major.$Local:Minor.$BuildVersion" if ($OutVar) { - Write-Host "##vso[task.setvariable variable=tag;isOutput=true]$Local:Major.$Local:Minor.$Local:Revision" + Write-Host "##vso[task.setvariable variable=tag;isOutput=true]$Local:Major.$Local:Minor" } if (![String]::IsNullOrEmpty($TargetFile)) @@ -65,10 +63,6 @@ if (![String]::IsNullOrEmpty($TargetFile)) { $Local:ResultContent += "#define VERSION_MINOR $Local:Minor"; } - elseif ($Local:line.StartsWith("#define VERSION_REVISION")) - { - $Local:ResultContent += "#define VERSION_REVISION $Local:Revision"; - } elseif ($Local:line.StartsWith("#define VERSION_BUILD")) { $Local:ResultContent += "#define VERSION_BUILD $BuildVersion"; diff --git a/src/binver/binver/version.h b/src/binver/binver/version.h @@ -2,16 +2,16 @@ #define STRINGIZE(s) STRINGIZE2(s) #define VERSION_MAJOR 0 -#define VERSION_MINOR 0 +#define VERSION_MINOR 1 +#define VERSION_BUILD 0 #define VERSION_REVISION 0 -#define VERSION_BUILD 2 #define VER_FILE_DESCRIPTION_STR "WinGet CLI" -#define VER_FILE_VERSION VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION, VERSION_BUILD +#define VER_FILE_VERSION VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION #define VER_FILE_VERSION_STR STRINGIZE(VERSION_MAJOR) \ "." STRINGIZE(VERSION_MINOR) \ - "." STRINGIZE(VERSION_REVISION) \ "." STRINGIZE(VERSION_BUILD) \ + "." STRINGIZE(VERSION_REVISION) \ #define VER_PRODUCTNAME_STR "WinGet CLI" #define VER_PRODUCT_VERSION VER_FILE_VERSION