Skip to content

Commit

Permalink
[dotnet] Accept invalid runtime identifiers for Restore. (#15357)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Jul 12, 2022
1 parent 620a4eb commit f7772d4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@

<Target Name="_ValidateRuntimeIdentifier"
Condition="'$(RuntimeIdentifier)' != '' And '$(_RuntimeIdentifierValidation)' != 'false' And '$(_RuntimeIdentifierIsRequired)' == 'true'"
BeforeTargets="Restore;Build;ResolvedFrameworkReference;ResolveRuntimePackAssets;ProcessFrameworkReferences">
BeforeTargets="Build;ResolvedFrameworkReference;ResolveRuntimePackAssets">
<PropertyGroup>
<_IsValidRuntimeIdentifier Condition="@(_XamarinValidRuntimeIdentifier->WithMetadataValue('Platform', '$(_PlatformName)')->WithMetadataValue('Filename', '$(RuntimeIdentifier)')->Count()) &gt; 0">true</_IsValidRuntimeIdentifier>
</PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions tests/common/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public static ExecutionResult AssertPublishFailure (string project, Dictionary<s
return rv;
}

public static ExecutionResult AssertRestore (string project, Dictionary<string, string> properties = null)
{
return Execute ("restore", project, properties, true);
}

public static ExecutionResult AssertBuild (string project, Dictionary<string, string> properties = null)
{
return Execute ("build", project, properties, true);
Expand Down Expand Up @@ -105,6 +110,7 @@ public static ExecutionResult Execute (string verb, string project, Dictionary<s
case "build":
case "pack":
case "publish":
case "restore":
var args = new List<string> ();
args.Add (verb);
args.Add (project);
Expand Down
60 changes: 41 additions & 19 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,24 +448,24 @@ public void BuildAndExecuteNativeReferencesTestApp (string project, ApplePlatfor
}

[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-arm")] // we don't support this
[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-arm")] // we don't support this
[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)
[TestCase (ApplePlatform.iOS, "ios-x64", false)] // valid RID in a previous preview (and common mistake)
[TestCase (ApplePlatform.iOS, "iossimulator-x84", true)] // it's x86, not x84
[TestCase (ApplePlatform.iOS, "iossimulator-arm", true)] // we don't support this
[TestCase (ApplePlatform.iOS, "helloworld", true)] // random text
[TestCase (ApplePlatform.iOS, "osx-x64", false)] // valid RID for another platform
[TestCase (ApplePlatform.TVOS, "tvos-x64", false)] // valid RID in a previous preview (and common mistake)
[TestCase (ApplePlatform.TVOS, "tvossimulator-x46", true)] // it's x64, not x46
[TestCase (ApplePlatform.TVOS, "tvossimulator-arm", true)] // we don't support this
[TestCase (ApplePlatform.TVOS, "helloworld", true)] // random text
[TestCase (ApplePlatform.TVOS, "osx-x64", false)] // valid RID for another platform
[TestCase (ApplePlatform.MacOSX, "osx-x46", true)] // it's x64, not x46
[TestCase (ApplePlatform.MacOSX, "macos-arm64", true)] // it's osx, not macos
[TestCase (ApplePlatform.MacOSX, "helloworld", true)] // random text
[TestCase (ApplePlatform.MacOSX, "ios-arm64", false)] // valid RID for another platform
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x46", true)] // it's x64, not x46
[TestCase (ApplePlatform.MacCatalyst, "helloworld", true)] // random text
[TestCase (ApplePlatform.MacCatalyst, "osx-x64", false)] // valid RID for another platform
public void InvalidRuntimeIdentifier (ApplePlatform platform, string runtimeIdentifier, bool notRecognized)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Expand All @@ -477,7 +477,29 @@ public void InvalidRuntimeIdentifier (ApplePlatform platform, string runtimeIden
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray ();
var uniqueErrors = errors.Select (v => v.Message).Distinct ().ToArray ();
Assert.AreEqual (1, uniqueErrors.Length, "Error count");
Assert.AreEqual ($"The RuntimeIdentifier '{runtimeIdentifier}' is invalid.", uniqueErrors [0], "Error message");
string expectedError;
if (notRecognized) {
expectedError = $"The specified RuntimeIdentifier '{runtimeIdentifier}' is not recognized.";
} else {
expectedError = $"The RuntimeIdentifier '{runtimeIdentifier}' is invalid.";
}
Assert.AreEqual (expectedError, uniqueErrors [0], "Error message");
}

[Test]
[TestCase (ApplePlatform.iOS, "win10-x86")]
[TestCase (ApplePlatform.TVOS, "win10-x64")]
[TestCase (ApplePlatform.MacOSX, "win10-arm")]
[TestCase (ApplePlatform.MacCatalyst, "win10-arm64")]
public void InvalidRuntimeIdentifier_Restore (ApplePlatform platform, string runtimeIdentifier)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);

var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifier);
DotNet.AssertRestore (project_path, properties);
}

[Test]
Expand Down

5 comments on commit f7772d4

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.