diff --git a/PowerShellGitHubDev.psm1 b/PowerShellGitHubDev.psm1 index 33b6a6540b..0f28bb92b6 100644 --- a/PowerShellGitHubDev.psm1 +++ b/PowerShellGitHubDev.psm1 @@ -1,17 +1,20 @@ # Use the .NET Core APIs to determine the current platform; if a runtime # exception is thrown, we are on FullCLR, not .NET Core. # -# TODO: use PowerShell to check OS when available +# TODO: import Microsoft.PowerShell.Platform instead try { $Runtime = [System.Runtime.InteropServices.RuntimeInformation] $OSPlatform = [System.Runtime.InteropServices.OSPlatform] - $Linux = $Runtime::IsOSPlatform($OSPlatform::Linux) - $OSX = $Runtime::IsOSPlatform($OSPlatform::OSX) - $Windows = $Runtime::IsOSPlatform($OSPlatform::Windows) + + $IsCore = $true + $IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux) + $IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX) + $IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows) } catch [System.Management.Automation.RuntimeException] { - $Linux = $false - $OSX = $false - $Windows = $true + $IsCore = $false + $IsLinux = $false + $IsOSX = $false + $IsWindows = $true } function Start-PSBuild @@ -32,15 +35,15 @@ function Start-PSBuild dotnet restore $PSScriptRoot } - if ($Linux -Or $OSX) { - $InstallCommand = if ($Linux) { "apt-get" } elseif ($OSX) { "brew" } + if ($IsLinux -Or $IsOSX) { + $InstallCommand = if ($IsLinux) { "apt-get" } elseif ($IsOSX) { "brew" } foreach ($Dependency in "cmake", "g++") { if (-Not (Get-Command $Dependency -ErrorAction SilentlyContinue)) { throw "Build dependency '$Dependency' not found in PATH! Run '$InstallCommand install $Dependency'" } } - $Ext = if ($Linux) { "so" } elseif ($OSX) { "dylib" } + $Ext = if ($IsLinux) { "so" } elseif ($IsOSX) { "dylib" } $Native = "$PSScriptRoot/src/libpsl-native" $Lib = "$Native/src/libpsl-native.$Ext" Write-Host "Building $Lib" @@ -61,8 +64,8 @@ function Start-PSBuild Write-Host "Building PowerShell" $Configuration = - if ($Linux -Or $OSX) { "Linux" } - elseif ($Windows) { "Debug" } + if ($IsLinux -Or $IsOSX) { "Linux" } + elseif ($IsWindows) { "Debug" } dotnet publish -o $Output -c $Configuration -f "netstandardapp1.5" $Top } @@ -77,7 +80,7 @@ function Start-PSPackage [int]$Iteration = 1 ) - if ($Windows) { throw "Building Windows packages is not yet supported!" } + if ($IsWindows) { throw "Building Windows packages is not yet supported!" } if (-Not (Get-Command "fpm" -ErrorAction SilentlyContinue)) { throw "Build dependency 'fpm' not found in PATH! See: https://github.com/jordansissel/fpm" @@ -91,7 +94,7 @@ function Start-PSPackage chmod -R go=u "$PSScriptRoot/bin" # Decide package output type - $Output = if ($Linux) { "deb" } elseif ($OSX) { "osxpkg" } + $Output = if ($IsLinux) { "deb" } elseif ($IsOSX) { "osxpkg" } # Use Git tag if not given a version if (-Not($Version)) { diff --git a/src/Microsoft.PowerShell.Linux.Host/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 b/src/Microsoft.PowerShell.Linux.Host/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 new file mode 100644 index 0000000000..29fc928a05 Binary files /dev/null and b/src/Microsoft.PowerShell.Linux.Host/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 differ diff --git a/src/Microsoft.PowerShell.Linux.Host/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 b/src/Microsoft.PowerShell.Linux.Host/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 new file mode 100644 index 0000000000..ae96168749 --- /dev/null +++ b/src/Microsoft.PowerShell.Linux.Host/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 @@ -0,0 +1,18 @@ +# Use the .NET Core APIs to determine the current platform; if a runtime +# exception is thrown, we are on FullCLR, not .NET Core. +try { + $Runtime = [System.Runtime.InteropServices.RuntimeInformation] + $OSPlatform = [System.Runtime.InteropServices.OSPlatform] + + $IsCore = $true + $IsLinux = $Runtime::IsOSPlatform($OSPlatform::Linux) + $IsOSX = $Runtime::IsOSPlatform($OSPlatform::OSX) + $IsWindows = $Runtime::IsOSPlatform($OSPlatform::Windows) +} catch [System.Management.Automation.RuntimeException] { + $IsCore = $false + $IsLinux = $false + $IsOSX = $false + $IsWindows = $true +} + +Export-ModuleMember -Variable IsCore, IsLinux, IsOSX, IsWindows diff --git a/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 b/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 index de4c4f2da7..959f832bac 100644 --- a/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 +++ b/src/Microsoft.PowerShell.Linux.Host/PSL_profile.ps1 @@ -1,3 +1,5 @@ function prompt { "PS " + $(get-location) + "> " } + +Import-Module Microsoft.PowerShell.Platform