From daf5006281d6f48f3cacc412af0e3447a7c6fb36 Mon Sep 17 00:00:00 2001 From: monojenkins Date: Fri, 10 May 2019 10:16:01 -0400 Subject: [PATCH] [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. --- .../Xamarin.Mac.Common.targets | 7 ++++ .../Xamarin.iOS.Common.targets | 7 ++++ .../TargetTests/TargetTests.cs | 36 ++++++++++++------- tests/common/mac/ProjectTestHelpers.cs | 16 +++++++-- .../iOS/introspection-ios.csproj | 1 - tests/mmptest/src/AssemblyReferencesTests.cs | 7 +++- tests/monotouch-test/monotouch-test.csproj | 1 - tests/xammac_tests/xammac_tests.csproj | 1 - 8 files changed, 56 insertions(+), 20 deletions(-) diff --git a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets index 009aef1ed2..9965d7c796 100644 --- a/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets +++ b/msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets @@ -186,6 +186,13 @@ Copyright (C) 2014 Xamarin. All rights reserved. + + + + + + + <_CollectBundleResourcesDependsOn> _CompileImageAssets; diff --git a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets index 0b826bcc3e..c05e6e6c29 100644 --- a/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets +++ b/msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets @@ -458,6 +458,13 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved. + + + + + + + <_CollectBundleResourcesDependsOn> _CompileInterfaceDefinitions; diff --git a/msbuild/tests/Xamarin.iOS.Tasks.Tests/TargetTests/TargetTests.cs b/msbuild/tests/Xamarin.iOS.Tasks.Tests/TargetTests/TargetTests.cs index b9072574ce..8428c43b5a 100644 --- a/msbuild/tests/Xamarin.iOS.Tasks.Tests/TargetTests/TargetTests.cs +++ b/msbuild/tests/Xamarin.iOS.Tasks.Tests/TargetTests/TargetTests.cs @@ -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] diff --git a/tests/common/mac/ProjectTestHelpers.cs b/tests/common/mac/ProjectTestHelpers.cs index 13982e6c66..8bae19ab7f 100644 --- a/tests/common/mac/ProjectTestHelpers.cs +++ b/tests/common/mac/ProjectTestHelpers.cs @@ -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) diff --git a/tests/introspection/iOS/introspection-ios.csproj b/tests/introspection/iOS/introspection-ios.csproj index 7231a24d56..c0e48c59fc 100644 --- a/tests/introspection/iOS/introspection-ios.csproj +++ b/tests/introspection/iOS/introspection-ios.csproj @@ -143,7 +143,6 @@ - diff --git a/tests/mmptest/src/AssemblyReferencesTests.cs b/tests/mmptest/src/AssemblyReferencesTests.cs index 5fbb213eb3..a0e39f702d 100644 --- a/tests/mmptest/src/AssemblyReferencesTests.cs +++ b/tests/mmptest/src/AssemblyReferencesTests.cs @@ -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"); }); } diff --git a/tests/monotouch-test/monotouch-test.csproj b/tests/monotouch-test/monotouch-test.csproj index f4f66bec08..84933fc6f8 100644 --- a/tests/monotouch-test/monotouch-test.csproj +++ b/tests/monotouch-test/monotouch-test.csproj @@ -156,7 +156,6 @@ - diff --git a/tests/xammac_tests/xammac_tests.csproj b/tests/xammac_tests/xammac_tests.csproj index bfdb67740a..e8ce769f56 100644 --- a/tests/xammac_tests/xammac_tests.csproj +++ b/tests/xammac_tests/xammac_tests.csproj @@ -60,7 +60,6 @@ -