From ccc9d4caf22f44061db44a76b60f2c677a40a24e Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 9 Jul 2021 17:43:03 -0400 Subject: [PATCH 1/2] Move PosixSignalRegistration to corelib --- .../TestUtilities/System/PlatformDetection.cs | 3 +- .../System.Private.CoreLib.Shared.projitems | 15 +++++++++ .../Runtime/InteropServices/PosixSignal.cs | 0 .../InteropServices/PosixSignalContext.cs | 0 ...ignalRegistration.PlatformNotSupported.cs} | 0 .../PosixSignalRegistration.Unix.cs | 0 .../PosixSignalRegistration.Windows.cs | 0 .../PosixSignalRegistration.cs | 0 .../src/Resources/Strings.resx | 3 -- .../src/System.Runtime.InteropServices.csproj | 27 ++-------------- ...ystem.Runtime.InteropServices.Tests.csproj | 5 +-- .../PosixSignalRegistrationTests.Browser.cs | 29 ----------------- .../PosixSignalRegistrationTests.Unix.cs | 32 +++++++++++++------ 13 files changed, 43 insertions(+), 71 deletions(-) rename src/libraries/{System.Runtime.InteropServices => System.Private.CoreLib}/src/System/Runtime/InteropServices/PosixSignal.cs (100%) rename src/libraries/{System.Runtime.InteropServices => System.Private.CoreLib}/src/System/Runtime/InteropServices/PosixSignalContext.cs (100%) rename src/libraries/{System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalRegistration.Unsupported.cs => System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.PlatformNotSupported.cs} (100%) rename src/libraries/{System.Runtime.InteropServices => System.Private.CoreLib}/src/System/Runtime/InteropServices/PosixSignalRegistration.Unix.cs (100%) rename src/libraries/{System.Runtime.InteropServices => System.Private.CoreLib}/src/System/Runtime/InteropServices/PosixSignalRegistration.Windows.cs (100%) rename src/libraries/{System.Runtime.InteropServices => System.Private.CoreLib}/src/System/Runtime/InteropServices/PosixSignalRegistration.cs (100%) delete mode 100644 src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Browser.cs diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs index e11da7e8d4d93b..90f21d02f5c49b 100644 --- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs +++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs @@ -37,7 +37,8 @@ public static partial class PlatformDetection public static bool IsSolaris => RuntimeInformation.IsOSPlatform(OSPlatform.Create("SOLARIS")); public static bool IsBrowser => RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")); public static bool IsNotBrowser => !IsBrowser; - public static bool IsNotMobile => IsNotBrowser && !IsMacCatalyst && !IsiOS && !IstvOS && !IsAndroid; + public static bool IsMobile => IsBrowser || IsMacCatalyst || IsiOS || IstvOS || IsAndroid; + public static bool IsNotMobile => !IsMobile; public static bool IsNotNetFramework => !IsNetFramework; public static bool IsArmProcess => RuntimeInformation.ProcessArchitecture == Architecture.Arm; diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index a1e270dbde97dd..3dcfc2c7313a57 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -837,6 +837,9 @@ + + + @@ -1235,6 +1238,7 @@ + @@ -1651,6 +1655,9 @@ Common\Interop\Windows\Interop.OBJECT_ATTRIBUTES.cs + + Common\Interop\Windows\Interop.SetConsoleCtrlHandler.cs + Common\Interop\Windows\Kernel32\Interop.SetCurrentDirectory.cs @@ -1833,6 +1840,7 @@ + @@ -2129,6 +2137,10 @@ Common\Interop\Unix\System.Native\Interop.GetPid.cs + + + + + diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignal.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignal.cs similarity index 100% rename from src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignal.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignal.cs diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalContext.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalContext.cs similarity index 100% rename from src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalContext.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalContext.cs diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalRegistration.Unsupported.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.PlatformNotSupported.cs similarity index 100% rename from src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalRegistration.Unsupported.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.PlatformNotSupported.cs diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalRegistration.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.Unix.cs similarity index 100% rename from src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalRegistration.Unix.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.Unix.cs diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalRegistration.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.Windows.cs similarity index 100% rename from src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalRegistration.Windows.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.Windows.cs diff --git a/src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalRegistration.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.cs similarity index 100% rename from src/libraries/System.Runtime.InteropServices/src/System/Runtime/InteropServices/PosixSignalRegistration.cs rename to src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.cs diff --git a/src/libraries/System.Runtime.InteropServices/src/Resources/Strings.resx b/src/libraries/System.Runtime.InteropServices/src/Resources/Strings.resx index d7644789f28c21..08d7e045a580f5 100644 --- a/src/libraries/System.Runtime.InteropServices/src/Resources/Strings.resx +++ b/src/libraries/System.Runtime.InteropServices/src/Resources/Strings.resx @@ -111,7 +111,4 @@ Specified file length was too large for the file system. - - Cannot create '{0}' because a file or directory with the same name already exists. - diff --git a/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj b/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj index 7137155589b233..3bc59997f7f0c4 100644 --- a/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj +++ b/src/libraries/System.Runtime.InteropServices/src/System.Runtime.InteropServices.csproj @@ -2,7 +2,7 @@ true enable - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser + $(NetCoreAppCurrent) @@ -33,9 +33,6 @@ - - - @@ -51,27 +48,7 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj index 33204d0ee7cc93..f0ffe70d47c314 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.Tests.csproj @@ -1,7 +1,7 @@ true - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix true true @@ -192,7 +192,4 @@ - - - diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Browser.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Browser.cs deleted file mode 100644 index 2202ed25744ee9..00000000000000 --- a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Browser.cs +++ /dev/null @@ -1,29 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Linq; -using System.Runtime.InteropServices; -using System.Collections.Generic; - -namespace System.Tests -{ - public partial class PosixSignalRegistrationTests - { - public static IEnumerable UninstallableSignals() => Enumerable.Empty(); - - public static IEnumerable SupportedSignals() => Enumerable.Empty(); - - public static IEnumerable UnsupportedSignals() - { - foreach (PosixSignal signal in Enum.GetValues()) - { - yield return new object[] { signal }; - } - - yield return new object[] { 0 }; - yield return new object[] { 3 }; - yield return new object[] { -1000 }; - yield return new object[] { 1000 }; - } - } -} diff --git a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs index 1716a3ba24f7f4..e08d77565513a1 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs @@ -14,23 +14,37 @@ public partial class PosixSignalRegistrationTests { public static IEnumerable UninstallableSignals() { - yield return new object[] { (PosixSignal)9 }; + if (PlatformDetection.IsNotMobile) + { + yield return new object[] { (PosixSignal)9 }; + } } public static IEnumerable SupportedSignals() { - foreach (PosixSignal value in Enum.GetValues(typeof(PosixSignal))) - yield return new object[] { value }; + if (PlatformDetection.IsNotMobile) + { + foreach (PosixSignal value in Enum.GetValues(typeof(PosixSignal))) + yield return new object[] { value }; + } } public static IEnumerable UnsupportedSignals() { + if (PlatformDetection.IsMobile) + { + foreach (PosixSignal value in Enum.GetValues(typeof(PosixSignal))) + yield return new object[] { value }; + } + yield return new object[] { 0 }; yield return new object[] { -1000 }; yield return new object[] { 1000 }; } - [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + public static bool NotMobileAndRemoteExecutable => PlatformDetection.IsNotMobile && RemoteExecutor.IsSupported; + + [ConditionalTheory(nameof(NotMobileAndRemoteExecutable))] [MemberData(nameof(SupportedSignals))] public void SignalHandlerCalledForKnownSignals(PosixSignal s) { @@ -55,7 +69,7 @@ public void SignalHandlerCalledForKnownSignals(PosixSignal s) }, s.ToString()).Dispose(); } - [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + [ConditionalTheory(nameof(NotMobileAndRemoteExecutable))] [MemberData(nameof(PosixSignalAsRawValues))] public void SignalHandlerCalledForRawSignals(PosixSignal s) { @@ -80,7 +94,7 @@ public void SignalHandlerCalledForRawSignals(PosixSignal s) }, s.ToString()).Dispose(); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMobile))] public void SignalHandlerWorksForSecondRegistration() { PosixSignal signal = PosixSignal.SIGCONT; @@ -104,7 +118,7 @@ public void SignalHandlerWorksForSecondRegistration() } } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMobile))] public void SignalHandlerNotCalledWhenDisposed() { PosixSignal signal = PosixSignal.SIGCONT; @@ -118,7 +132,7 @@ public void SignalHandlerNotCalledWhenDisposed() Thread.Sleep(100); } - [Fact] + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotMobile))] public void SignalHandlerNotCalledWhenFinalized() { PosixSignal signal = PosixSignal.SIGCONT; @@ -140,7 +154,7 @@ void CreateDanglingRegistration() } } - [ConditionalTheory(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))] + [ConditionalTheory(nameof(NotMobileAndRemoteExecutable))] [InlineData(PosixSignal.SIGINT, true, 0)] [InlineData(PosixSignal.SIGINT, false, 130)] [InlineData(PosixSignal.SIGTERM, true, 0)] From 224f95cae493e8800371789425b18ae7636246a5 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sat, 10 Jul 2021 21:52:52 -0400 Subject: [PATCH 2/2] Fix trimming issue on mobile targets --- .../PosixSignalRegistration.PlatformNotSupported.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.PlatformNotSupported.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.PlatformNotSupported.cs index 4bfd2eae0be670..3ccc169b1a84b3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.PlatformNotSupported.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/PosixSignalRegistration.PlatformNotSupported.cs @@ -1,12 +1,15 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Diagnostics.CodeAnalysis; + namespace System.Runtime.InteropServices { public sealed partial class PosixSignalRegistration { private PosixSignalRegistration() { } + [DynamicDependency("#ctor")] // Prevent the private ctor and the IDisposable implementation from getting linked away public static partial PosixSignalRegistration Create(PosixSignal signal, Action handler) { if (handler is null)