[xharness] Automatically inline Imports to a "shared.csproj" when cloning projects. Fixes #12316 and #12277. (#12322)

This way we process the shared.csproj that we use in our .NET test projects.
The main effect is that we'll clone any project references included in the
shared.csproj, which will fix #12316. On another hand, it means that we'll
add/remove defines in referenced projects, which fixes #12277.

It also allows us to put more code in the "shared.csproj" files.

Fixes https://github.com/xamarin/xamarin-macios/issues/12316.
Fixes https://github.com/xamarin/xamarin-macios/issues/12277.
This commit is contained in:
Rolf Bjarne Kvinge 2021-08-04 18:13:02 +02:00 коммит произвёл GitHub
Родитель 142e71780a
Коммит a91e34f01b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
23 изменённых файлов: 387 добавлений и 67 удалений

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

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is not processed by xharness, and contains logic shared by all our test suites -->
<Project>
<!-- Logic for iOS -->
<PropertyGroup Condition="$(TargetFramework.EndsWith('-ios'))">
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
</PropertyGroup>
<ItemGroup Condition="'$(_PlatformName)' == 'iOS'">
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
</ItemGroup>
<!-- Logic for tvOS -->
<PropertyGroup Condition="$(TargetFramework.EndsWith('-tvos'))">
<DefineConstants>$(DefineConstants);XAMCORE_3_0</DefineConstants>
<AssetTargetFallback>xamarintvos10;$(AssetTargetFallback)</AssetTargetFallback>
</PropertyGroup>
<ItemGroup Condition="$(TargetFramework.EndsWith('-tvos'))">
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
</ItemGroup>
<!-- Logic for macOS -->
<PropertyGroup Condition="$(TargetFramework.EndsWith('-macos'))">
<DefineConstants>$(DefineConstants);MONOMAC</DefineConstants>
</PropertyGroup>
<!-- Logic for Mac Catalyst -->
<PropertyGroup Condition="$(TargetFramework.EndsWith('-maccatalyst'))">
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
</PropertyGroup>
<!-- Logic for all test suites -->
</Project>

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

@ -2,14 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-maccatalyst</TargetFramework>
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
</PropertyGroup>
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<!-- this empty item group is here for xharness -->
</ItemGroup>
<Import Project="$(RootTestsDirectory)/linker/ios/dont link/dotnet/shared.csproj" />
</Project>

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

@ -2,13 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios</TargetFramework>
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/linker/ios/dont link/dotnet/shared.csproj" />
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>

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

@ -7,9 +7,12 @@
<RootNamespace>dontlink</RootNamespace>
<AssemblyName>dont link</AssemblyName>
<MtouchLink>None</MtouchLink>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..\..\..'))</RootTestsDirectory>
<ThisTestDirectory>$(RootTestsDirectory)\linker\ios\dont link</ThisTestDirectory>
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/common/shared-dotnet.csproj" />
<ItemGroup>
<PackageReference Include="NUnitLite" Version="3.12.0" />
<ProjectReference Include="$(RootTestsDirectory)\..\external\Touch.Unit\Touch.Client\dotnet\$(_PlatformName)\Touch.Client-$(_PlatformName).dotnet.csproj" />

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

@ -2,13 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-tvos</TargetFramework>
<AssetTargetFallback>xamarintvos10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/linker/ios/dont link/dotnet/shared.csproj" />
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>

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

@ -2,13 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-maccatalyst</TargetFramework>
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
</PropertyGroup>
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<!-- this empty item group is here for xharness -->
</ItemGroup>
<Import Project="$(RootTestsDirectory)/linker/ios/link all/dotnet/shared.csproj" />
</Project>

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

@ -2,13 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios</TargetFramework>
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/linker/ios/link all/dotnet/shared.csproj" />
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>

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

