From 5b3840f75316f1ca95bdf3e13fadc743a5c0449d Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 13:37:53 -0700 Subject: [PATCH 01/11] Deploy Platform module on all flavors --- .../Microsoft.PowerShell.Platform.psd1 | Bin .../Microsoft.PowerShell.Platform.psm1 | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename src/{Microsoft.PowerShell.CoreConsoleHost => }/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 (100%) rename src/{Microsoft.PowerShell.CoreConsoleHost => }/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 (100%) diff --git a/src/Microsoft.PowerShell.CoreConsoleHost/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 b/src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 similarity index 100% rename from src/Microsoft.PowerShell.CoreConsoleHost/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 rename to src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 diff --git a/src/Microsoft.PowerShell.CoreConsoleHost/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 b/src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 similarity index 100% rename from src/Microsoft.PowerShell.CoreConsoleHost/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 rename to src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 From 6f2110f38a18e65f76806e81bb7dda901ba767c2 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 14:49:56 -0700 Subject: [PATCH 02/11] Replace use of IsLinux with IsWindows So that IsLinux can stop being overloading for OS X. --- .../CoreCLR/CorePsExtensions.cs | 2 +- .../CoreCLR/CorePsPlatform.cs | 38 +++++++------------ .../namespaces/FileSystemContentStream.cs | 2 +- .../namespaces/FileSystemProvider.cs | 2 +- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs b/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs index ec69e4fa4..554564af4 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs @@ -828,7 +828,7 @@ namespace System.Management.Automation // Porting note: if not otherwise defined, map Windows environment // variables to their corresponding Linux counterparts - if (Platform.IsLinux() && String.IsNullOrEmpty(value)) + if (!Platform.IsWindows() && String.IsNullOrEmpty(value)) { switch (variable) { diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 51fc33d68..595521389 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -30,18 +30,6 @@ namespace System.Management.Automation /// internal static class Platform { - // this queries specifically for Linux or OS X because they are very similar - internal static bool IsLinux() - { -#if CORECLR - return RuntimeInformation.IsOSPlatform(OSPlatform.Linux) - || RuntimeInformation.IsOSPlatform(OSPlatform.OSX); -#else - // FullCLR doesn't have a Linux version - return false; -#endif - } - // this is specifically to query for Windows, everything else is considered to be non-Windows internal static bool IsWindows() { @@ -190,7 +178,7 @@ namespace System.Management.Automation internal static bool NonWindowsIsHardLink(FileSystemInfo fileInfo) { - if (IsLinux()) + if (!IsWindows()) { return LinuxPlatform.IsHardLink(fileInfo); } @@ -200,7 +188,7 @@ namespace System.Management.Automation internal static bool NonWindowsIsSymLink(FileSystemInfo fileInfo) { - if (IsLinux()) + if (!IsWindows()) { return LinuxPlatform.IsSymLink(fileInfo); } @@ -216,7 +204,7 @@ namespace System.Management.Automation internal static string NonWindowsInternalGetTarget(string path) { - if (IsLinux()) + if (!IsWindows()) { return LinuxPlatform.FollowSymLink(path); } @@ -229,7 +217,7 @@ namespace System.Management.Automation #if CORECLR internal static string NonWindowsGetFolderPath(SpecialFolder folder) { - if (IsLinux()) + if (!IsWindows()) { return LinuxPlatform.GetFolderPath(folder); } @@ -242,7 +230,7 @@ namespace System.Management.Automation internal static string NonWindowsInternalGetLinkType(FileSystemInfo fileInfo) { - if (IsLinux()) + if (!IsWindows()) { if (NonWindowsIsSymLink(fileInfo)) { @@ -263,7 +251,7 @@ namespace System.Management.Automation internal static bool NonWindowsCreateSymbolicLink(string path, string strTargetPath, bool isDirectory) { - if (IsLinux()) + if (!IsWindows()) { // Linux doesn't care if target is a directory or not return LinuxPlatform.CreateSymbolicLink(path, strTargetPath); @@ -276,7 +264,7 @@ namespace System.Management.Automation internal static bool NonWindowsCreateHardLink(string path, string strTargetPath) { - if (IsLinux()) + if (!IsWindows()) { return LinuxPlatform.CreateHardLink(path, strTargetPath); } @@ -288,7 +276,7 @@ namespace System.Management.Automation internal static void NonWindowsSetDate(DateTime dateToUse) { - if (IsLinux()) + if (!IsWindows()) { LinuxPlatform.SetDateInfoInternal date = new LinuxPlatform.SetDateInfoInternal(dateToUse); LinuxPlatform.SetDate(date); @@ -301,7 +289,7 @@ namespace System.Management.Automation internal static string NonWindowsGetDomainName() { - if (IsLinux()) + if (!IsWindows()) { string fullyQualifiedName = LinuxPlatform.Native.GetFullyQualifiedName(); if (string.IsNullOrEmpty(fullyQualifiedName)) @@ -326,7 +314,7 @@ namespace System.Management.Automation internal static string NonWindowsGetUserName() { - if (IsLinux()) + if (!IsWindows()) { return LinuxPlatform.UserName; } @@ -338,7 +326,7 @@ namespace System.Management.Automation internal static string NonWindowsGetMachineName() { - if (IsLinux()) + if (!IsWindows()) { return LinuxPlatform.HostName; } @@ -351,7 +339,7 @@ namespace System.Management.Automation // Hostname in this context seems to be the FQDN internal static string NonWindowsGetHostName() { - if (IsLinux()) + if (!IsWindows()) { string hostName = LinuxPlatform.Native.GetFullyQualifiedName(); if (string.IsNullOrEmpty(hostName)) @@ -370,7 +358,7 @@ namespace System.Management.Automation internal static bool NonWindowsIsExecutable(string path) { - if (IsLinux()) + if (!IsWindows()) { return LinuxPlatform.IsExecutable(path); } diff --git a/src/System.Management.Automation/namespaces/FileSystemContentStream.cs b/src/System.Management.Automation/namespaces/FileSystemContentStream.cs index 15df54f65..048bf992c 100644 --- a/src/System.Management.Automation/namespaces/FileSystemContentStream.cs +++ b/src/System.Management.Automation/namespaces/FileSystemContentStream.cs @@ -1195,7 +1195,7 @@ namespace Microsoft.PowerShell.Commands // Porting note: only UTF-8 is supported on Linux, which is not an SBCS if ((_currentEncoding.Equals(_oemEncoding) || _currentEncoding.Equals(_defaultAnsiEncoding)) - && !Platform.IsLinux()) + && Platform.IsWindows()) { NativeMethods.CPINFO cpInfo; if (NativeMethods.GetCPInfo((uint)_currentEncoding.CodePage, out cpInfo) && diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 50bd189a0..80c4ca96b 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -8105,7 +8105,7 @@ namespace Microsoft.PowerShell.Commands [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods")] private static string WinInternalGetLinkType(string filePath) { - if (Platform.IsLinux()) + if (!Platform.IsWindows()) { throw new Platform.PlatformNotSupportedException(); } From f5410a18cec880a6d3681103704b08d81f664796 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 14:54:41 -0700 Subject: [PATCH 03/11] Replace IsWindows method with property And add *correct* IsLinux and IsOSX properties. --- .../commands/management/Process.cs | 8 +- .../commands/utility/SetDateCommand.cs | 2 +- .../CoreCLR/CorePsExtensions.cs | 12 +-- .../CoreCLR/CorePsPlatform.cs | 91 ++++++++++++------- .../engine/CommandPathSearch.cs | 6 +- .../engine/DataStoreAdapterProvider.cs | 2 +- .../engine/InformationRecord.cs | 2 +- .../engine/InitialSessionState.cs | 2 +- .../engine/Modules/ModuleIntrinsics.cs | 4 +- .../engine/NativeCommandParameterBinder.cs | 2 +- .../engine/NativeCommandProcessor.cs | 4 +- .../engine/Utils.cs | 4 +- .../remoting/common/RemoteSessionNamedPipe.cs | 2 +- .../engine/remoting/fanin/WSManPlugin.cs | 4 +- .../remoting/fanin/WSManPluginFacade.cs | 4 +- .../remoting/fanin/WSManPluginShellSession.cs | 2 +- .../fanin/WSManPluginTransportManager.cs | 2 +- .../remoting/server/ServerPowerShellDriver.cs | 2 +- .../remoting/server/serverremotesession.cs | 2 +- .../namespaces/FileSystemContentStream.cs | 2 +- .../namespaces/FileSystemProvider.cs | 30 +++--- .../utils/PsUtils.cs | 4 +- 22 files changed, 110 insertions(+), 83 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs index 5d9fe6800..2b7211b0e 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs @@ -1362,7 +1362,7 @@ namespace Microsoft.PowerShell.Commands continue; } - if (Platform.IsWindows() && !Force) + if (Platform.IsWindows && !Force) { // Check if the process is owned by current user if (!IsProcessOwnedByCurrentUser(process)) @@ -2097,7 +2097,7 @@ namespace Microsoft.PowerShell.Commands } //LoadUserProfile. - if (Platform.IsWindows()) + if (Platform.IsWindows) { startInfo.LoadUserProfile = _loaduserprofile; } @@ -2193,7 +2193,7 @@ namespace Microsoft.PowerShell.Commands #endif //Starts the Process Process process; - if (Platform.IsWindows()) + if (Platform.IsWindows) { process = start(startInfo); } @@ -2238,7 +2238,7 @@ namespace Microsoft.PowerShell.Commands { if (!process.HasExited) { - if (Platform.IsWindows()) + if (Platform.IsWindows) { waithandle = new ManualResetEvent(false); diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetDateCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetDateCommand.cs index 1cd50f686..cf5868ce2 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetDateCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetDateCommand.cs @@ -117,7 +117,7 @@ namespace Microsoft.PowerShell.Commands if ( ShouldProcess( dateToUse.ToString() ) ) { - if (Platform.IsWindows()) + if (Platform.IsWindows) { #pragma warning disable 56523 diff --git a/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs b/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs index 554564af4..d66748dfa 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsExtensions.cs @@ -828,7 +828,7 @@ namespace System.Management.Automation // Porting note: if not otherwise defined, map Windows environment // variables to their corresponding Linux counterparts - if (!Platform.IsWindows() && String.IsNullOrEmpty(value)) + if (!Platform.IsWindows && String.IsNullOrEmpty(value)) { switch (variable) { @@ -1023,7 +1023,7 @@ namespace System.Management.Automation { get { - if (Platform.IsWindows()) + if (Platform.IsWindows) { return WinGetUserDomainName(); } @@ -1059,7 +1059,7 @@ namespace System.Management.Automation { get { - if (Platform.IsWindows()) + if (Platform.IsWindows) { return WinGetUserName(); } @@ -1088,7 +1088,7 @@ namespace System.Management.Automation { get { - if (Platform.IsWindows()) + if (Platform.IsWindows) { return WinGetMachineName(); } @@ -1108,7 +1108,7 @@ namespace System.Management.Automation { if (m_os == null) { - if (Platform.IsWindows()) + if (Platform.IsWindows) { m_os = WinOSVersion; } @@ -1179,7 +1179,7 @@ namespace System.Management.Automation /// private static string InternalGetFolderPath(SpecialFolder folder) { - if (!Platform.IsWindows()) + if (!Platform.IsWindows) { return Platform.NonWindowsGetFolderPath(folder); } diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 595521389..f6accdcf5 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -30,15 +30,42 @@ namespace System.Management.Automation /// internal static class Platform { - // this is specifically to query for Windows, everything else is considered to be non-Windows - internal static bool IsWindows() + + // Platform variables used to defined corresponding PowerShell built-in variables + public static const bool IsLinux { -#if CORECLR - return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); -#else - // FullCLR has only Windows version - return true; -#endif + get + { + #if CORECLR + return RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + #else + return false; + #endif + } + } + + public static const bool IsOSX + { + get + { + #if CORECLR + return RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + #else + return false; + #endif + } + } + + public static const bool IsWindows + { + get + { + #if CORECLR + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + #else + return true; + #endif + } } // true if cross-platform (always for this project) @@ -77,13 +104,13 @@ namespace System.Management.Automation internal static bool HasCom() { // TODO: catch exception from Type.IsComObject - return IsWindows(); + return IsWindows; } // The Antimalware Scan Interface is not supported on Linux internal static bool HasAmsi() { - return IsWindows(); + return IsWindows; } internal static bool UsesCodeSignedAssemblies() @@ -95,25 +122,25 @@ namespace System.Management.Automation // disconnected network drives on Windows internal static bool HasDriveAutoMounting() { - return IsWindows(); + return IsWindows; } // Linux does not have a registry internal static bool HasRegistrySupport() { - return IsWindows(); + return IsWindows; } // Linux does not have PowerShell execution policies internal static bool HasExecutionPolicy() { - return IsWindows(); + return IsWindows; } // Linux has a single rooted file system internal static bool HasSingleRootFilesystem() { - return !IsWindows(); + return !IsWindows; } // Linux has no notion of file shares. It has mount points @@ -128,7 +155,7 @@ namespace System.Management.Automation // the UNC equivalent of a "network drive" aka mount would be the mount itself internal static bool HasUNCSupport() { - return IsWindows(); + return IsWindows; } // Linux uses .net to query file attributes @@ -140,25 +167,25 @@ namespace System.Management.Automation // Linux does not have group policy support internal static bool HasGroupPolicySupport() { - return IsWindows(); + return IsWindows; } // non-windows does not have network drive support internal static bool HasNetworkDriveSupport() { - return IsWindows(); + return IsWindows; } // non-windows does not have reparse points internal static bool SupportsReparsePoints() { - return IsWindows(); + return IsWindows; } // non-windows does not support removing drives internal static bool SupportsRemoveDrive() { - return IsWindows(); + return IsWindows; } // Platform methods prefixed NonWindows are: @@ -178,7 +205,7 @@ namespace System.Management.Automation internal static bool NonWindowsIsHardLink(FileSystemInfo fileInfo) { - if (!IsWindows()) + if (!IsWindows) { return LinuxPlatform.IsHardLink(fileInfo); } @@ -188,7 +215,7 @@ namespace System.Management.Automation internal static bool NonWindowsIsSymLink(FileSystemInfo fileInfo) { - if (!IsWindows()) + if (!IsWindows) { return LinuxPlatform.IsSymLink(fileInfo); } @@ -204,7 +231,7 @@ namespace System.Management.Automation internal static string NonWindowsInternalGetTarget(string path) { - if (!IsWindows()) + if (!IsWindows) { return LinuxPlatform.FollowSymLink(path); } @@ -217,7 +244,7 @@ namespace System.Management.Automation #if CORECLR internal static string NonWindowsGetFolderPath(SpecialFolder folder) { - if (!IsWindows()) + if (!IsWindows) { return LinuxPlatform.GetFolderPath(folder); } @@ -230,7 +257,7 @@ namespace System.Management.Automation internal static string NonWindowsInternalGetLinkType(FileSystemInfo fileInfo) { - if (!IsWindows()) + if (!IsWindows) { if (NonWindowsIsSymLink(fileInfo)) { @@ -251,7 +278,7 @@ namespace System.Management.Automation internal static bool NonWindowsCreateSymbolicLink(string path, string strTargetPath, bool isDirectory) { - if (!IsWindows()) + if (!IsWindows) { // Linux doesn't care if target is a directory or not return LinuxPlatform.CreateSymbolicLink(path, strTargetPath); @@ -264,7 +291,7 @@ namespace System.Management.Automation internal static bool NonWindowsCreateHardLink(string path, string strTargetPath) { - if (!IsWindows()) + if (!IsWindows) { return LinuxPlatform.CreateHardLink(path, strTargetPath); } @@ -276,7 +303,7 @@ namespace System.Management.Automation internal static void NonWindowsSetDate(DateTime dateToUse) { - if (!IsWindows()) + if (!IsWindows) { LinuxPlatform.SetDateInfoInternal date = new LinuxPlatform.SetDateInfoInternal(dateToUse); LinuxPlatform.SetDate(date); @@ -289,7 +316,7 @@ namespace System.Management.Automation internal static string NonWindowsGetDomainName() { - if (!IsWindows()) + if (!IsWindows) { string fullyQualifiedName = LinuxPlatform.Native.GetFullyQualifiedName(); if (string.IsNullOrEmpty(fullyQualifiedName)) @@ -314,7 +341,7 @@ namespace System.Management.Automation internal static string NonWindowsGetUserName() { - if (!IsWindows()) + if (!IsWindows) { return LinuxPlatform.UserName; } @@ -326,7 +353,7 @@ namespace System.Management.Automation internal static string NonWindowsGetMachineName() { - if (!IsWindows()) + if (!IsWindows) { return LinuxPlatform.HostName; } @@ -339,7 +366,7 @@ namespace System.Management.Automation // Hostname in this context seems to be the FQDN internal static string NonWindowsGetHostName() { - if (!IsWindows()) + if (!IsWindows) { string hostName = LinuxPlatform.Native.GetFullyQualifiedName(); if (string.IsNullOrEmpty(hostName)) @@ -358,7 +385,7 @@ namespace System.Management.Automation internal static bool NonWindowsIsExecutable(string path) { - if (!IsWindows()) + if (!IsWindows) { return LinuxPlatform.IsExecutable(path); } diff --git a/src/System.Management.Automation/engine/CommandPathSearch.cs b/src/System.Management.Automation/engine/CommandPathSearch.cs index 0c4edaf8f..bdb64e59d 100644 --- a/src/System.Management.Automation/engine/CommandPathSearch.cs +++ b/src/System.Management.Automation/engine/CommandPathSearch.cs @@ -56,7 +56,7 @@ namespace System.Management.Automation // turn the command name into a pattern and then match against extensions in PATHEXT. // The old code would enumerate the file system many more times, once per possible extension. // Porting note: this is wrong on Linux, where we don't depend on extensions - if (Platform.IsWindows()) + if (Platform.IsWindows) { commandName = commandName + ".*"; } @@ -478,7 +478,7 @@ namespace System.Management.Automation for (int i = 0; i < baseNames.Length; i++) { if (name.Equals(baseNames[i], StringComparison.OrdinalIgnoreCase) - || (!Platform.IsWindows() && Platform.NonWindowsIsExecutable(name))) + || (!Platform.IsWindows && Platform.NonWindowsIsExecutable(name))) { if (result == null) result = new Collection(); @@ -505,7 +505,7 @@ namespace System.Management.Automation foreach (var fileName in fileNames) { if (fileName.EndsWith(allowedExt, StringComparison.OrdinalIgnoreCase) - || (!Platform.IsWindows() && Platform.NonWindowsIsExecutable(fileName))) + || (!Platform.IsWindows && Platform.NonWindowsIsExecutable(fileName))) { if (result == null) result = new Collection(); diff --git a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs index 12d63374d..a8f5c30ab 100644 --- a/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs +++ b/src/System.Management.Automation/engine/DataStoreAdapterProvider.cs @@ -499,7 +499,7 @@ namespace System.Management.Automation // TODO:PSL // this is probably not right here - if (implementingType == typeof(Microsoft.PowerShell.Commands.FileSystemProvider) && !Platform.IsWindows()) + if (implementingType == typeof(Microsoft.PowerShell.Commands.FileSystemProvider) && !Platform.IsWindows) { volumeSeparatedByColon = false; } diff --git a/src/System.Management.Automation/engine/InformationRecord.cs b/src/System.Management.Automation/engine/InformationRecord.cs index b698501db..34546787e 100644 --- a/src/System.Management.Automation/engine/InformationRecord.cs +++ b/src/System.Management.Automation/engine/InformationRecord.cs @@ -38,7 +38,7 @@ namespace System.Management.Automation this.TimeGenerated = DateTime.Now; this.Tags = new List(); - if (Platform.IsWindows()) + if (Platform.IsWindows) { this.User = System.Security.Principal.WindowsIdentity.GetCurrent().Name; } diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 4e853cbb2..e4bc81a63 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -4724,7 +4724,7 @@ End /// internal static string GetClearHostFunctionText() { - if (Platform.IsWindows()) + if (Platform.IsWindows) { return @" $RawUI = $Host.UI.RawUI diff --git a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs index ca0afb099..3243b074d 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs @@ -582,7 +582,7 @@ namespace System.Management.Automation // module using ""System32" in the key. // Porting note: psHome cannot be lower-cased on case sensitive file systems - if (Platform.IsWindows()) + if (Platform.IsWindows) { psHome = psHome.ToLowerInvariant().Replace("\\syswow64\\", "\\system32\\"); } @@ -600,7 +600,7 @@ namespace System.Management.Automation /// internal static string GetDscModulePath() { - if (!Platform.IsWindows()) + if (!Platform.IsWindows) { return string.Empty; } diff --git a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs index b9636c6a0..50a4675cc 100644 --- a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs +++ b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs @@ -131,7 +131,7 @@ namespace System.Management.Automation { var rawArgs = arguments.ToString(); - if (tracer.IsEnabled && Platform.IsWindows()) + if (tracer.IsEnabled && Platform.IsWindows) { // This tracing really shouldn't be in the property getter... tracer.WriteLine("Raw argument string: {0}", rawArgs); diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index 9fc15982d..fb025bce9 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -1026,8 +1026,8 @@ namespace System.Management.Automation // On Windows, check the extension list and see if we should try to execute this directly. // Otherwise, use the platform library to check executability - if ((Platform.IsWindows() && ValidateExtension(this.Path)) - || (!Platform.IsWindows() && Platform.NonWindowsIsExecutable(this.Path))) + if ((Platform.IsWindows && ValidateExtension(this.Path)) + || (!Platform.IsWindows && Platform.NonWindowsIsExecutable(this.Path))) { startInfo.UseShellExecute = false; if (redirectInput) diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index d32c79f4d..1c9edc414 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -607,7 +607,7 @@ namespace System.Management.Automation /// Profile uses this to control profile loading. /// internal static string ProductNameForDirectory = - Platform.IsWindows() ? "WindowsPowerShell" : Platform.ProductNameForDirectory; + Platform.IsWindows ? "WindowsPowerShell" : Platform.ProductNameForDirectory; /// /// The name of the subdirectory that contains packages. @@ -964,7 +964,7 @@ namespace System.Management.Automation // SecurityPrincipal API of .net for now assume Linux // users have no concept of "Administrator" for now and // specifically do not map to a check for root user - if (Platform.IsWindows()) + if (Platform.IsWindows) { System.Security.Principal.WindowsIdentity currentIdentity = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(currentIdentity); diff --git a/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs b/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs index 0c6aaa43e..89bfdf878 100644 --- a/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs +++ b/src/System.Management.Automation/engine/remoting/common/RemoteSessionNamedPipe.cs @@ -534,7 +534,7 @@ namespace System.Management.Automation.Remoting // All PowerShell instances will start with the named pipe // and listner created and running. - if (Platform.IsWindows()) + if (Platform.IsWindows) { IPCNamedPipeServerEnabled = true; } diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs index c9fdc61a2..a5d9e3ed2 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPlugin.cs @@ -283,7 +283,7 @@ namespace System.Management.Automation.Remoting // to verify here. WSManPluginServerTransportManager serverTransportMgr; - if (Platform.IsWindows()) + if (Platform.IsWindows) { serverTransportMgr = new WSManPluginServerTransportManager(BaseTransportManager.DefaultFragmentSize, new PSRemotingCryptoHelperServer()); } @@ -390,7 +390,7 @@ namespace System.Management.Automation.Remoting // Wrap the provided handle so it can be passed to the registration function EventWaitHandle eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset); - if (Platform.IsWindows()) + if (Platform.IsWindows) { SafeWaitHandle safeWaitHandle = new SafeWaitHandle(requestDetails.shutdownNotificationHandle, false); // Owned by WinRM ClrFacade.SetSafeWaitHandle(eventWaitHandle, safeWaitHandle); diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs index cf55c288c..ff39a87d0 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginFacade.cs @@ -326,7 +326,7 @@ namespace System.Management.Automation.Remoting this.shutdownPluginGCHandle = GCHandle.Alloc(shutdownPlugin); unmanagedStruct.wsManPluginShutdownPluginCallbackNative = Marshal.GetFunctionPointerForDelegate(shutdownPlugin); } - if(!Platform.IsWindows()) + if(!Platform.IsWindows) { WSMPluginOperationShutdownDelegate pluginShutDownDelegate = new WSMPluginOperationShutdownDelegate(WSManPluginManagedEntryWrapper.WSManPSShutdown); this.WSMPluginOperationShutdownGCHandle = GCHandle.Alloc(pluginShutDownDelegate); @@ -351,7 +351,7 @@ namespace System.Management.Automation.Remoting this.pluginSignalGCHandle.Free(); this.pluginConnectGCHandle.Free(); this.shutdownPluginGCHandle.Free(); - if(!Platform.IsWindows()) + if(!Platform.IsWindows) { this.WSMPluginOperationShutdownGCHandle.Free(); } diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginShellSession.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginShellSession.cs index b311c2f39..41913739b 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginShellSession.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginShellSession.cs @@ -265,7 +265,7 @@ namespace System.Management.Automation.Remoting //RACE TO BE FIXED - As soon as this API is called, WinRM service will send CommandResponse back and Signal is expected anytime // If Signal comes and executes before registering the notification handle, cleanup will be messed result = WSManNativeApi.WSManPluginReportContext(creationRequestDetails.unmanagedHandle, 0, creationRequestDetails.unmanagedHandle); - if (Platform.IsWindows() && (WSManPluginConstants.ExitCodeSuccess == result)) + if (Platform.IsWindows && (WSManPluginConstants.ExitCodeSuccess == result)) { registeredShutdownNotification = 1; diff --git a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginTransportManager.cs b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginTransportManager.cs index 9db15cbf3..7c49a68bd 100644 --- a/src/System.Management.Automation/engine/remoting/fanin/WSManPluginTransportManager.cs +++ b/src/System.Management.Automation/engine/remoting/fanin/WSManPluginTransportManager.cs @@ -332,7 +332,7 @@ namespace System.Management.Automation.Remoting isRequestPending = true; this.requestDetails = requestDetails; - if (Platform.IsWindows()) + if (Platform.IsWindows) { // Wrap the provided handle so it can be passed to the registration function SafeWaitHandle safeWaitHandle = new SafeWaitHandle(requestDetails.shutdownNotificationHandle, false); // Owned by WinRM diff --git a/src/System.Management.Automation/engine/remoting/server/ServerPowerShellDriver.cs b/src/System.Management.Automation/engine/remoting/server/ServerPowerShellDriver.cs index 692aeaf80..0f1e57ede 100644 --- a/src/System.Management.Automation/engine/remoting/server/ServerPowerShellDriver.cs +++ b/src/System.Management.Automation/engine/remoting/server/ServerPowerShellDriver.cs @@ -336,7 +336,7 @@ namespace System.Management.Automation // Flow the impersonation policy to pipeline execution thread // only if the current thread is impersonated (Delegation is // also a kind of impersonation). - if (Platform.IsWindows()) + if (Platform.IsWindows) { WindowsIdentity currentThreadIdentity = WindowsIdentity.GetCurrent(); switch (currentThreadIdentity.ImpersonationLevel) diff --git a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs index d1e7d7c41..d2e5b8955 100644 --- a/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs +++ b/src/System.Management.Automation/engine/remoting/server/serverremotesession.cs @@ -170,7 +170,7 @@ namespace System.Management.Automation.Remoting _senderInfo = senderInfo; _configProviderId = configurationProviderId; _initParameters = initializationParameters; - if (Platform.IsWindows()) + if (Platform.IsWindows) { _cryptoHelper = (PSRemotingCryptoHelperServer)transportManager.CryptoHelper; _cryptoHelper.Session = this; diff --git a/src/System.Management.Automation/namespaces/FileSystemContentStream.cs b/src/System.Management.Automation/namespaces/FileSystemContentStream.cs index 048bf992c..8539cb77e 100644 --- a/src/System.Management.Automation/namespaces/FileSystemContentStream.cs +++ b/src/System.Management.Automation/namespaces/FileSystemContentStream.cs @@ -1195,7 +1195,7 @@ namespace Microsoft.PowerShell.Commands // Porting note: only UTF-8 is supported on Linux, which is not an SBCS if ((_currentEncoding.Equals(_oemEncoding) || _currentEncoding.Equals(_defaultAnsiEncoding)) - && Platform.IsWindows()) + && Platform.IsWindows) { NativeMethods.CPINFO cpInfo; if (NativeMethods.GetCPInfo((uint)_currentEncoding.CodePage, out cpInfo) && diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 80c4ca96b..ab14d7cf7 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -490,7 +490,7 @@ namespace Microsoft.PowerShell.Commands private void MapNetworkDrive(PSDriveInfo drive) { // Porting note: mapped network drives are only supported on Windows - if (Platform.IsWindows()) + if (Platform.IsWindows) { WinMapNetworkDrive(drive); } @@ -992,7 +992,7 @@ namespace Microsoft.PowerShell.Commands // Porting notes: on the non-Windows platforms, the drive never // uses : as a separator between drive and path - if (!Platform.IsWindows()) + if (!Platform.IsWindows) { newPSDriveInfo.VolumeSeparatedByColon = false; } @@ -1505,7 +1505,7 @@ namespace Microsoft.PowerShell.Commands { DirectoryInfo directory = new DirectoryInfo(path); - if (!Platform.IsWindows() && Platform.NonWindowsIsSymLink(directory)) + if (!Platform.IsWindows && Platform.NonWindowsIsSymLink(directory)) { // For Linux, treat symlink to directories like a file WriteItemObject(directory, path, false); @@ -2210,7 +2210,7 @@ namespace Microsoft.PowerShell.Commands if(itemType == ItemType.SymbolicLink) { - if (Platform.IsWindows()) + if (Platform.IsWindows) { success = WinCreateSymbolicLink(path,strTargetPath,isDirectory); } @@ -2221,7 +2221,7 @@ namespace Microsoft.PowerShell.Commands } else if(itemType == ItemType.HardLink) { - if (Platform.IsWindows()) + if (Platform.IsWindows) { success = WinCreateHardLink(path,strTargetPath); } @@ -7981,7 +7981,7 @@ namespace Microsoft.PowerShell.Commands if (fileSysInfo != null) { - if (Platform.IsWindows()) + if (Platform.IsWindows) { using (SafeFileHandle handle = OpenReparsePoint(fileSysInfo.FullName, FileDesiredAccess.GenericRead)) { @@ -8018,7 +8018,7 @@ namespace Microsoft.PowerShell.Commands private static List InternalGetTarget(string filePath) { var links = new List(); - if (!Platform.IsWindows()) + if (!Platform.IsWindows) { string link = Platform.NonWindowsInternalGetTarget(filePath); if (!String.IsNullOrEmpty(link)) @@ -8092,7 +8092,7 @@ namespace Microsoft.PowerShell.Commands private static string InternalGetLinkType(FileSystemInfo fileInfo) { - if (Platform.IsWindows()) + if (Platform.IsWindows) { return WinInternalGetLinkType(fileInfo.FullName); } @@ -8105,7 +8105,7 @@ namespace Microsoft.PowerShell.Commands [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods")] private static string WinInternalGetLinkType(string filePath) { - if (!Platform.IsWindows()) + if (!Platform.IsWindows) { throw new Platform.PlatformNotSupportedException(); } @@ -8169,7 +8169,7 @@ namespace Microsoft.PowerShell.Commands internal static bool IsHardLink(FileSystemInfo fileInfo) { - if (Platform.IsWindows()) + if (Platform.IsWindows) return WinIsHardLink(fileInfo); else return Platform.NonWindowsIsHardLink(fileInfo); @@ -8177,7 +8177,7 @@ namespace Microsoft.PowerShell.Commands internal static bool IsReparsePoint(FileSystemInfo fileInfo) { - if (Platform.IsWindows()) + if (Platform.IsWindows) { // Note that this class also has a enum called FileAttributes, so use fully qualified name return (fileInfo.Attributes & System.IO.FileAttributes.ReparsePoint) @@ -8228,7 +8228,7 @@ namespace Microsoft.PowerShell.Commands internal static bool IsHardLink(ref IntPtr handle) { - if (Platform.IsWindows()) + if (Platform.IsWindows) return WinIsHardLink(ref handle); else return Platform.NonWindowsIsHardLink(ref handle); @@ -8256,7 +8256,7 @@ namespace Microsoft.PowerShell.Commands private static string InternalGetTarget(SafeFileHandle handle) { - if (Platform.IsWindows()) + if (Platform.IsWindows) { return WinInternalGetTarget(handle); } @@ -8336,7 +8336,7 @@ namespace Microsoft.PowerShell.Commands { // this is a purely Windows specific feature, no feature flag // used for that reason - if (Platform.IsWindows()) + if (Platform.IsWindows) { return WinCreateJunction(path,target); } @@ -8420,7 +8420,7 @@ namespace Microsoft.PowerShell.Commands if (!String.IsNullOrEmpty(junctionPath)) { - if (!Platform.IsWindows()) + if (!Platform.IsWindows) { // For non-Windows platform, treat it as a file. Just delete it. try diff --git a/src/System.Management.Automation/utils/PsUtils.cs b/src/System.Management.Automation/utils/PsUtils.cs index deb01a119..78b0b54c1 100644 --- a/src/System.Management.Automation/utils/PsUtils.cs +++ b/src/System.Management.Automation/utils/PsUtils.cs @@ -586,7 +586,7 @@ namespace System.Management.Automation internal static string GetHostName() { // Note: non-windows CoreCLR does not support System.Net yet - if (Platform.IsWindows()) + if (Platform.IsWindows) { return WinGetHostName(); } @@ -612,7 +612,7 @@ namespace System.Management.Automation internal static uint GetNativeThreadId() { - if (Platform.IsWindows()) + if (Platform.IsWindows) { return WinGetNativeThreadId(); } From 49066d212a1f93fc395b68e2f2c9db13fb6b575a Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 15:02:51 -0700 Subject: [PATCH 04/11] Replace IsX method with IsCore property --- .../CoreCLR/CorePsPlatform.cs | 20 +++++++++---------- .../DisplayDatabase/typeDataXmlLoader.cs | 2 +- .../engine/CommandDiscovery.cs | 2 +- .../engine/InitialSessionState.cs | 2 +- .../engine/Modules/ModuleIntrinsics.cs | 2 +- .../engine/SecurityManagerBase.cs | 2 +- .../engine/Utils.cs | 4 ++-- .../security/SecuritySupport.cs | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index f6accdcf5..26847b617 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -68,16 +68,16 @@ namespace System.Management.Automation } } - // true if cross-platform (always for this project) - internal static bool IsX() + public static const bool IsCore { -#if CORECLR - // CoreCLR version is cross-platform - return true; -#else - // FullCLR is not cross-platform - return false; -#endif + get + { + #if CORECLR + return true; + #else + return false; + #endif + } } // format files @@ -115,7 +115,7 @@ namespace System.Management.Automation internal static bool UsesCodeSignedAssemblies() { - return !Platform.IsX(); + return !Platform.IsCore; } // This is mainly with respect to the auto-mounting of diff --git a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs index f37434522..1127b1e1d 100644 --- a/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs +++ b/src/System.Management.Automation/commands/utility/FormatAndOutput/common/DisplayDatabase/typeDataXmlLoader.cs @@ -1810,7 +1810,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format // optional pre-load and binding verification // Porting Note: DLL.resources are not currently available on Linux - if (!Platform.IsX() && this.VerifyStringResources) + if (!Platform.IsCore && this.VerifyStringResources) { DisplayResourceManagerCache.LoadingResult result; DisplayResourceManagerCache.AssemblyBindingStatus bindingStatus; diff --git a/src/System.Management.Automation/engine/CommandDiscovery.cs b/src/System.Management.Automation/engine/CommandDiscovery.cs index 2d57504b8..2d0e2e917 100644 --- a/src/System.Management.Automation/engine/CommandDiscovery.cs +++ b/src/System.Management.Automation/engine/CommandDiscovery.cs @@ -1323,7 +1323,7 @@ namespace System.Management.Automation // Close the progress pane that may have popped up from analyzing UNC paths. // Porting note: we don't like this message - if (!Platform.IsX() && context.CurrentCommandProcessor != null) + if (!Platform.IsCore && context.CurrentCommandProcessor != null) { ProgressRecord analysisProgress = new ProgressRecord(0, Modules.ScriptAnalysisPreparing, " "); analysisProgress.RecordType = ProgressRecordType.Completed; diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index e4bc81a63..e1d807dca 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -5648,7 +5648,7 @@ if($paths) { // Porting note: the snapins still require 'ProcessorArchitecture=MSIL' in // the strong name, which is not in the strong name of assemblies created // by dotnet-cli - if (!Platform.IsX() && + if (!Platform.IsCore && !string.Equals(assemblyName.FullName, psSnapInInfo.AssemblyName, StringComparison.OrdinalIgnoreCase)) { string message = StringUtil.Format(ConsoleInfoErrorStrings.PSSnapInAssemblyNameMismatch, psSnapInInfo.AbsoluteModulePath, psSnapInInfo.AssemblyName); diff --git a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs index 3243b074d..6fe29f7e8 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs @@ -763,7 +763,7 @@ namespace System.Management.Automation // Porting note: Open PowerShell has a Modules folder in the the application base path which contains the built-in modules // It must be in the front of the path no matter what. - if (Platform.IsX()) + if (Platform.IsCore) { currentProcessModulePath = AddToPath(currentProcessModulePath, GetSystemwideModulePath(), 0); } diff --git a/src/System.Management.Automation/engine/SecurityManagerBase.cs b/src/System.Management.Automation/engine/SecurityManagerBase.cs index 8d89b859b..a9120d27d 100644 --- a/src/System.Management.Automation/engine/SecurityManagerBase.cs +++ b/src/System.Management.Automation/engine/SecurityManagerBase.cs @@ -90,7 +90,7 @@ namespace System.Management.Automation // TODO:PSL this is a workaround since the exception below // hides the internal issue of what's going on in terms of // execution policy. - if (Platform.IsX()) + if (Platform.IsCore) { return; } diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index 1c9edc414..2c960f93e 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -240,7 +240,7 @@ namespace System.Management.Automation /// internal static string GetApplicationBase(string shellId) { - if (!Platform.IsX()) + if (!Platform.IsCore) { // try to get the path from the registry first string result = GetApplicationBaseFromRegistry(shellId); @@ -305,7 +305,7 @@ namespace System.Management.Automation // And built-in modules string progFileDir; - if (Platform.IsX()) + if (Platform.IsCore) { progFileDir = Path.Combine(appBase, "Modules"); } diff --git a/src/System.Management.Automation/security/SecuritySupport.cs b/src/System.Management.Automation/security/SecuritySupport.cs index 1a6b0ff4f..755b1df4c 100644 --- a/src/System.Management.Automation/security/SecuritySupport.cs +++ b/src/System.Management.Automation/security/SecuritySupport.cs @@ -433,7 +433,7 @@ namespace System.Management.Automation // There is no signature support on non-Windows platforms (yet), when // execution reaches here, we are sure the file is under product folder - if (Platform.IsX()) + if (Platform.IsCore) { return true; } From a082a02e6c14285ad839665b3190ab23eae850fc Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 15:04:27 -0700 Subject: [PATCH 05/11] Add PowerShell variables corresponding to platform This deprecates the Microsoft.PowerShell.Platform module and ensure that IsLinux/OSX/Windows/Core variables are defined all throughout PowerShell. --- .../engine/InitialSessionState.cs | 26 +++++++++++++++++++ .../engine/SpecialVariables.cs | 14 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index e1d807dca..f0c84c5b6 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -5101,6 +5101,32 @@ end RemotingErrorIdStrings.PSSessionAppName, ScopedItemOptions.None), // End: Variables which control remoting behavior + + #region Platform + new SessionStateVariableEntry( + SpecialVariables.IsLinux, + Platform.IsLinux, + String.Empty, + ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + + new SessionStateVariableEntry( + SpecialVariables.IsOSX, + Platform.IsOSX, + String.Empty, + ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + + new SessionStateVariableEntry( + SpecialVariables.IsWindows, + Platform.IsWindows, + String.Empty, + ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + + new SessionStateVariableEntry( + SpecialVariables.IsCore, + Platform.IsCore, + String.Empty, + ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope), + #endregion }; /// diff --git a/src/System.Management.Automation/engine/SpecialVariables.cs b/src/System.Management.Automation/engine/SpecialVariables.cs index 2f6dd0a01..a6a83d883 100644 --- a/src/System.Management.Automation/engine/SpecialVariables.cs +++ b/src/System.Management.Automation/engine/SpecialVariables.cs @@ -156,6 +156,20 @@ namespace System.Management.Automation internal const string PSModuleAutoLoading = "PSModuleAutoLoadingPreference"; internal static VariablePath PSModuleAutoLoadingPreferenceVarPath = new VariablePath("global:" + PSModuleAutoLoading); + #region Platform Variables + internal const string IsLinux = "IsLinux"; + internal static VariablePath IsLinuxPath = new VariablePath("IsLinux"); + + internal const string IsOSX = "IsOSX"; + internal static VariablePath IsOSXPath = new VariablePath("IsOSX"); + + internal const string IsWindows = "IsWindows"; + internal static VariablePath IsWindowsPath = new VariablePath("IsWindows"); + + internal const string IsCore = "IsCore"; + internal static VariablePath IsCorePath = new VariablePath("IsCore"); + + #endregion #region Preference Variables internal const string DebugPreference = "DebugPreference"; From 822244d26118f75b4f399111b9015789991c6f1e Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 15:08:16 -0700 Subject: [PATCH 06/11] Fix properties Static but not const, go figure. --- .../CoreCLR/CorePsPlatform.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index 26847b617..50c651425 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -32,7 +32,7 @@ namespace System.Management.Automation { // Platform variables used to defined corresponding PowerShell built-in variables - public static const bool IsLinux + public static bool IsLinux { get { @@ -44,7 +44,7 @@ namespace System.Management.Automation } } - public static const bool IsOSX + public static bool IsOSX { get { @@ -56,7 +56,7 @@ namespace System.Management.Automation } } - public static const bool IsWindows + public static bool IsWindows { get { @@ -68,7 +68,7 @@ namespace System.Management.Automation } } - public static const bool IsCore + public static bool IsCore { get { From fffaf4cfe2e709f7f384d973533495abff872c84 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 15:11:33 -0700 Subject: [PATCH 07/11] Remove Platform module --- .../PSL_profile.ps1 | 2 -- .../Microsoft.PowerShell.Platform.psd1 | Bin 6700 -> 0 bytes .../Microsoft.PowerShell.Platform.psm1 | 18 ------------------ 3 files changed, 20 deletions(-) delete mode 100644 src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 delete mode 100644 src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 diff --git a/src/Microsoft.PowerShell.CoreConsoleHost/PSL_profile.ps1 b/src/Microsoft.PowerShell.CoreConsoleHost/PSL_profile.ps1 index 959f832ba..de4c4f2da 100644 --- a/src/Microsoft.PowerShell.CoreConsoleHost/PSL_profile.ps1 +++ b/src/Microsoft.PowerShell.CoreConsoleHost/PSL_profile.ps1 @@ -1,5 +1,3 @@ function prompt { "PS " + $(get-location) + "> " } - -Import-Module Microsoft.PowerShell.Platform diff --git a/src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 b/src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psd1 deleted file mode 100644 index 29fc928a0522e0dae721cfc1553eda8d914ae826..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6700 zcmchcT~Av_5Qg`fUvVTZAXOm{Xqr~46bpw0i6)2w&8_iQ-5N}76G*H4^|tS`<7Ib! z&H>kj3W3k@&d$8^J-ht<*Q#4_tFCZAx{>R+Yd3UVyNm7r5=X=WbWO+wSFT$BKLH{?xPW zh5uMOU5Pt(NVPQ!oNM*c%l}-W=xNO?*pfZ4NL$}Too@6t75>8i9f+cA>rEj!*3OY= zai=T#O=&fePTSu0rtg`z-9)&sP@&&zQJnj43w_s{!y4@Y&J^D~Cqug}&u=C2 z4qQ_luZ6?BJe3UIiMHSMNwi?sfqYI(O!d_B-(a_3v4~>Dy>+L~xSGVCeB70HcO-X9 zw%>5yNS_zddPAPy@hcndm3~@!-tbgg?pwe1%CGP0?YjhXL%5J`{=d&AD~i^X)(|Zk z!DNJaWlyp$jLmvJKHGOTX-NusjAyRIcO=dhuc2<``JF~I5N@sRx& z)21qyH{E;p#+}IT`-%~(Q8%*Q*!{L-{4}+DDz07qE%SUFO{i?dcU!V9^kbcqtR(uc z_1X99V_!F@q*i;^Rbvm;+o^HO#G37XNQWcwX6~TsF@Z3(F)cASQMI~ynhF^R3b!s> zfxqj%*4syQ#h3o6AN>SI5m%HiP?cCW)$WG`XpM0xsj@7 zQ$_Go-`Bu%aiBX;qo~(d>C$_~`WBU(+K0Vtf65!KeZNvYg{*4rSiIAEmrh4$ftIgj z@n?5^zTth;6^e6V8)*Oi+EU9~zOqwIA0Kfwo-*!yN)A&m*w@uxnKHM1+(f?-fz}h4 z_3#^igNNGQH%!iBb!YfIg_oFE@l%R^qUtkJ2TgOP%2Oxm_Vi_Xvd#Fpwzu-(aHca8 ztwm?=RN!!S zWi_7y(p4r_yvV5xKiYna#bfQ8KXX0LPB`UAv3R1}1T^zHlyhg_cZE1jg4i_ex?7>M zT1K1^lT2o0N!7`x%n5{VGA>qGze;A_J@M=)R_Tz-%g(thBKJ(bqr$d)tqYZoT=}

