[d16-2] [msbuild] Add reference to `System.Drawing.Common.dll` to XI projects. (#6035)

* [msbuild] Add reference to `System.Drawing.Common.dll` to XI projects.

Fixes https://github.com/mono/mono/issues/13483 :

```
@akoeplinger: Since we moved types from Mono.Android.dll and
Xamarin.iOS/WatchOS/TVOS.dll to System.Drawing.Common.dll user projects
would fail to compile. We need to add some msbuild logic to add a
reference to the assembly automatically.
```

* [msbuild] Implement the same fix for XM projects as well.

* [msbuild] Update Xamarin.iOS.Tasks.TargetTests.GetReferencedAssemblies_* tests.

We're including a new assembly, which means the
Xamarin.iOS.Tasks.TargetTests.GetReferencedAssemblies_* must be updated
accordingly.

Also modify these tests so that test assert that fails lists the actual
assembly that's missing, i.e. instead of this:

    1) Test Failure : Xamarin.iOS.Tasks.TargetTests.GetReferencedAssemblies_Executable
         #1
      Expected: 6
      But was:  7

we now print:

    1) Test Failure : Xamarin.iOS.Tasks.TargetTests.GetReferencedAssemblies_Executable
         References
      Expected: equivalent to < "mscorlib.dll", "MyLibrary.dll", "System.Core.dll", "System.dll", "System.Xml.dll", "Xamarin.iOS.dll" >
      But was:  < "mscorlib.dll", "MyLibrary.dll", "System.Core.dll", "System.dll", "System.Drawing.Common.dll", "System.Xml.dll", "Xamarin.iOS.dll" >

* [tests] Adjust Xamarin.MMP.Tests.AssemblyReferencesTests.ShouldNotAllowReference_ToSystemDrawing.

The test was verifying that referencing System.Drawing.dll and trying to use
System.Drawing.RectangleF would fail to compile (because System.Drawing.dll
shouldn't be resolved in this case).

The addition of System.Drawing.Common.dll breaks this assumption, because now
we ship System.Drawing.RectangleF, so the code that was supposed to fail to
compile works just fine instead.

So modify the test to verify that there's no System.Drawing.dll in the final
bundle.

* Remove workarounds for mono/mono#13483.

* [msbuild] Create a way out if automatically referencing System.Drawing.Common.dll causes problems.

* [msbuild] Adjust variable name and boolean logic according to review.
This commit is contained in:
monojenkins 2019-05-10 10:16:01 -04:00 коммит произвёл Rolf Bjarne Kvinge
Родитель 557d435844
Коммит daf5006281
8 изменённых файлов: 56 добавлений и 20 удалений

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

@ -186,6 +186,13 @@ Copyright (C) 2014 Xamarin. All rights reserved.
<RemoveDir Directories="$(IntermediateOutputPath)" />
</Target>
<Target Name="_AddExtraReferences" BeforeTargets="ResolveAssemblyReferences" Condition="'$(DisableExtraReferences)' != 'true'">
<ItemGroup>
<!-- https://github.com/mono/mono/issues/13483 -->
<Reference Include="System.Drawing.Common.dll" />
</ItemGroup>
</Target>
<PropertyGroup>
<_CollectBundleResourcesDependsOn>
_CompileImageAssets;

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

@ -458,6 +458,13 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<Delete SessionId="$(BuildSessionId)" Condition="'$(IsMacEnabled)' == 'true'" Files="@(_IpaPackageFile)" />
</Target>
<Target Name="_AddExtraReferences" BeforeTargets="ResolveAssemblyReferences" Condition="'$(DisableExtraReferences)' != 'true'">
<ItemGroup>
<!-- https://github.com/mono/mono/issues/13483 -->
<Reference Include="System.Drawing.Common.dll" />
</ItemGroup>
</Target>
<PropertyGroup>
<_CollectBundleResourcesDependsOn>
_CompileInterfaceDefinitions;

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

@ -139,14 +139,19 @@ namespace Xamarin.iOS.Tasks
{
RunTargetOnInstance (MonoTouchProjectInstance, TargetName.ResolveReferences);
var references = MonoTouchProjectInstance.GetItems ("ReferencePath").ToArray ();
var expected_references = new string[] {
"MyLibrary.dll",
"System.dll",
"System.Xml.dll",
"System.Core.dll",
"mscorlib.dll",
"Xamarin.iOS.dll",
"System.Drawing.Common.dll",
};
Array.Sort (expected_references);
Assert.AreEqual (6, references.Length, "#1");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("MyLibrary")), "#2");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("System")), "#3a");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("System.Xml")), "#3b");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("System.Core")), "#3c");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("mscorlib")), "#3d");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("Xamarin.iOS")), "#3e");
var actual_references = references.Select ((v) => Path.GetFileName (v.EvaluatedInclude)).OrderBy ((v) => v);
CollectionAssert.AreEquivalent (expected_references, actual_references, "References");
}
[Test]
@ -154,13 +159,18 @@ namespace Xamarin.iOS.Tasks
{
RunTargetOnInstance (LibraryProjectInstance, TargetName.ResolveReferences);
var references = LibraryProjectInstance.GetItems ("ReferencePath").ToArray ();
var expected_references = new string[] {
"System.dll",
"System.Xml.dll",
"System.Core.dll",
"mscorlib.dll",
"Xamarin.iOS.dll",
"System.Drawing.Common.dll",
};
Array.Sort (expected_references);
Assert.AreEqual (5, references.Length, "#1");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("System")), "#2a");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("System.Xml")), "#2b");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("System.Core")), "#2c");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("mscorlib")), "#2d");
Assert.IsTrue (references.Any (t => t.EvaluatedInclude.Contains ("Xamarin.iOS")), "#2e");
var actual_references = references.Select ((v) => Path.GetFileName (v.EvaluatedInclude)).OrderBy ((v) => v);
CollectionAssert.AreEquivalent (expected_references, actual_references, "References");
}
[Test]

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

