Skip to content
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

Log build info #772

Merged
merged 5 commits into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ docs/_repo/
docs/metadata/
*.zip

# Generated build info file
src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs

# quickbuild.exe
/VersionGeneratingLogs/
QLogs
Expand Down
49 changes: 48 additions & 1 deletion PowerShellEditorServices.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -142,6 +143,51 @@ task TestPowerShellApi -If { !$script:IsUnix } {
exec { & $script:dotnetExe restore .\src\PowerShellEditorServices\PowerShellEditorServices.csproj }
}

task CreateBuildInfo -Before Build {
$buildVersion = "<development-build>"
$buildOrigin = "<development>"

# 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:TF_BUILD)
{
$psd1Path = [System.IO.Path]::Combine($PSScriptRoot, "module", "PowerShellEditorServices", "PowerShellEditorServices.psd1")
$buildVersion = (Import-PowerShellDataFile -LiteralPath $psd1Path).Version
$buildOrigin = "VSTS"
Copy link
Member

Choose a reason for hiding this comment

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

Ehhem "Azure Pipelines" 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but felt we should keep things consistent and change it over all at once.

}

# 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) {
Expand Down Expand Up @@ -208,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\
Expand All @@ -216,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
Expand Down
3 changes: 3 additions & 0 deletions module/PowerShellEditorServices/Start-EditorServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/PowerShellEditorServices.Host/BuildInfo/BuildInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Microsoft.PowerShell.EditorServices.Host
{
public static class BuildInfo
{
public const string BuildVersion = "<unset>";
public const string BuildOrigin = "<unset>";
public static readonly System.DateTime? BuildTime = null;
}
}
58 changes: 29 additions & 29 deletions src/PowerShellEditorServices.Host/EditorServicesHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -140,39 +141,38 @@ 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;
string osVersion = RuntimeInformation.OSDescription;

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}"));
#else
""));
#endif
string buildTime = BuildInfo.BuildTime?.ToString("s", System.Globalization.CultureInfo.InvariantCulture) ?? "<unspecified>";

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);
}

/// <summary>
Expand Down
5 changes: 0 additions & 5 deletions src/PowerShellEditorServices/Console/ConsoleReadLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ 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();
return;
}

s_consoleProxy = new UnixConsoleOperations();
#else
s_consoleProxy = new WindowsConsoleOperations();
#endif
}

public ConsoleReadLine(PowerShellContext powerShellContext)
Expand Down
6 changes: 1 addition & 5 deletions src/PowerShellEditorServices/Language/LanguageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,10 @@ public async Task<FindReferencesResult> 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);
Expand Down
2 changes: 2 additions & 0 deletions src/PowerShellEditorServices/PowerShellEditorServices.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.2.0" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
Expand Down
6 changes: 1 addition & 5 deletions src/PowerShellEditorServices/Workspace/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
using System.IO;
using System.Security;
using System.Text;

#if CoreCLR
using System.Runtime.InteropServices;
#endif

namespace Microsoft.PowerShell.EditorServices
{
Expand Down Expand Up @@ -498,12 +495,11 @@ private string ResolveRelativeScriptPath(string baseFilePath, string relativePat
/// <returns>A file-scheme URI string with the drive colon unescaped.</returns>
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]) &&
Expand Down