@ -9,9 +9,12 @@
<MtouchLink>Full</MtouchLink>
<MtouchExtraArgs>--optimize=all,-remove-dynamic-registrar,-force-rejected-types-removal</MtouchExtraArgs>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..\..\..'))</RootTestsDirectory>
<ThisTestDirectory>$(RootTestsDirectory)\linker\ios\link all</ThisTestDirectory>
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/common/shared-dotnet.csproj" />
<!-- We use configurations like Debug64 and Release64, which doesn't work with the default logic we and .NET have -->
<PropertyGroup Condition="$(Configuration.Contains('Debug'))">
<MtouchDebug>true</MtouchDebug>

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

@ -2,14 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-tvos</TargetFramework>
<DefineConstants>XAMCORE_3_0;$(DefineConstants)</DefineConstants>
<AssetTargetFallback>xamarintvos10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/linker/ios/link all/dotnet/shared.csproj" />
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>

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

@ -2,13 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-maccatalyst</TargetFramework>
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
</PropertyGroup>
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<!-- this empty item group is here for xharness -->
</ItemGroup>
<Import Project="$(RootTestsDirectory)/linker/ios/link sdk/dotnet/shared.csproj" />
</Project>

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

@ -2,13 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios</TargetFramework>
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/linker/ios/link sdk/dotnet/shared.csproj" />
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>

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

@ -9,9 +9,12 @@
<MtouchLink>SdkOnly</MtouchLink>
<MtouchExtraArgs>-disable-thread-check "--dlsym:-link sdk" -gcc_flags="-UhoItsB0rken"</MtouchExtraArgs>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..\..\..'))</RootTestsDirectory>
<ThisTestDirectory>$(RootTestsDirectory)\linker\ios\link sdk</ThisTestDirectory>
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/common/shared-dotnet.csproj" />
<ItemGroup>
<Reference Include="support">
<HintPath>$(ThisTestDirectory)/support.dll</HintPath>

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

@ -2,13 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-tvos</TargetFramework>
<AssetTargetFallback>xamarintvos10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/linker/ios/link sdk/dotnet/shared.csproj" />
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>

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

@ -2,18 +2,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-maccatalyst</TargetFramework>
<DefineConstants Condition="'$(Configuration)' == 'Debug'">$(DefineConstants);DYNAMIC_REGISTRAR</DefineConstants> <!-- this can't be in shared.csproj, because xharness needs to remove the DYNAMIC_REGISTRAR define for certain test cases -->
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
<AssemblyName>monotouchtest</AssemblyName> <!-- this can't be in shared.csproj, because xharness won't see it there -->
<DefineConstants Condition="'$(Configuration)' == 'Debug'">$(DefineConstants);DYNAMIC_REGISTRAR</DefineConstants>
</PropertyGroup>
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<!-- this empty item group is here for xharness -->
</ItemGroup>
<Import Project="$(RootTestsDirectory)/monotouch-test/dotnet/shared.csproj" />
<PropertyGroup>
<!-- This must be after the place where xharness injects the RuntimeIdentifier property -->
<DefineConstants Condition="'$(RuntimeIdentifier)' == 'maccatalyst-arm64'">$(DefineConstants);AOT</DefineConstants>

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

@ -2,15 +2,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-ios</TargetFramework>
<AssetTargetFallback>xamarinios10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
<AssemblyName>monotouchtest</AssemblyName> <!-- this can't be in shared.csproj, because xharness won't see it there -->
<DefineConstants Condition="'$(Platform)' == 'iPhoneSimulator'">$(DefineConstants);DYNAMIC_REGISTRAR</DefineConstants> <!-- this can't be in shared.csproj, because xharness needs to remove the DYNAMIC_REGISTRAR define for certain test cases -->
<DefineConstants Condition="'$(Platform)' == 'iPhoneSimulator'">$(DefineConstants);DYNAMIC_REGISTRAR</DefineConstants>
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/monotouch-test/dotnet/shared.csproj" />
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>

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

