[msbuild] Don't support RuntimeIdentifiers for Hot Restart. (#20750)

There's no need to support `RuntimeIdentifiers` (plural) for Hot Restart
(because we don't have any scenarios where multiple runtime identifiers
applies to iOS; a single runtime identifier can always be used).

Adding support would make our code base more complex, so just avoid it by
showing an early error if someone tries (which is likely to be accidental
anyways).

This way we show an actionable error message for a scenario customers will
probably be confused about (because the build would fail in rather
inexplicable ways) if they run into it.

Partial fix for https://github.com/xamarin/xamarin-macios/issues/19262.
This commit is contained in:
Rolf Bjarne Kvinge 2024-07-01 19:26:57 +02:00 коммит произвёл GitHub
Родитель b30dc91f99
Коммит a28cf64a8c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 64 добавлений и 15 удалений

Просмотреть файл

@ -12,6 +12,10 @@
<Import Project="$(MSBuildThisFileDirectory)Xamarin.Messaging.Build.targets" Condition="Exists('$(MSBuildThisFileDirectory)Xamarin.Messaging.Build.targets') And '$(MessagingBuildTargetsImported)' != 'true'" />
<Import Project="$(MSBuildThisFileDirectory)Xamarin.Messaging.Apple.targets" Condition="Exists('$(MSBuildThisFileDirectory)Xamarin.Messaging.Apple.targets') And '$(MessagingAppleTargetsImported)' != 'true'" />
<Target Name="_ValidateHotRestartState" Condition="'$(IsHotRestartBuild)' == 'true'" BeforeTargets="Build">
<Error Condition="'$(RuntimeIdentifiers)' != ''" Text="Hot Restart is not supported when 'RuntimeIdentifiers' (plural) is set. Use 'RuntimeIdentifier' (singular) instead." />
</Target>
<Target Name="_GenerateHotRestartBuildSessionId">
<GenerateBuildSessionId MessagingVersion="$(MessagingVersion)"
TargetFramework="$(TargetFramework)"

Просмотреть файл

@ -1393,6 +1393,31 @@ namespace Xamarin.Tests {
var result = DotNet.AssertBuild (project_path, properties);
}
[TestCase (ApplePlatform.iOS, "ios-arm64")]
public void PluralRuntimeIdentifiers (ApplePlatform platform, string runtimeIdentifiers)
{
PluralRuntimeIdentifiersImpl (platform, runtimeIdentifiers);
}
internal static void PluralRuntimeIdentifiersImpl (ApplePlatform platform, string runtimeIdentifiers, Dictionary<string, string>? extraProperties = null, bool isUsingHotRestart = false)
{
var project = "MySimpleApp";
Configuration.IgnoreIfIgnoredPlatform (platform);
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
var properties = GetDefaultProperties (extraProperties: extraProperties);
properties ["RuntimeIdentifiers"] = runtimeIdentifiers;
if (isUsingHotRestart) {
var rv = DotNet.AssertBuildFailure (project_path, properties);
var errors = BinLog.GetBuildLogErrors (rv.BinLogPath).ToArray ();
AssertErrorMessages (errors, $"Hot Restart is not supported when 'RuntimeIdentifiers' (plural) is set. Use 'RuntimeIdentifier' (singular) instead.");
} else {
DotNet.AssertBuild (project_path, properties);
}
}
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")]
[TestCase (ApplePlatform.iOS, "ios-arm64")]
public void CustomizedCodeSigning (ApplePlatform platform, string runtimeIdentifiers)

Просмотреть файл

