[tests] Define NATIVEAOT in our common csproj file instead of xharness when building with NativeAOT. (#19914)

This avoids problems when building and running test suites from the command
line (we'll use the same defines as in xharness).

Some changes in xharness were needed in order to set the
PublishAot/_IsPublishing properties early enough.
This commit is contained in:
Rolf Bjarne Kvinge 2024-02-22 09:23:49 +01:00 коммит произвёл GitHub
Родитель a231083ae5
Коммит c30f099659
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 45 добавлений и 26 удалений

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

@ -60,6 +60,12 @@
<CustomBeforeMicrosoftCommonTargets>$(CustomBeforeMicrosoftCommonTargets);$(MSBuildThisFileDirectory)SupportedOSPlatformVersions.targets</CustomBeforeMicrosoftCommonTargets>
</PropertyGroup>
<!-- Logic for NativeAOT -->
<PropertyGroup Condition="'$(PublishAot)' == 'true' And '$(_IsPublishing)' == 'true'">
<!-- Define NATIVEAOT when using NativeAOT -->
<DefineConstants>$(DefineConstants);NATIVEAOT</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnitLite" Version="3.12.0" Condition="'$(ExcludeNUnitLiteReference)' != 'true'" />
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\external\Touch.Unit\Touch.Client\dotnet\$(_PlatformName)\Touch.Client-$(_PlatformName).dotnet.csproj" Condition="'$(ExcludeTouchUnitReference)' != 'true'" />

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

@ -109,7 +109,7 @@ namespace Xharness.Jenkins {
yield return new TestData { Variation = "Release (managed static registrar, all optimizations)", BundlerArguments = "--optimize:all", Registrar = "managed-static", Debug = false, Profiling = false, LinkMode = "Full", Defines = "OPTIMIZEALL", Ignored = ignore };
}
if (test.TestProject.IsDotNetProject)
yield return new TestData { Variation = "Release (NativeAOT)", Debug = false, PublishAot = true, Ignored = ignore, Defines = "NATIVEAOT", LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT)", Debug = false, PublishAot = true, Ignored = ignore, LinkMode = "Full" };
break;
case string name when name.StartsWith ("mscorlib", StringComparison.Ordinal):
if (supports_debug)
@ -138,12 +138,12 @@ namespace Xharness.Jenkins {
if (test.TestProject.IsDotNetProject && mac_supports_arm64) {
yield return new TestData { Variation = "Debug (ARM64)", Debug = true, Profiling = false, Ignored = !mac_supports_arm64 ? true : ignore, RuntimeIdentifier = arm64_sim_runtime_identifier, };
yield return new TestData { Variation = "Release (NativeAOT, ARM64)", Debug = false, PublishAot = true, Ignored = ignore, Defines = "NATIVEAOT", RuntimeIdentifier = arm64_sim_runtime_identifier, LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, ARM64)", Debug = false, PublishAot = true, Ignored = ignore, RuntimeIdentifier = arm64_sim_runtime_identifier, LinkMode = "Full" };
}
if (test.TestProject.IsDotNetProject) {
yield return new TestData { Variation = "Debug (managed static registrar)", Registrar = "managed-static", Debug = true, Profiling = false, Ignored = ignore };
yield return new TestData { Variation = "Release (managed static registrar, all optimizations)", BundlerArguments = "--optimize:all", Registrar = "managed-static", Debug = false, Profiling = false, LinkMode = "Full", Defines = "OPTIMIZEALL", Ignored = ignore };
yield return new TestData { Variation = "Release (NativeAOT, x64)", Debug = false, PublishAot = true, Ignored = ignore, Defines = "NATIVEAOT", RuntimeIdentifier = x64_sim_runtime_identifier, LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, x64)", Debug = false, PublishAot = true, Ignored = ignore, RuntimeIdentifier = x64_sim_runtime_identifier, LinkMode = "Full" };
}
break;
case "introspection":
@ -169,19 +169,19 @@ namespace Xharness.Jenkins {
if (test.Platform != TestPlatform.MacCatalyst) {
yield return new TestData { Variation = "Debug (static registrar)", Registrar = "static", Debug = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac), };
yield return new TestData { Variation = "Debug (static registrar, ARM64)", Registrar = "static", Debug = true, Profiling = false, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac) || !mac_supports_arm64, RuntimeIdentifier = arm64_runtime_identifier, };
yield return new TestData { Variation = "Release (NativeAOT, ARM64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac) || !mac_supports_arm64, Defines = "NATIVEAOT", RuntimeIdentifier = arm64_runtime_identifier, LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, x64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac), Defines = "NATIVEAOT", RuntimeIdentifier = "osx-x64", LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, ARM64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac) || !mac_supports_arm64, RuntimeIdentifier = arm64_runtime_identifier, LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, x64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac), RuntimeIdentifier = "osx-x64", LinkMode = "Full" };
}
if (test.Platform == TestPlatform.MacCatalyst) {
yield return new TestData { Variation = "Release (ARM64, LLVM)", Debug = false, UseLlvm = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.MacCatalyst) || !mac_supports_arm64, RuntimeIdentifier = arm64_runtime_identifier };
yield return new TestData { Variation = "Release", Debug = false, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.MacCatalyst) };
yield return new TestData { Variation = "Release (NativeAOT)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.MacCatalyst), Defines = "NATIVEAOT", LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, ARM64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.MacCatalyst) || !mac_supports_arm64, Defines = "NATIVEAOT", RuntimeIdentifier = arm64_runtime_identifier, LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, x64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.MacCatalyst), Defines = "NATIVEAOT", LinkMode = "Full", RuntimeIdentifier = x64_runtime_identifier };
yield return new TestData { Variation = "Release (NativeAOT)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.MacCatalyst), LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, ARM64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.MacCatalyst) || !mac_supports_arm64, RuntimeIdentifier = arm64_runtime_identifier, LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT, x64)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.MacCatalyst), LinkMode = "Full", RuntimeIdentifier = x64_runtime_identifier };
}
if (test.Platform == TestPlatform.Mac) {
yield return new TestData { Variation = "Release", Debug = false, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac) };
yield return new TestData { Variation = "Release (NativeAOT)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac), Defines = "NATIVEAOT", LinkMode = "Full" };
yield return new TestData { Variation = "Release (NativeAOT)", Debug = false, PublishAot = true, Ignored = !jenkins.TestSelection.IsEnabled (TestLabel.Monotouch) || !jenkins.TestSelection.IsEnabled (PlatformLabel.Mac), LinkMode = "Full" };
}
if (test.TestProject.IsDotNetProject) {
yield return new TestData { Variation = "Release (all optimizations)", BundlerArguments = "--optimize:all", Registrar = "static", Debug = false, Profiling = false, LinkMode = "Full", Defines = "OPTIMIZEALL", Ignored = ignore };
@ -305,8 +305,8 @@ namespace Xharness.Jenkins {
if (!string.IsNullOrEmpty (registrar))
clone.Xml.SetProperty ("Registrar", registrar);
if (publishaot) {
clone.Xml.SetProperty ("PublishAot", "true");
clone.Xml.SetProperty ("_IsPublishing", "true"); // quack like "dotnet publish", otherwise PublishAot=true has no effect.
clone.Xml.SetProperty ("PublishAot", "true", last: false);
clone.Xml.SetProperty ("_IsPublishing", "true", last: false); // quack like "dotnet publish", otherwise PublishAot=true has no effect.
}
clone.Xml.Save (clone.Path);
});

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

@ -17,7 +17,7 @@ using Xamarin.Utils;
namespace Xharness {
public static class EvolvedProjectFileExtensions {
public static void SetProperty (this XmlDocument csproj, string key, string value)
public static void SetProperty (this XmlDocument csproj, string key, string value, bool last = true)
{
// Set all existing properties
var xmlNodeList = csproj.SelectNodes ("/*[local-name() = 'Project']/*[local-name() = 'PropertyGroup']/*[local-name() = '" + key + "']")!.Cast<XmlNode> ();
@ -25,7 +25,7 @@ namespace Xharness {
item.InnerText = value;
// Create a new one as well, in case any of the other ones are for a different configuration.
var propertyGroup = GetLastPropertyGroup (csproj);
var propertyGroup = GetSpecificPropertyGroup (csproj, last);
var mea = csproj.CreateElement (key, csproj.GetNamespace ());
mea.InnerText = value;
propertyGroup.AppendChild (mea);
@ -62,42 +62,55 @@ namespace Xharness {
static XmlElement GetLastPropertyGroup (this XmlDocument csproj)
{
// Is the last property group Condition-less? If so, return it.
// Definition of last: the last PropertyGroup before an Import node (or last in file if there are no Import nodes)
return GetSpecificPropertyGroup (csproj, true);
}
static XmlElement GetSpecificPropertyGroup (this XmlDocument csproj, bool last /* or first */)
{
// If last:
// Is the last property group Condition-less? If so, return it.
// Definition of last: the last PropertyGroup before an Import node (or last in file if there are no Import nodes)
var propertyGroups = csproj.SelectNodes ("/*[local-name() = 'Project']/*[local-name() = 'PropertyGroup']")!.Cast<XmlElement> ();
var imports = csproj.SelectNodes ("/*[local-name() = 'Project']/*[local-name() = 'Import']")!.Cast<XmlElement> ();
if (propertyGroups.Any ()) {
XmlElement? last = null;
XmlElement? specific = null;
if (imports.Any ()) {
if (last && imports.Any ()) {
var firstImport = imports.First ();
var firstImportIndex = firstImport.ParentNode!.ChildNodes.IndexOf (firstImport);
foreach (var pg in propertyGroups) {
var pgIndex = pg.ParentNode!.ChildNodes.IndexOf (pg);
if (pgIndex < firstImportIndex) {
last = pg;
specific = pg;
} else {
break;
}
}
} else {
last = propertyGroups.Last ();
specific = last ? propertyGroups.Last () : propertyGroups.First ();
}
if (last?.HasAttribute ("Condition") == false)
return last;
if (specific?.HasAttribute ("Condition") == false)
return specific;
}
// Create a new PropertyGroup, and add it either:
// * Just before the first Import node
// * If no Import node, then after the last PropertyGroup.
// If last:
// * Just before the first Import node
// * If no Import node, then after the last PropertyGroup.
// If first:
// * At the very top, before the first PropertyGroup
var projectNode = csproj.SelectSingleNode ("//*[local-name() = 'Project']")!;
var newPropertyGroup = csproj.CreateElement ("PropertyGroup", csproj.GetNamespace ());
if (imports.Any ()) {
if (last && imports.Any ()) {
projectNode.InsertBefore (newPropertyGroup, imports.First ());
} else {
var lastPropertyGroup = csproj.SelectNodes ("/*[local-name() = 'Project']/*[local-name() = 'PropertyGroup']")!.Cast<XmlNode> ().Last ();
projectNode.InsertAfter (newPropertyGroup, lastPropertyGroup);
var allPropertyGroups = csproj.SelectNodes ("/*[local-name() = 'Project']/*[local-name() = 'PropertyGroup']")!.Cast<XmlNode> ();
if (last) {
projectNode.InsertAfter (newPropertyGroup, allPropertyGroups.Last ());
} else {
projectNode.InsertBefore (newPropertyGroup, allPropertyGroups.First ());
}
}
projectNode.InsertBefore (csproj.CreateComment ($" This property group was created by xharness "), newPropertyGroup);
return newPropertyGroup;