@ -2,13 +2,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-macos</TargetFramework>
<DefineConstants>$(DefineConstants);MONOMAC;XAMMAC_TESTS</DefineConstants>
<DefineConstants Condition="'$(Configuration)' == 'Debug'">$(DefineConstants);DYNAMIC_REGISTRAR</DefineConstants> <!-- this can't be in shared.csproj, because xharness needs to remove the DYNAMIC_REGISTRAR define for certain test cases -->
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
<AssemblyName>monotouchtest</AssemblyName> <!-- this can't be in shared.csproj, because xharness won't see it there -->
<DefineConstants>$(DefineConstants);XAMMAC_TESTS</DefineConstants>
<DefineConstants Condition="'$(Configuration)' == 'Debug'">$(DefineConstants);DYNAMIC_REGISTRAR</DefineConstants>
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/monotouch-test/dotnet/shared.csproj" />
<!-- Imports of the form '../shared.csproj' will be inlined by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<Compile Include="..\..\..\common\Configuration.cs">

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

@ -8,7 +8,9 @@
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\..\product.snk</AssemblyOriginatorKeyFile>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<AssemblyName>monotouchtest</AssemblyName>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)\..\..\..'))</RootTestsDirectory>
<TestLibrariesDirectory>$(RootTestsDirectory)\test-libraries</TestLibrariesDirectory>
<MonoTouchTestDirectory>$(RootTestsDirectory)\monotouch-test</MonoTouchTestDirectory>
@ -20,6 +22,8 @@
<DefineConstants Condition="'$(Configuration)' == 'Debug'">$(DefineConstants);DEBUG</DefineConstants>
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/common/shared-dotnet.csproj" />
<ItemGroup>
<PackageReference Include="NUnitLite" Version="3.12.0" />
<ProjectReference Include="$(RootTestsDirectory)\..\external\Touch.Unit\Touch.Client\dotnet\$(_PlatformName)\Touch.Client-$(_PlatformName).dotnet.csproj" />

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

@ -2,16 +2,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-tvos</TargetFramework>
<DefineConstants>$(DefineConstants);XAMCORE_3_0</DefineConstants>
<DefineConstants Condition="'$(Platform)' == 'iPhoneSimulator'">$(DefineConstants);DYNAMIC_REGISTRAR</DefineConstants> <!-- this can't be in shared.csproj, because xharness needs to remove the DYNAMIC_REGISTRAR define for certain test cases -->
<AssetTargetFallback>xamarintvos10;$(AssetTargetFallback)</AssetTargetFallback>
<RootTestsDirectory>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\..'))</RootTestsDirectory> <!-- this can't be in shared.csproj, because xharness won't see it there -->
<AssemblyName>monotouchtest</AssemblyName> <!-- this can't be in shared.csproj, because xharness won't see it there -->
<DefineConstants Condition="'$(Platform)' == 'iPhoneSimulator'">$(DefineConstants);DYNAMIC_REGISTRAR</DefineConstants>
</PropertyGroup>
<Import Project="$(RootTestsDirectory)/monotouch-test/dotnet/shared.csproj" />
<!-- Imports of the form '../shared.csproj' will be processed by xharness -->
<Import Project="../shared.csproj" />
<ItemGroup>
<PackageReference Include="MonoTouch.Dialog" Version="2.0.0-pre1" />
<!-- this empty item group is here for xharness -->
</ItemGroup>
</Project>

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