<5vo6&zz&G?wukdp?QaIRS1hB=oy9a7&l zg=0@zP)q6UbaCtS%f`^ExHZMA?Ymdbvl>y}!LXP0W6L^vEL}FuIxNIlwymkoW+S>+ z^<7BJWXr8IpQ5aCR>id(M_R3y#jr0O$(JajET0ZC&|G1sVNPE>wWQ}%elq=;$HIH) ze5sutyE<_uK1pgv%b!^B5Pr7#mD#5y62*R9Stf&!`vjkWAIMoM{qn8S3<|#zHnkE~g%QxL>lfc|a3B??=V7VsXgb z@wu?sX(ir*M0`xXBloN5=%aPkvZ*dmEsv0M9TO{_d$Xm+EPe3(@QEWuqjS!(wRyw&5Neuj8EP<;&(<3={C7P=`U{^10E VVz8_uvk^BKrb|knTjz^*{{w&6UE}}& diff --git a/src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 b/src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 deleted file mode 100644 index ae9616874..000000000 --- a/src/Modules/Microsoft.PowerShell.Platform/Microsoft.PowerShell.Platform.psm1 +++ /dev/null @@ -1,18 +0,0 @@ -# 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 From bcdad12c04aa566e74dd6b86406b9bc05a9d4db5 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 15:13:01 -0700 Subject: [PATCH 08/11] Fix tests for removal of Platform module --- test/powershell/Import-Module.Tests.ps1 | 4 ++-- test/powershell/Remove-Module.Tests.ps1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/powershell/Import-Module.Tests.ps1 b/test/powershell/Import-Module.Tests.ps1 index cfbe45879..52e8dd1b3 100644 --- a/test/powershell/Import-Module.Tests.ps1 +++ b/test/powershell/Import-Module.Tests.ps1 @@ -1,5 +1,5 @@ Describe "Import-Module" { - $moduleName = "Microsoft.PowerShell.Platform" + $moduleName = "Microsoft.PowerShell.Security" BeforeEach { Remove-Module -Name $moduleName -Force @@ -21,4 +21,4 @@ { Import-Module -ModuleInfo $a } | Should Not Throw (Get-Module -Name $moduleName).Name | Should Be $moduleName } -} \ No newline at end of file +} diff --git a/test/powershell/Remove-Module.Tests.ps1 b/test/powershell/Remove-Module.Tests.ps1 index f5d65658f..c1d8eae88 100644 --- a/test/powershell/Remove-Module.Tests.ps1 +++ b/test/powershell/Remove-Module.Tests.ps1 @@ -1,5 +1,5 @@ Describe "Remove-Module" { - $moduleName = "Microsoft.PowerShell.Platform" + $moduleName = "Microsoft.PowerShell.Security" BeforeEach { Import-Module -Name $moduleName -Force From 13e0760e16576addab154616dc942dfdc5e848ef Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 15:13:50 -0700 Subject: [PATCH 09/11] Fix build module for removal of Platform module --- PowerShellGitHubDev.psm1 | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/PowerShellGitHubDev.psm1 b/PowerShellGitHubDev.psm1 index a5925a3e3..0f460a37c 100644 --- a/PowerShellGitHubDev.psm1 +++ b/PowerShellGitHubDev.psm1 @@ -1,7 +1,5 @@ # Use the .NET Core APIs to determine the current platform; if a runtime # exception is thrown, we are on FullCLR, not .NET Core. -# -# TODO: import Microsoft.PowerShell.Platform instead try { $Runtime = [System.Runtime.InteropServices.RuntimeInformation] $OSPlatform = [System.Runtime.InteropServices.OSPlatform] @@ -10,11 +8,15 @@ try { $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 +} catch { + # If these are already set, then they're read-only and we're done + try { + $IsCore = $false + $IsLinux = $false + $IsOSX = $false + $IsWindows = $true + } + catch { } } @@ -122,9 +124,9 @@ function Start-PSBuild { # FullCLR only builds a library, so there is no runtime component if ($FullCLR) { - $script:Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, $Executable) + $script:Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, $Executable) } else { - $script:Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, $Runtime, $Executable) + $script:Output = [IO.Path]::Combine($Top, "bin", $Configuration, $Framework, $Runtime, $Executable) } Write-Verbose "script:Output is $script:Output" From 8c7174de1064b7df6cd6ee91d9d01a376b3b7747 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 15:22:37 -0700 Subject: [PATCH 10/11] Fix xUnit tests --- test/csharp/test_CorePsPlatform.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/csharp/test_CorePsPlatform.cs b/test/csharp/test_CorePsPlatform.cs index e36f5aa4f..a99c3b0f9 100644 --- a/test/csharp/test_CorePsPlatform.cs +++ b/test/csharp/test_CorePsPlatform.cs @@ -12,7 +12,19 @@ namespace PSTests [Fact] public static void TestIsLinux() { - Assert.True(Platform.IsLinux()); + Assert.True(Platform.IsLinux); + } + + [Fact] + public static void TestIsWindows() + { + Assert.False(Platform.IsWindows); + } + + [Fact] + public static void TestIsCore() + { + Assert.True(Platform.IsCore); } [Fact] From b3521944ecd2f38b9c97f0e30b85b079f9fc5557 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 8 Apr 2016 15:23:38 -0700 Subject: [PATCH 11/11] Fix Pester test --- test/powershell/Select-String.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/powershell/Select-String.Tests.ps1 b/test/powershell/Select-String.Tests.ps1 index dcac4471a..7a6b2456c 100644 --- a/test/powershell/Select-String.Tests.ps1 +++ b/test/powershell/Select-String.Tests.ps1 @@ -87,8 +87,6 @@ Describe "Select-String" { } Context "Filesytem actions" { - $isWindows = [System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform([System.Runtime.InteropServices.OSPlatform]::Windows) - $testDirectory = $TestDrive $testInputFile = Join-Path -Path $testDirectory -ChildPath testfile1.txt