@ -11,30 +11,34 @@ using Xamarin.Tests;
namespace Xamarin.Tests {
[TestFixture]
public abstract class TestBaseClass {
protected Dictionary<string, string> verbosity = new Dictionary<string, string> {
protected static Dictionary<string, string> verbosity = new Dictionary<string, string> {
{ "_BundlerVerbosity", "1" },
};
protected Dictionary<string, string> GetDefaultProperties (string? runtimeIdentifiers = null)
protected static Dictionary<string, string> GetDefaultProperties (string? runtimeIdentifiers = null, Dictionary<string, string>? extraProperties = null)
{
var rv = new Dictionary<string, string> (verbosity);
if (!string.IsNullOrEmpty (runtimeIdentifiers))
SetRuntimeIdentifiers (rv, runtimeIdentifiers);
if (extraProperties is not null) {
foreach (var kvp in extraProperties)
rv [kvp.Key] = kvp.Value;
}
return rv;
}
protected void SetRuntimeIdentifiers (Dictionary<string, string> properties, string runtimeIdentifiers)
protected static void SetRuntimeIdentifiers (Dictionary<string, string> properties, string runtimeIdentifiers)
{
var multiRid = runtimeIdentifiers.IndexOf (';') >= 0 ? "RuntimeIdentifiers" : "RuntimeIdentifier";
properties [multiRid] = runtimeIdentifiers;
}
protected string GetProjectPath (string project, string runtimeIdentifiers, ApplePlatform platform, out string appPath, string? subdir = null, string configuration = "Debug", string? netVersion = null)
protected static string GetProjectPath (string project, string runtimeIdentifiers, ApplePlatform platform, out string appPath, string? subdir = null, string configuration = "Debug", string? netVersion = null)
{
return GetProjectPath (project, null, runtimeIdentifiers, platform, out appPath, configuration, netVersion);
}
protected string GetProjectPath (string project, string? subdir, string runtimeIdentifiers, ApplePlatform platform, out string appPath, string configuration = "Debug", string? netVersion = null)
protected static string GetProjectPath (string project, string? subdir, string runtimeIdentifiers, ApplePlatform platform, out string appPath, string configuration = "Debug", string? netVersion = null)
{
var rv = GetProjectPath (project, subdir, platform);
appPath = Path.Combine (GetOutputPath (project, subdir, runtimeIdentifiers, platform, configuration, netVersion), project + ".app");
@ -62,7 +66,7 @@ namespace Xamarin.Tests {
return Path.Combine (Path.GetDirectoryName (projectPath)!, binOrObj, configuration, platform.ToFramework (), appPathRuntimeIdentifier);
}
protected string GetOutputPath (string project, string? subdir, string runtimeIdentifiers, ApplePlatform platform, string configuration = "Debug", string? netVersion = null)
protected static string GetOutputPath (string project, string? subdir, string runtimeIdentifiers, ApplePlatform platform, string configuration = "Debug", string? netVersion = null)
{
var rv = GetProjectPath (project, subdir, platform);
if (string.IsNullOrEmpty (runtimeIdentifiers))
@ -71,7 +75,7 @@ namespace Xamarin.Tests {
return Path.Combine (Path.GetDirectoryName (rv)!, "bin", configuration, platform.ToFramework (netVersion), appPathRuntimeIdentifier);
}
protected string GetDefaultRuntimeIdentifier (ApplePlatform platform, string configuration = "Debug")
protected static string GetDefaultRuntimeIdentifier (ApplePlatform platform, string configuration = "Debug")
{
var arch = Configuration.CanRunArm64 ? "arm64" : "x64";
switch (platform) {
@ -92,7 +96,7 @@ namespace Xamarin.Tests {
}
}
protected string GetProjectPath (string project, string? subdir = null, ApplePlatform? platform = null)
protected static string GetProjectPath (string project, string? subdir = null, ApplePlatform? platform = null)
{
var project_dir = Path.Combine (Configuration.SourceRoot, "tests", "dotnet", project);
if (!string.IsNullOrEmpty (subdir))
@ -143,7 +147,7 @@ namespace Xamarin.Tests {
}
}
protected void Clean (string project_path)
protected static void Clean (string project_path)
{
var dirs = Directory.GetDirectories (Path.GetDirectoryName (project_path)!, "*", SearchOption.AllDirectories);
dirs = dirs.OrderBy (v => v.Length).Reverse ().ToArray (); // If we have nested directories, make sure to delete the nested one first

Просмотреть файл

@ -27,12 +27,7 @@ namespace Xamarin.Tests {
var properties = GetDefaultProperties (runtimeIdentifiers);
if (!string.IsNullOrWhiteSpace (configuration))
properties ["Configuration"] = configuration;
properties ["IsHotRestartBuild"] = "true";
properties ["IsHotRestartEnvironmentReady"] = "true";
properties ["EnableCodeSigning"] = "false"; // Skip code signing, since that would require making sure we have code signing configured on bots.
properties ["_AppIdentifier"] = "placeholder_AppIdentifier"; // This needs to be set to a placeholder value because DetectSigningIdentity usually does it (and we've disabled signing)
properties ["_BundleIdentifier"] = "placeholder_BundleIdentifier"; // This needs to be set to a placeholder value because DetectSigningIdentity usually does it (and we've disabled signing)
properties ["_IsAppSigned"] = "false";
AddHotRestartProperties (properties);
// Redirect hot restart output to a place we can control from here
var hotRestartOutputDir = Path.Combine (tmpdir, "out");
@ -284,6 +279,15 @@ namespace Xamarin.Tests {
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);
}
[Category ("Windows")]
[Category ("RemoteWindows")]
[TestCase (ApplePlatform.iOS, "ios-arm64")]
public void PluralRuntimeIdentifiersWithHotRestart (ApplePlatform platform, string runtimeIdentifiers)
{
var properties = AddHotRestartProperties ();
DotNetProjectTest.PluralRuntimeIdentifiersImpl (platform, runtimeIdentifiers, properties, isUsingHotRestart: true);
}
static void AssertWarningsEqual (IList<string> expected, IList<string> actual, string message)
{
if (expected.Count == actual.Count) {
@ -373,5 +377,17 @@ namespace Xamarin.Tests {
if (!string.IsNullOrEmpty (properties ["ServerUser"]))
properties ["EnsureRemoteConnection"] = "true";
}
protected Dictionary<string, string> AddHotRestartProperties (Dictionary<string, string>? properties = null)
{
properties ??= new Dictionary<string, string> ();
properties ["IsHotRestartBuild"] = "true";
properties ["IsHotRestartEnvironmentReady"] = "true";
properties ["EnableCodeSigning"] = "false"; // Skip code signing, since that would require making sure we have code signing configured on bots.
properties ["_IsAppSigned"] = "false";
properties ["_AppIdentifier"] = "placeholder_AppIdentifier"; // This needs to be set to a placeholder value because DetectSigningIdentity usually does it (and we've disabled signing)
properties ["_BundleIdentifier"] = "placeholder_BundleIdentifier"; // This needs to be set to a placeholder value because DetectSigningIdentity usually does it (and we've disabled signing)
return properties;
}
}
}