@ -167,6 +167,18 @@ namespace Xamarin.MMP.Tests
// Generated by TestUnifiedExecutable/TestSystemMonoExecutable and added to TestCode
public Guid guid { get; set; }
public string BundleName {
get { return AssemblyName != "" ? AssemblyName : ProjectName.Split ('.') [0]; }
}
public string BundlePath {
get { return Path.Combine (TmpDir, "bin", Release ? "Release" : "Debug", BundleName + ".app"); }
}
public string ExecutablePath {
get { return Path.Combine (BundlePath, "Contents", "MacOS", BundleName); }
}
public UnifiedTestConfig (string tmpDir)
{
TmpDir = tmpDir;
@ -427,9 +439,7 @@ namespace Xamarin.MMP.Tests
public static string RunGeneratedUnifiedExecutable (UnifiedTestConfig config)
{
string bundleName = config.AssemblyName != "" ? config.AssemblyName : config.ProjectName.Split ('.')[0];
string exePath = Path.Combine (config.TmpDir, "bin/" + (config.Release ? "Release/" : "Debug/") + bundleName + ".app/Contents/MacOS/" + bundleName);
return RunEXEAndVerifyGUID (config.TmpDir, config.guid, exePath);
return RunEXEAndVerifyGUID (config.TmpDir, config.guid, config.ExecutablePath);
}
public static OutputText TestUnifiedExecutable (UnifiedTestConfig config, bool shouldFail = false, string[] environment = null)

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

@ -143,7 +143,6 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing.Common" /> <!-- FIXME: https://github.com/mono/mono/issues/13483 -->
<Reference Include="Xamarin.iOS" />
<Reference Include="MonoTouch.NUnitLite" />
<Reference Include="System.Core" />

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

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;
@ -17,7 +18,11 @@ namespace Xamarin.MMP.Tests
TestCode = "System.Drawing.RectangleF f = new System.Drawing.RectangleF ();",
XM45 = true
};
TI.TestUnifiedExecutable (test, shouldFail: true);
TI.TestUnifiedExecutable (test);
var allAssembliesInBundle = Directory.GetFiles (test.BundlePath, "*.dll", SearchOption.AllDirectories).Select (Path.GetFileName);
Assert.That (allAssembliesInBundle, Does.Contain ("mscorlib.dll"), "mscorlib.dll");
Assert.That (allAssembliesInBundle, Does.Contain ("System.Drawing.Common.dll"), "System.Drawing.Common.dll");
Assert.That (allAssembliesInBundle, Does.Not.Contain ("System.Drawing.dll"), "System.Drawing.dll");
});
}

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

@ -156,7 +156,6 @@
<Reference Include="MonoTouch.NUnitLite" />
<Reference Include="System.Net.Http" />
<Reference Include="OpenTK-1.0" />
<Reference Include="System.Drawing.Common" /> <!-- FIXME: https://github.com/mono/mono/issues/13483 -->
</ItemGroup>
<ItemGroup>
<None Include="Info.plist">

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

@ -60,7 +60,6 @@
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="OpenTK" />
<Reference Include="System.Drawing.Common" /> <!-- FIXME: https://github.com/mono/mono/issues/13483 -->
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>