From f1fa0f2546bf311aea611a7aa02a2be9e4d6118b Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Fri, 12 Oct 2018 16:00:17 -0700 Subject: [PATCH 1/5] Add default BuildInfo file --- src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs diff --git a/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs b/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs new file mode 100644 index 000000000..d3e9689a5 --- /dev/null +++ b/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs @@ -0,0 +1,9 @@ +namespace Microsoft.PowerShell.EditorServices.Host +{ + public static class BuildInfo + { + public const string BuildVersion = ""; + public const string BuildOrigin = ""; + public static readonly DateTime? BuildTime = null; + } +} From e8979ada864b704eca7127a02857c3c5312aae0d Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Fri, 12 Oct 2018 16:02:55 -0700 Subject: [PATCH 2/5] Correct default BuildInfo.cs --- src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs b/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs index d3e9689a5..181a42589 100644 --- a/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs +++ b/src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs @@ -4,6 +4,6 @@ public static class BuildInfo { public const string BuildVersion = ""; public const string BuildOrigin = ""; - public static readonly DateTime? BuildTime = null; + public static readonly System.DateTime? BuildTime = null; } } From 66b31046063dda3a9b4250709d7a96f2d9e12fa9 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Fri, 12 Oct 2018 16:31:19 -0700 Subject: [PATCH 3/5] Create build information and log at startup --- PowerShellEditorServices.build.ps1 | 46 ++++++++++++++ .../Start-EditorServices.ps1 | 3 + .../EditorServicesHost.cs | 60 ++++++++++--------- .../PowerShellEditorServices.Host.csproj | 2 + 4 files changed, 83 insertions(+), 28 deletions(-) diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index 375b2dce7..a53760804 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -20,6 +20,7 @@ $script:IsCIBuild = $env:APPVEYOR -ne $null $script:IsUnix = $PSVersionTable.PSEdition -and $PSVersionTable.PSEdition -eq "Core" -and !$IsWindows $script:TargetFrameworksParam = "/p:TargetFrameworks=\`"$(if (!$script:IsUnix) { "net451;" })netstandard1.6\`"" $script:SaveModuleSupportsAllowPrerelease = (Get-Command Save-Module).Parameters.ContainsKey("AllowPrerelease") +$script:BuildInfoPath = [System.IO.Path]::Combine($PSScriptRoot, "src", "PowerShellEditorServices.Host", "BuildInfo", "BuildInfo.cs") if ($PSVersionTable.PSEdition -ne "Core") { Add-Type -Assembly System.IO.Compression.FileSystem @@ -142,6 +143,51 @@ task TestPowerShellApi -If { !$script:IsUnix } { exec { & $script:dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj } } +task CreateBuildInfo -Before Build { + $buildVersion = "" + $buildOrigin = "" + + # Set build info fields on build platforms + if ($env:APPVEYOR) + { + $buildVersion = $env:APPVEYOR_BUILD_VERSION + $buildOrigin = if ($env:CI) { "AppVeyor CI" } else { "AppVeyor" } + } + elseif ($env:VSTS_BUILD) + { + $psd1Path = [System.IO.Path]::Combine($PSScriptRoot, "module", "PowerShellEditorServices", "PowerShellEditorServices.psd1") + $buildVersion = (Import-PowerShellDataFile -LiteralPath $psd1Path).Version + $buildOrigin = "VSTS" + } + + # Allow override of build info fields (except date) + if ($env:PSES_BUILD_VERSION) + { + $buildVersion = $env:PSES_BUILD_VERSION + } + + if ($env:PSES_BUILD_ORIGIN) + { + $buildOrigin = $env:PSES_BUILD_ORIGIN + } + + [string]$buildTime = [datetime]::Now.ToString("s", [System.Globalization.CultureInfo]::InvariantCulture) + + $buildInfoContents = @" +namespace Microsoft.PowerShell.EditorServices.Host +{ + public static class BuildInfo + { + public const string BuildVersion = "$buildVersion"; + public const string BuildOrigin = "$buildOrigin"; + public static readonly System.DateTime? BuildTime = System.DateTime.Parse("$buildTime"); + } +} +"@ + + Set-Content -LiteralPath $script:BuildInfoPath -Value $buildInfoContents -Force +} + task Build { exec { & $script:dotnetExe publish -c $Configuration .\src\PowerShellEditorServices.Host\PowerShellEditorServices.Host.csproj -f netstandard1.6 } if (!$script:IsUnix) { diff --git a/module/PowerShellEditorServices/Start-EditorServices.ps1 b/module/PowerShellEditorServices/Start-EditorServices.ps1 index c84ad537a..9d3970adf 100644 --- a/module/PowerShellEditorServices/Start-EditorServices.ps1 +++ b/module/PowerShellEditorServices/Start-EditorServices.ps1 @@ -243,6 +243,9 @@ function Set-NamedPipeMode { } } +LogSection "Console Encoding" +Log $OutputEncoding + # Add BundledModulesPath to $env:PSModulePath if ($BundledModulesPath) { $env:PSModulePath = $env:PSModulePath.TrimEnd([System.IO.Path]::PathSeparator) + [System.IO.Path]::PathSeparator + $BundledModulesPath diff --git a/src/PowerShellEditorServices.Host/EditorServicesHost.cs b/src/PowerShellEditorServices.Host/EditorServicesHost.cs index 324590877..711bbb555 100644 --- a/src/PowerShellEditorServices.Host/EditorServicesHost.cs +++ b/src/PowerShellEditorServices.Host/EditorServicesHost.cs @@ -19,6 +19,7 @@ using System.Management.Automation.Runspaces; using System.Reflection; using System.Threading.Tasks; +using System.Runtime.InteropServices; namespace Microsoft.PowerShell.EditorServices.Host { @@ -140,39 +141,42 @@ public void StartLogging(string logFilePath, LogLevel logLevel) .Build(); #if CoreCLR - FileVersionInfo fileVersionInfo = - FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location); - - // TODO #278: Need the correct dependency package for this to work correctly - //string osVersionString = RuntimeInformation.OSDescription; - //string processArchitecture = RuntimeInformation.ProcessArchitecture == Architecture.X64 ? "64-bit" : "32-bit"; - //string osArchitecture = RuntimeInformation.OSArchitecture == Architecture.X64 ? "64-bit" : "32-bit"; + FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().GetTypeInfo().Assembly.Location); #else - FileVersionInfo fileVersionInfo = - FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location); - string osVersionString = Environment.OSVersion.VersionString; - string processArchitecture = Environment.Is64BitProcess ? "64-bit" : "32-bit"; - string osArchitecture = Environment.Is64BitOperatingSystem ? "64-bit" : "32-bit"; + FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location); #endif - string newLine = Environment.NewLine; - - this.logger.Write( - LogLevel.Normal, - string.Format( - $"PowerShell Editor Services Host v{fileVersionInfo.FileVersion} starting (pid {Process.GetCurrentProcess().Id})..." + newLine + newLine + - " Host application details:" + newLine + newLine + - $" Name: {this.hostDetails.Name}" + newLine + - $" ProfileId: {this.hostDetails.ProfileId}" + newLine + - $" Version: {this.hostDetails.Version}" + newLine + -#if !CoreCLR - $" Arch: {processArchitecture}" + newLine + newLine + - " Operating system details:" + newLine + newLine + - $" Version: {osVersionString}" + newLine + - $" Arch: {osArchitecture}")); +#if CoreCLR + string osVersion = RuntimeInformation.OSDescription; #else - "")); + string osVersion = Environment.OSVersion.VersionString; #endif + + string buildTime = BuildInfo.BuildTime?.ToString("s", System.Globalization.CultureInfo.InvariantCulture) ?? ""; + + string logHeader = $@" +PowerShell Editor Services Host v{fileVersionInfo.FileVersion} starting (PID {Process.GetCurrentProcess().Id} + + Host application details: + + Name: {this.hostDetails.Name} + Version: {this.hostDetails.Version} + ProfileId: {this.hostDetails.ProfileId} + Arch: {RuntimeInformation.OSArchitecture} + + Operating system details: + + Version: {osVersion} + Arch: {RuntimeInformation.OSArchitecture} + + Build information: + + Version: {BuildInfo.BuildVersion} + Origin: {BuildInfo.BuildOrigin} + Date: {buildTime} +"; + + this.logger.Write(LogLevel.Normal, logHeader); } /// diff --git a/src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj b/src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj index 1874e2c20..2adaa3384 100644 --- a/src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj +++ b/src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj @@ -20,6 +20,8 @@ 6.0.0-alpha13 + + From a8f26d9ec2b2a1531fa98d5480dfd1ca000c22f5 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 15 Oct 2018 09:28:09 -0700 Subject: [PATCH 4/5] Ignore BuildInfo.cs from now on, since builds will change it --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b19f5bd8d..088159d3d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,9 @@ docs/_repo/ docs/metadata/ *.zip +# Generated build info file +src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs + # quickbuild.exe /VersionGeneratingLogs/ QLogs From d02ab610ac6dcd72e8b03dcce4fc2385f157bfe1 Mon Sep 17 00:00:00 2001 From: Robert Holt Date: Mon, 15 Oct 2018 11:42:27 -0700 Subject: [PATCH 5/5] Add System.Runtime.InteropServices to build --- PowerShellEditorServices.build.ps1 | 5 +++-- src/PowerShellEditorServices.Host/EditorServicesHost.cs | 4 ---- .../PowerShellEditorServices.Host.csproj | 2 -- src/PowerShellEditorServices/Console/ConsoleReadLine.cs | 5 ----- src/PowerShellEditorServices/Language/LanguageService.cs | 6 +----- .../PowerShellEditorServices.csproj | 2 ++ src/PowerShellEditorServices/Workspace/Workspace.cs | 6 +----- 7 files changed, 7 insertions(+), 23 deletions(-) diff --git a/PowerShellEditorServices.build.ps1 b/PowerShellEditorServices.build.ps1 index a53760804..2e5038fca 100644 --- a/PowerShellEditorServices.build.ps1 +++ b/PowerShellEditorServices.build.ps1 @@ -153,7 +153,7 @@ task CreateBuildInfo -Before Build { $buildVersion = $env:APPVEYOR_BUILD_VERSION $buildOrigin = if ($env:CI) { "AppVeyor CI" } else { "AppVeyor" } } - elseif ($env:VSTS_BUILD) + elseif ($env:TF_BUILD) { $psd1Path = [System.IO.Path]::Combine($PSScriptRoot, "module", "PowerShellEditorServices", "PowerShellEditorServices.psd1") $buildVersion = (Import-PowerShellDataFile -LiteralPath $psd1Path).Version @@ -254,6 +254,7 @@ task LayoutModule -After Build { New-Item -Force $PSScriptRoot\module\PowerShellEditorServices\bin\Core -Type Directory | Out-Null Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\netstandard1.6\publish\Serilog*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\ + Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\netstandard1.6\publish\System.Runtime.InteropServices.RuntimeInformation.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\ Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\ Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\netstandard1.6\UnixConsoleEcho.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Core\ @@ -262,11 +263,11 @@ task LayoutModule -After Build { if (!$script:IsUnix) { Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\net451\Serilog*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop + Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices\bin\$Configuration\net451\System.Runtime.InteropServices.RuntimeInformation.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\* -Filter Microsoft.PowerShell.EditorServices*.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\Newtonsoft.Json.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\UnixConsoleEcho.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ - Copy-Item -Force -Path $PSScriptRoot\src\PowerShellEditorServices.Host\bin\$Configuration\net451\publish\System.Runtime.InteropServices.RuntimeInformation.dll -Destination $PSScriptRoot\module\PowerShellEditorServices\bin\Desktop\ } # Copy Third Party Notices.txt to module folder diff --git a/src/PowerShellEditorServices.Host/EditorServicesHost.cs b/src/PowerShellEditorServices.Host/EditorServicesHost.cs index 711bbb555..0d1f7e8e4 100644 --- a/src/PowerShellEditorServices.Host/EditorServicesHost.cs +++ b/src/PowerShellEditorServices.Host/EditorServicesHost.cs @@ -146,11 +146,7 @@ public void StartLogging(string logFilePath, LogLevel logLevel) FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(this.GetType().Assembly.Location); #endif -#if CoreCLR string osVersion = RuntimeInformation.OSDescription; -#else - string osVersion = Environment.OSVersion.VersionString; -#endif string buildTime = BuildInfo.BuildTime?.ToString("s", System.Globalization.CultureInfo.InvariantCulture) ?? ""; diff --git a/src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj b/src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj index 2adaa3384..1874e2c20 100644 --- a/src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj +++ b/src/PowerShellEditorServices.Host/PowerShellEditorServices.Host.csproj @@ -20,8 +20,6 @@ 6.0.0-alpha13 - - diff --git a/src/PowerShellEditorServices/Console/ConsoleReadLine.cs b/src/PowerShellEditorServices/Console/ConsoleReadLine.cs index a3da640c7..7c518a718 100644 --- a/src/PowerShellEditorServices/Console/ConsoleReadLine.cs +++ b/src/PowerShellEditorServices/Console/ConsoleReadLine.cs @@ -29,8 +29,6 @@ internal class ConsoleReadLine #region Constructors static ConsoleReadLine() { - // Maybe we should just include the RuntimeInformation package for FullCLR? - #if CoreCLR if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { s_consoleProxy = new WindowsConsoleOperations(); @@ -38,9 +36,6 @@ static ConsoleReadLine() } s_consoleProxy = new UnixConsoleOperations(); - #else - s_consoleProxy = new WindowsConsoleOperations(); - #endif } public ConsoleReadLine(PowerShellContext powerShellContext) diff --git a/src/PowerShellEditorServices/Language/LanguageService.cs b/src/PowerShellEditorServices/Language/LanguageService.cs index e30c00b8a..f15e05bff 100644 --- a/src/PowerShellEditorServices/Language/LanguageService.cs +++ b/src/PowerShellEditorServices/Language/LanguageService.cs @@ -325,14 +325,10 @@ public async Task FindReferencesOfSymbol( // We want to look for references first in referenced files, hence we use ordered dictionary // TODO: File system case-sensitivity is based on filesystem not OS, but OS is a much cheaper heuristic -#if CoreCLR - // The RuntimeInformation.IsOSPlatform is not supported in .NET Framework var fileMap = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? new OrderedDictionary() : new OrderedDictionary(StringComparer.OrdinalIgnoreCase); -#else - var fileMap = new OrderedDictionary(StringComparer.OrdinalIgnoreCase); -#endif + foreach (ScriptFile file in referencedFiles) { fileMap.Add(file.FilePath, file); diff --git a/src/PowerShellEditorServices/PowerShellEditorServices.csproj b/src/PowerShellEditorServices/PowerShellEditorServices.csproj index 1fbf922e9..d5060ae8f 100644 --- a/src/PowerShellEditorServices/PowerShellEditorServices.csproj +++ b/src/PowerShellEditorServices/PowerShellEditorServices.csproj @@ -65,6 +65,8 @@ + + diff --git a/src/PowerShellEditorServices/Workspace/Workspace.cs b/src/PowerShellEditorServices/Workspace/Workspace.cs index edbe23d96..61caee3b7 100644 --- a/src/PowerShellEditorServices/Workspace/Workspace.cs +++ b/src/PowerShellEditorServices/Workspace/Workspace.cs @@ -10,10 +10,7 @@ using System.IO; using System.Security; using System.Text; - -#if CoreCLR using System.Runtime.InteropServices; -#endif namespace Microsoft.PowerShell.EditorServices { @@ -498,12 +495,11 @@ private string ResolveRelativeScriptPath(string baseFilePath, string relativePat /// A file-scheme URI string with the drive colon unescaped. private static string UnescapeDriveColon(string fileUri) { -#if CoreCLR if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return fileUri; } -#endif + // Check here that we have something like "file:///C%3A/" as a prefix (caller must check the file:// part) if (!(fileUri[7] == '/' && char.IsLetter(fileUri[8]) &&