@ -306,6 +306,7 @@ namespace Xharness {
TargetFrameworkFlavors = MacFlavors.DotNet,
Platform = "AnyCPU",
Ignore = !ENABLE_DOTNET,
TestPlatform = TestPlatform.Mac,
});
MacTestProjects.Add (new MacTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "monotouch-test", "dotnet", "MacCatalyst", "monotouch-test.csproj"))) {
@ -314,6 +315,7 @@ namespace Xharness {
TargetFrameworkFlavors = MacFlavors.MacCatalyst,
Platform = "AnyCPU",
Ignore = !ENABLE_DOTNET,
TestPlatform = TestPlatform.MacCatalyst,
});
MacTestProjects.Add (new MacTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dotnet", "MacCatalyst", "dont link.csproj"))) {
@ -322,6 +324,7 @@ namespace Xharness {
TargetFrameworkFlavors = MacFlavors.MacCatalyst,
Platform = "AnyCPU",
Ignore = !ENABLE_DOTNET,
TestPlatform = TestPlatform.MacCatalyst,
});
MacTestProjects.Add (new MacTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "dotnet", "MacCatalyst", "link all.csproj"))) {
@ -330,6 +333,7 @@ namespace Xharness {
TargetFrameworkFlavors = MacFlavors.MacCatalyst,
Platform = "AnyCPU",
Ignore = !ENABLE_DOTNET,
TestPlatform = TestPlatform.MacCatalyst,
});
MacTestProjects.Add (new MacTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "dotnet", "MacCatalyst", "link sdk.csproj"))) {
@ -338,6 +342,7 @@ namespace Xharness {
TargetFrameworkFlavors = MacFlavors.MacCatalyst,
Platform = "AnyCPU",
Ignore = !ENABLE_DOTNET,
TestPlatform = TestPlatform.MacCatalyst,
});
foreach (var flavor in new MonoNativeFlavor [] { MonoNativeFlavor.Compat, MonoNativeFlavor.Unified }) {
@ -462,19 +467,19 @@ namespace Xharness {
Configurations = new string [] { "Debug", "Release" },
IgnoreMacCatalystVariation = false,
});
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dotnet", "iOS", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, SkipMacCatalystVariation = true });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dotnet", "iOS", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, SkipMacCatalystVariation = true, TestPlatform = TestPlatform.iOS_Unified, });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "dont link", "dotnet", "tvOS", "dont link.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = true, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, GenerateVariations = false, TestPlatform = TestPlatform.tvOS, });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "link all.csproj"))) {
Configurations = new string [] { "Debug", "Release" },
IgnoreMacCatalystVariation = false,
});
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "dotnet", "iOS", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, SkipMacCatalystVariation = true, });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "dotnet", "iOS", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, SkipMacCatalystVariation = true, TestPlatform = TestPlatform.iOS_Unified, });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link all", "dotnet", "tvOS", "link all.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = true, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, GenerateVariations = false, TestPlatform = TestPlatform.tvOS, });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "link sdk.csproj"))) {
Configurations = new string [] { "Debug", "Release" },
IgnoreMacCatalystVariation = false,
});
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "dotnet", "iOS", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, SkipMacCatalystVariation = true, });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "dotnet", "iOS", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = false, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, SkipMacCatalystVariation = true, TestPlatform = TestPlatform.iOS_Unified, });
IOSTestProjects.Add (new iOSTestProject (Path.GetFullPath (Path.Combine (RootDirectory, "linker", "ios", "link sdk", "dotnet", "tvOS", "link sdk.csproj"))) { Configurations = new string [] { "Debug", "Release" }, IsDotNetProject = true, SkipiOSVariation = true, SkiptvOSVariation = true, SkipwatchOSVariation = true, SkipTodayExtensionVariation = true, SkipDeviceVariations = false, SkipiOS32Variation = true, GenerateVariations = false, TestPlatform = TestPlatform.tvOS, });
foreach (var flavor in new MonoNativeFlavor [] { MonoNativeFlavor.Compat, MonoNativeFlavor.Unified }) {

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

@ -0,0 +1,217 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using Microsoft.DotNet.XHarness.iOS.Shared.Utilities;
using Xamarin.Utils;
#nullable enable
namespace Xharness {
public static class EvolvedProjectFileExtensions {
// Evaluates a text and replaces '$(Variable)' with the property value specified in the 'properties' dictionary.
// Contrary to what MSBuild does, if the variable can't be found in the dictionary, it's not replaced with
// an empty string, instead the variable reference stays as-is.
public static string EvaluateAsMSBuildText (this string text, Dictionary<string, string> properties)
{
if (text.Length < 4)
return text;
if (text.IndexOf ('$') == -1)
return text;
var sb = new StringBuilder ();
for (var i = 0; i < text.Length; i++) {
if (text [i] != '$' || i + 2 >= text.Length) {
sb.Append (text [i]);
continue;
}
if (text [i + 1] != '(') {
sb.Append ('$');
sb.Append (text [i + 1]);
continue;
}
var endParenthesis = text.IndexOf (')', i + 2);
if (endParenthesis == -1)
continue;
var variable = text.Substring (i + 2, endParenthesis - i - 2);
if (properties.TryGetValue (variable, out var value)) {
sb.Append (value);
} else {
// Put back the variable reference
sb.Append ('$');
sb.Append ('(');
sb.Append (variable);
sb.Append (')');
}
i = endParenthesis;
}
return sb.ToString ();
}
// Collect all top-level properties in a csproj. They're evaluated as they're found, so that multiple properties concatenating
// strings work correctly. The 'forcedProperties' dictionary contains properties that are hardcoded and should be returned as
// the dictionary says.
public static Dictionary<string, string> CollectAndEvaluateTopLevelProperties (this XmlDocument doc, Dictionary<string, string> forcedProperties)
{
var collectedProperties = new Dictionary<string, string> (forcedProperties);
var properties = doc.SelectNodes ("/Project/*[local-name() = 'PropertyGroup' and not(@Condition)]//*");
foreach (XmlNode prop in properties) {
if (!forcedProperties.ContainsKey (prop.Name))
collectedProperties [prop.Name] = prop.InnerText.EvaluateAsMSBuildText (collectedProperties);
}
return collectedProperties;
}
static IEnumerable<XmlNode> SelectElementNodes (this XmlNode node, string name)
{
foreach (XmlNode? child in node.ChildNodes) {
if (child == null)
continue;
if (child.NodeType == XmlNodeType.Element && child.Name == name)
yield return child;
if (!child.HasChildNodes)
continue;
foreach (XmlNode descendent in child.SelectElementNodes (name))
yield return descendent;
}
}
// This is an evolved version of https://github.com/dotnet/xharness/blob/b2297d610df1ae15fc7ba8bd8c9bc0a7192aaefa/src/Microsoft.DotNet.XHarness.iOS.Shared/Utilities/ProjectFileExtensions.cs#L1168
public static void ResolveAllPaths (this XmlDocument csproj, string project_path, Dictionary<string, string>? variableSubstitution = null)
{
var dir = Path.GetDirectoryName (project_path)!;
var nodes_with_paths = new string []
{
"AssemblyOriginatorKeyFile",
"CodesignEntitlements",
"TestLibrariesDirectory",
"HintPath",
"RootTestsDirectory",
};
var attributes_with_paths = new []
{
new { Element = "None", Attribute = "Include", SkipLogicalName = false, },
new { Element = "Compile", Attribute = "Include", SkipLogicalName = false, },
new { Element = "Compile", Attribute = "Exclude", SkipLogicalName = false, },
new { Element = "ProjectReference", Attribute = "Include", SkipLogicalName = true, },
new { Element = "InterfaceDefinition", Attribute = "Include", SkipLogicalName = false, },
new { Element = "BundleResource", Attribute = "Include", SkipLogicalName = false, },
new { Element = "EmbeddedResource", Attribute = "Include", SkipLogicalName = false, },
new { Element = "ImageAsset", Attribute = "Include", SkipLogicalName = false, },
new { Element = "GeneratedTestInput", Attribute = "Include", SkipLogicalName = false, },
new { Element = "GeneratedTestOutput", Attribute = "Include", SkipLogicalName = false, },
new { Element = "TestLibrariesInput", Attribute = "Include", SkipLogicalName = false, },
new { Element = "TestLibrariesOutput", Attribute = "Include", SkipLogicalName = false, },
new { Element = "Content", Attribute = "Include", SkipLogicalName = false, },
new { Element = "ObjcBindingApiDefinition", Attribute = "Include", SkipLogicalName = false, },
new { Element = "ObjcBindingCoreSource", Attribute = "Include", SkipLogicalName = false, },
new { Element = "ObjcBindingNativeLibrary", Attribute = "Include", SkipLogicalName = false, },
new { Element = "ObjcBindingNativeFramework", Attribute = "Include", SkipLogicalName = false, },
new { Element = "Import", Attribute = "Project", SkipLogicalName = true, },
new { Element = "FilesToCopy", Attribute = "Include", SkipLogicalName = false, },
new { Element = "FilesToCopyFoo", Attribute = "Include", SkipLogicalName = false, },
new { Element = "FilesToCopyFooBar", Attribute = "Include", SkipLogicalName = false, },
new { Element = "FilesToCopyEncryptedXml", Attribute = "Include", SkipLogicalName = false, },
new { Element = "FilesToCopyCryptographyPkcs", Attribute = "Include", SkipLogicalName = false, },
new { Element = "FilesToCopyResources", Attribute = "Include", SkipLogicalName = false, },
new { Element = "FilesToCopyXMLFiles", Attribute = "Include", SkipLogicalName = false, },
new { Element = "FilesToCopyChannels", Attribute = "Include", SkipLogicalName = false, },
new { Element = "CustomMetalSmeltingInput", Attribute = "Include", SkipLogicalName = false, },
new { Element = "Metal", Attribute = "Include", SkipLogicalName = false, },
new { Element = "NativeReference", Attribute = "Include", SkipLogicalName = false, },
};
var nodes_with_variables = new string []
{
"MtouchExtraArgs",
};
Func<string, string>? convert = null;
convert = (input) => {
if (input.Contains (';')) {
var split = input.Split (new char [] { ';' }, StringSplitOptions.RemoveEmptyEntries);
for (var i = 0; i < split.Length; i++)
split [i] = convert!.Invoke (split [i]);
return string.Join (";", split);
}
if (variableSubstitution != null)
input = input.EvaluateAsMSBuildText (variableSubstitution);
var makeFullPath = input [0] != '$';
if (makeFullPath) {
input = input.Replace ('\\', '/'); // make unix-style
input = Path.GetFullPath (Path.Combine (dir, input));
input = input.Replace ('/', '\\'); // make windows-style again
}
return input;
};
foreach (var key in nodes_with_paths) {
var nodes = csproj.SelectElementNodes (key);
foreach (var node in nodes)
node.InnerText = convert (node.InnerText);
}
foreach (var key in nodes_with_variables) {
var nodes = csproj.SelectElementNodes (key);
foreach (var node in nodes)
node.InnerText = node.InnerText.Replace ("${ProjectDir}", StringUtils.Quote (Path.GetDirectoryName (project_path)));
}
foreach (var kvp in attributes_with_paths) {
var element = kvp.Element;
var attrib = kvp.Attribute;
var skipLogicalName = kvp.SkipLogicalName;
var nodes = csproj.SelectElementNodes (element);
foreach (XmlNode node in nodes) {
var a = node.Attributes [attrib];
if (a == null)
continue;
// Fix any default LogicalName values (but don't change existing ones).
if (!skipLogicalName) {
var ln = node.SelectElementNodes ("LogicalName")?.SingleOrDefault ();
var links = node.SelectElementNodes ("Link");
if (ln == null && !links.Any ()) {
ln = csproj.CreateElement ("LogicalName", csproj.GetNamespace ());
node.AppendChild (ln);
string logicalName = a.Value;
switch (element) {
case "BundleResource":
if (logicalName.StartsWith ("Resources\\", StringComparison.Ordinal))
logicalName = logicalName.Substring ("Resources\\".Length);
break;
default:
break;
}
ln.InnerText = logicalName;
}
}
a.Value = convert (a.Value);
}
}
}
}
}

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

@ -50,5 +50,33 @@ namespace Xharness {
return false;
}
}
// This must match our $(_PlatformName) variable in our MSBuild logic.
public static string ToPlatformName (this TestPlatform platform)
{
switch (platform) {
case TestPlatform.iOS:
case TestPlatform.iOS_Unified:
case TestPlatform.iOS_Unified32:
case TestPlatform.iOS_Unified64:
case TestPlatform.iOS_TodayExtension64:
return "iOS";
case TestPlatform.tvOS:
return "tvOS";
case TestPlatform.watchOS:
case TestPlatform.watchOS_32:
case TestPlatform.watchOS_64_32:
return "watchOS";
case TestPlatform.MacCatalyst:
return "MacCatalyst";
case TestPlatform.Mac:
case TestPlatform.Mac_Modern:
case TestPlatform.Mac_Full:
case TestPlatform.Mac_System:
return "macOS";
default:
return null;
}
}
}
}

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

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.DotNet.XHarness.Common.Execution;
@ -67,6 +68,7 @@ namespace Xharness {
rv.MTouchExtraArgs = MTouchExtraArgs;
rv.TimeoutMultiplier = TimeoutMultiplier;
rv.Ignore = Ignore;
rv.TestPlatform = TestPlatform;
return rv;
}
@ -95,8 +97,46 @@ namespace Xharness {
XmlDocument doc;
doc = new XmlDocument ();
doc.LoadWithoutNetworkAccess (original_path);
var original_name = System.IO.Path.GetFileName (original_path);
doc.ResolveAllPaths (original_path, rootDirectory);
var variableSubstitution = new Dictionary<string, string> ();
variableSubstitution.Add ("RootTestsDirectory", rootDirectory);
// Find Import nodes that point to a shared code file, load that shared file and inject it here.
var nodes = doc.SelectNodes ("//*[local-name() = 'Import']");
foreach (XmlNode node in nodes) {
if (node == null)
continue;
var project = node.Attributes ["Project"].Value;
if (project != "../shared.csproj")
continue;
if (TestPlatform == TestPlatform.None)
throw new InvalidOperationException ($"The project ?{original_path}' did not set the TestPlatform property.");
var sharedProjectPath = System.IO.Path.Combine (System.IO.Path.GetDirectoryName (original_path), project);
// Check for variables that won't work correctly if the shared code is moved to a different file
var xml = File.ReadAllText (sharedProjectPath);
if (xml.Contains ("$(MSBuildThis"))
throw new InvalidOperationException ($"Can't use MSBuildThis* variables in shared MSBuild test code.");
var import = new XmlDocument ();
import.LoadXmlWithoutNetworkAccess (xml);
var importNodes = import.SelectSingleNode ("/Project").ChildNodes;
var previousNode = node;
foreach (XmlNode importNode in importNodes) {
var importedNode = doc.ImportNode (importNode, true);
previousNode.ParentNode.InsertAfter (importedNode, previousNode);
previousNode = importedNode;
}
node.ParentNode.RemoveChild (node);
variableSubstitution.Add ("_PlatformName", TestPlatform.ToPlatformName ());
variableSubstitution = doc.CollectAndEvaluateTopLevelProperties (variableSubstitution);
}
lock (typeof (TestProject))
doc.ResolveAllPaths (original_path, variableSubstitution);
// Replace RootTestsDirectory with a constant value, so that any relative paths don't end up wrong.
var rootTestsDirectoryNode = doc.SelectSingleNode ("/Project/PropertyGroup/RootTestsDirectory");

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

@ -178,6 +178,10 @@
<Compile Include="TestTargetExtensions.cs" />
<Compile Include="XmlDocumentExtensions.cs" />
<Compile Include="Targets\MacCatalystTarget.cs" />
<Compile Include="ProjectFileExtensions.cs" />
<Compile Include="..\..\tools\common\StringUtils.cs">
<Link>StringUtils.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\tools\common\SdkVersions.cs">