Skip to content

Commit

Permalink
[d16-2] [msbuild] Add reference to System.Drawing.Common.dll to XI …
Browse files Browse the repository at this point in the history
…projects. (xamarin#6035)

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

Fixes mono/mono#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.
  • Loading branch information
monojenkins authored and rolfbjarne committed May 10, 2019
1 parent 557d435 commit daf5006
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 21 deletions.
7 changes: 7 additions & 0 deletions msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 24 additions & 14 deletions msbuild/tests/Xamarin.iOS.Tasks.Tests/TargetTests/TargetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,28 +139,38 @@ public void GetReferencedAssemblies_Executable ()
{
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]
public void GetReferencedAssemblies_Library ()
{
RunTargetOnInstance (LibraryProjectInstance, TargetName.ResolveReferences);
var references = LibraryProjectInstance.GetItems ("ReferencePath").ToArray ();

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 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);

var actual_references = references.Select ((v) => Path.GetFileName (v.EvaluatedInclude)).OrderBy ((v) => v);
CollectionAssert.AreEquivalent (expected_references, actual_references, "References");
}

[Test]
Expand Down
16 changes: 13 additions & 3 deletions tests/common/mac/ProjectTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ public class UnifiedTestConfig
// 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;
Expand Down Expand Up @@ -427,9 +439,7 @@ public static string GenerateAndBuildUnifiedExecutable (UnifiedTestConfig config

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)
Expand Down
1 change: 0 additions & 1 deletion tests/introspection/iOS/introspection-ios.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
7 changes: 6 additions & 1 deletion tests/mmptest/src/AssemblyReferencesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;

Expand All @@ -17,7 +18,11 @@ public void ShouldNotAllowReference_ToSystemDrawing ()
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");
});
}

Expand Down
1 change: 0 additions & 1 deletion tests/monotouch-test/monotouch-test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
1 change: 0 additions & 1 deletion tests/xammac_tests/xammac_tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit daf5006

Please sign in to comment.