From 724d0fe1b318568c76e69a2c001e2307881d8e7c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 14 Jun 2021 20:35:24 +0200 Subject: [PATCH] [dotnet] Set a default RuntimeIdentifier and validate that we get a valid RuntimeIdentifier. Fixes #10861. Also add tests: * Remove RuntimeIdentifier from a few sample projects. These projects should continue to build just fine. * Add tests for invalid RuntimeIdentifiers. Fixes https://github.com/xamarin/xamarin-macios/issues/10861. --- .../Xamarin.Shared.Sdk.DefaultItems.targets | 25 ++++++++ dotnet/targets/Xamarin.Shared.Sdk.targets | 12 ++++ tests/dotnet/MyCocoaApp/MyCocoaApp.csproj | 1 - tests/dotnet/MySingleView/MySingleView.csproj | 1 - tests/dotnet/MyTVApp/MyTVApp.csproj | 1 - tests/dotnet/UnitTests/ProjectTest.cs | 61 +++++++++++++++++-- .../dotnet/MacCatalyst/monotouch-test.csproj | 1 - .../dotnet/iOS/monotouch-test.csproj | 1 - .../dotnet/macOS/monotouch-test.csproj | 1 - .../dotnet/tvOS/monotouch-test.csproj | 1 - 10 files changed, 94 insertions(+), 11 deletions(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.DefaultItems.targets b/dotnet/targets/Xamarin.Shared.Sdk.DefaultItems.targets index 92a721e661..b6015056c8 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.DefaultItems.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.DefaultItems.targets @@ -29,6 +29,31 @@ $(MtouchArch) + + + iossimulator-x64 + tvossimulator-x64 + osx-x64 + maccatalyst-x64 + + true + <_RuntimeIdentifierUsesAppHost>false + false + $(IntermediateOutputPath)$(RuntimeIdentifier)\ + $(OutputPath)$(RuntimeIdentifier)\ + + diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index ea95542dc5..af20ba39a7 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -790,6 +790,18 @@ + + + <_IsInvalidRuntimeIdentifier Condition="'$(_PlatformName)' == 'iOS' And '$(RuntimeIdentifier)' != 'iossimulator-x64' And '$(RuntimeIdentifier)' != 'iossimulator-x86' And '$(RuntimeIdentifier)' != 'ios-arm64' And '$(RuntimeIdentifier)' != 'ios-arm' ">true + <_IsInvalidRuntimeIdentifier Condition="'$(_PlatformName)' == 'tvOS' And '$(RuntimeIdentifier)' != 'tvossimulator-x64' And '$(RuntimeIdentifier)' != 'tvos-arm64'">true + <_IsInvalidRuntimeIdentifier Condition="'$(_PlatformName)' == 'macOS' And '$(RuntimeIdentifier)' != 'osx-x64' And '$(RuntimeIdentifier)' != 'osx-arm64'">true + <_IsInvalidRuntimeIdentifier Condition="'$(_PlatformName)' == 'MacCatalyst' And '$(RuntimeIdentifier)' != 'maccatalyst-x64' And '$(RuntimeIdentifier)' != 'maccatalyst-arm64'">true + + + + diff --git a/tests/dotnet/MyCocoaApp/MyCocoaApp.csproj b/tests/dotnet/MyCocoaApp/MyCocoaApp.csproj index 6e701ae12b..d9b70c3409 100644 --- a/tests/dotnet/MyCocoaApp/MyCocoaApp.csproj +++ b/tests/dotnet/MyCocoaApp/MyCocoaApp.csproj @@ -2,7 +2,6 @@ net6.0-macos - osx-x64 Exe \ No newline at end of file diff --git a/tests/dotnet/MySingleView/MySingleView.csproj b/tests/dotnet/MySingleView/MySingleView.csproj index 578b7ac0ec..97b5f03d87 100644 --- a/tests/dotnet/MySingleView/MySingleView.csproj +++ b/tests/dotnet/MySingleView/MySingleView.csproj @@ -2,7 +2,6 @@ net6.0-ios - iossimulator-x64 Exe MySingleTitle diff --git a/tests/dotnet/MyTVApp/MyTVApp.csproj b/tests/dotnet/MyTVApp/MyTVApp.csproj index 718f3966f8..29130d2334 100644 --- a/tests/dotnet/MyTVApp/MyTVApp.csproj +++ b/tests/dotnet/MyTVApp/MyTVApp.csproj @@ -2,7 +2,6 @@ net6.0-tvos - tvossimulator-x64 Exe diff --git a/tests/dotnet/UnitTests/ProjectTest.cs b/tests/dotnet/UnitTests/ProjectTest.cs index 480934e676..4d80708077 100644 --- a/tests/dotnet/UnitTests/ProjectTest.cs +++ b/tests/dotnet/UnitTests/ProjectTest.cs @@ -52,6 +52,7 @@ namespace Xamarin.Tests { } [Test] + [TestCase (null)] [TestCase ("iossimulator-x86")] [TestCase ("iossimulator-x64")] [TestCase ("ios-arm64")] @@ -63,7 +64,11 @@ namespace Xamarin.Tests { Configuration.IgnoreIfIgnoredPlatform (platform); Clean (project_path); var properties = new Dictionary (verbosity); - properties ["RuntimeIdentifier"] = runtimeIdentifier; + if (!string.IsNullOrEmpty (runtimeIdentifier)) { + properties ["RuntimeIdentifier"] = runtimeIdentifier; + } else { + runtimeIdentifier = "iossimulator-x64"; // default RID for iOS projects. We set it here to make the rest of the test know where to expect files to be. + } var result = DotNet.AssertBuild (project_path, properties); AssertThatLinkerExecuted (result); var appPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-ios", runtimeIdentifier, "MySingleView.app"); @@ -77,6 +82,7 @@ namespace Xamarin.Tests { } [Test] + [TestCase (null)] [TestCase ("osx-x64")] [TestCase ("osx-arm64")] public void BuildMyCocoaApp (string runtimeIdentifier) @@ -86,13 +92,18 @@ namespace Xamarin.Tests { Configuration.IgnoreIfIgnoredPlatform (platform); Clean (project_path); var properties = new Dictionary (verbosity); - properties ["RuntimeIdentifier"] = runtimeIdentifier; + if (!string.IsNullOrEmpty (runtimeIdentifier)) { + properties ["RuntimeIdentifier"] = runtimeIdentifier; + } else { + runtimeIdentifier = "osx-x64"; // default RID for macOS projects. We set it here to make the rest of the test know where to expect files to be. + } var result = DotNet.AssertBuild (project_path, properties); AssertThatLinkerExecuted (result); AssertAppContents (platform, Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-macos", runtimeIdentifier, "MyCocoaApp.app")); } [Test] + [TestCase (null)] [TestCase ("tvossimulator-x64")] [TestCase ("tvos-arm64")] public void BuildMyTVApp (string runtimeIdentifier) @@ -102,7 +113,11 @@ namespace Xamarin.Tests { Configuration.IgnoreIfIgnoredPlatform (platform); Clean (project_path); var properties = new Dictionary (verbosity); - properties ["RuntimeIdentifier"] = runtimeIdentifier; + if (!string.IsNullOrEmpty (runtimeIdentifier)) { + properties ["RuntimeIdentifier"] = runtimeIdentifier; + } else { + runtimeIdentifier = "tvossimulator-x64"; // default RID for tvOS projects. We set it here to make the rest of the test know where to expect files to be. + } var result = DotNet.AssertBuild (project_path, properties); AssertThatLinkerExecuted (result); AssertAppContents (platform, Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-tvos", runtimeIdentifier, "MyTVApp.app")); @@ -120,6 +135,7 @@ namespace Xamarin.Tests { } [Test] + [TestCase (null)] [TestCase ("maccatalyst-x64")] [TestCase ("maccatalyst-arm64")] public void BuildMyCatalystApp (string runtimeIdentifier) @@ -129,7 +145,11 @@ namespace Xamarin.Tests { Configuration.IgnoreIfIgnoredPlatform (platform); Clean (project_path); var properties = new Dictionary (verbosity); - properties ["RuntimeIdentifier"] = runtimeIdentifier; + if (!string.IsNullOrEmpty (runtimeIdentifier)) { + properties ["RuntimeIdentifier"] = runtimeIdentifier; + } else { + runtimeIdentifier = "maccatalyst-x64"; // default RID for Mac Catalyst projects. We set it here to make the rest of the test know where to expect files to be. + } var result = DotNet.AssertBuild (project_path, properties); AssertThatLinkerExecuted (result); var appPath = Path.Combine (Path.GetDirectoryName (project_path), "bin", "Debug", "net6.0-maccatalyst", runtimeIdentifier, "MyCatalystApp.app"); @@ -428,6 +448,39 @@ namespace Xamarin.Tests { } } + [Test] + [TestCase (ApplePlatform.iOS, "ios-x64")] // valid RID in a previous preview (and common mistake) + [TestCase (ApplePlatform.iOS, "iossimulator-x84")] // it's x86, not x84 + [TestCase (ApplePlatform.iOS, "iossimulator-arm64")] // we don't support this yet + [TestCase (ApplePlatform.iOS, "helloworld")] // random text + [TestCase (ApplePlatform.iOS, "osx-x64")] // valid RID for another platform + [TestCase (ApplePlatform.TVOS, "tvos-x64")] // valid RID in a previous preview (and common mistake) + [TestCase (ApplePlatform.TVOS, "tvossimulator-x46")] // it's x64, not x46 + [TestCase (ApplePlatform.TVOS, "tvossimulator-arm64")] // we don't support this yet + [TestCase (ApplePlatform.TVOS, "helloworld")] // random text + [TestCase (ApplePlatform.TVOS, "osx-x64")] // valid RID for another platform + [TestCase (ApplePlatform.MacOSX, "osx-x46")] // it's x64, not x46 + [TestCase (ApplePlatform.MacOSX, "macos-arm64")] // it's osx, not macos + [TestCase (ApplePlatform.MacOSX, "helloworld")] // random text + [TestCase (ApplePlatform.MacOSX, "ios-arm64")] // valid RID for another platform + [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x46")] // it's x64, not x46 + [TestCase (ApplePlatform.MacCatalyst, "helloworld")] // random text + [TestCase (ApplePlatform.MacCatalyst, "osx-x64")] // valid RID for another platform + public void InvalidRuntimeIdentifier (ApplePlatform platform, string runtimeIdentifier) + { + var project = "MySimpleApp"; + Configuration.IgnoreIfIgnoredPlatform (platform); + + var project_path = GetProjectPath (project, platform: platform); + Clean (project_path); + var properties = new Dictionary (verbosity); + properties ["RuntimeIdentifier"] = runtimeIdentifier; + var rv = DotNet.AssertBuildFailure (project_path, properties); + var errors = BinLog.GetBuildMessages (rv.BinLogPath).Where (v => v.Type == BuildLogEventType.Error).ToArray (); + Assert.AreEqual (1, errors.Length, "Error count"); + Assert.AreEqual ($"The RuntimeIdentifier '{runtimeIdentifier}' is invalid.", errors [0].Message, "Error message"); + } + void ExecuteWithMagicWordAndAssert (string executable) { var magicWord = Guid.NewGuid ().ToString (); diff --git a/tests/monotouch-test/dotnet/MacCatalyst/monotouch-test.csproj b/tests/monotouch-test/dotnet/MacCatalyst/monotouch-test.csproj index 52993feb16..65350fcfe7 100644 --- a/tests/monotouch-test/dotnet/MacCatalyst/monotouch-test.csproj +++ b/tests/monotouch-test/dotnet/MacCatalyst/monotouch-test.csproj @@ -2,7 +2,6 @@ net6.0-maccatalyst - maccatalyst-x64 Exe NET latest diff --git a/tests/monotouch-test/dotnet/iOS/monotouch-test.csproj b/tests/monotouch-test/dotnet/iOS/monotouch-test.csproj index 3561dce879..9960c4d67d 100644 --- a/tests/monotouch-test/dotnet/iOS/monotouch-test.csproj +++ b/tests/monotouch-test/dotnet/iOS/monotouch-test.csproj @@ -2,7 +2,6 @@ net6.0-ios - iossimulator-x64 Exe NET latest diff --git a/tests/monotouch-test/dotnet/macOS/monotouch-test.csproj b/tests/monotouch-test/dotnet/macOS/monotouch-test.csproj index 2ec163a69c..e65bb1109d 100644 --- a/tests/monotouch-test/dotnet/macOS/monotouch-test.csproj +++ b/tests/monotouch-test/dotnet/macOS/monotouch-test.csproj @@ -2,7 +2,6 @@ net6.0-macos - osx-x64 Exe NET latest diff --git a/tests/monotouch-test/dotnet/tvOS/monotouch-test.csproj b/tests/monotouch-test/dotnet/tvOS/monotouch-test.csproj index 1d483e9d3b..cfa43152ba 100644 --- a/tests/monotouch-test/dotnet/tvOS/monotouch-test.csproj +++ b/tests/monotouch-test/dotnet/tvOS/monotouch-test.csproj @@ -2,7 +2,6 @@ net6.0-tvos - tvossimulator-x64 Exe NET;XAMCORE_3_0 latest