From f3d04eb3a4d235cffef451e63c907caf6bacbaba Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Mon, 23 Jan 2017 10:50:47 -0500 Subject: [PATCH] [build] Fix the Linux build (Take 2?) As feared, commit 743529c1's removal of `$(TargetFrameworkRootPath)` [broke the Linux build][0]: Gui/Activities/TestSuiteActivity.cs(25,35): error CS0012: The type `System.IDisposable' is defined in an assembly that is not referenced. Consider adding a reference to assembly `System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' macOS is unaffected as [it's unfortunately using System files][1]: Found framework definition list '/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/RedistList/FrameworkList.xml' for framework 'MonoAndroid,Version=v1.0' (Heavy sigh.) Thus, our scenario: `msbuild` doesn't like our setting `$(TargetFrameworkRootPath)`, yet `$(TargetFrameworkRootPath)` needs to be set for Linux+xbuild to work, because Linux+xbuild doesn't have a system-wide Xamarin.Android install. (Not that we want to require a Xamarin.Android install! But that's just why macOS is building...) The fix? Split the difference, somewhat. We can't set `$(TargetFrameworkRootPath)` for *everything*, but we *can* override it for *specific projects*. Update `Mono.Data.Sqlite.csproj`, `Mono.Posix.csproj`, `OpenTK.csproj`, `System.Drawing.Primitives.csproj`, `System.EnterpriseServices.csproj`, and `Xamarin.Android.NUnitLite.csproj` to `` the new `build-tools/scripts/MonoAndroidFramework.props` file, which overrides `$(TargetFrameworkRootPath)` and other MSBuild properties appropriately, so that they resolve the `MonoAndroid` framework assemblies from the internal build tree. What's left is `Mono.Android.csproj` and `Mono.Android.Export.csproj`, which don't `` `Xamarin.Android.CSharp.targets`. These are the projects that needed to "hack in" a `@(Reference)` to `System.Runtime` in 7343965, which was removed in 743529c1. The fix is more voodoo in each of them: * Set `$(ImplicitlyExpandDesignTimeFacades)`=False and provide a `%(Reference.HintPath) value for `System.Runtime` so that it can be found. We *don't* want `$(ImplicitlyExpandDesignTimeFacades)`=True because that can cause all manner of madness on macOS, as it "implicitly expands facades", pulling in facades from *both* the internal build tree *and* the system-wide location. (Madness, and duplicate assembly reference errors, ensue.) * Set `$(TargetFrameworkIdentifier)`=MonoAndroid, so we're looking for the correct framework. * Set `$(TargetFrameworkRootPath)` so that the MonoAndroid framework can be found in the local build tree. * Set `$(TargetFrameworkVersion)` to a valid MonoAndroid framework version number. This allows `Mono.Android.Export.csproj`. `Mono.Android.csproj` needs one more fix: in order for frameworks to be resolved from a "clean" state, `RedistList\FrameworkList.xml` must exist before attempting to resolve assemblies. Fix the `_GenerateFrameworkList` target so that `FrameworkList.xml` is created *before* the `ResolveReferences` target, thus allowing the `MonoAndroid,v7.1` framework to be found. One more final tidbit: `MonoAndroidFramework.props` and `msbuild.mk` in concert use (and set) the new `$(_XAFixMSBuildFrameworkPathOverride)` MSBuild property, which is set when: 1. `msbuild` is being used, and 2. Mono is a version prior to Mono 4.8. The `msbuild` included in Mono prior to 4.8 has a known bug where [`$(FrameworkOverridePath)` doesn't respect `$(TargetFrameworkRootPath)`][2]. Without this fix, *too many* `mscorlib.dll` files are used in various parts of the build process (via `@(_ExplicitReference)`), which causes yet more sadness. When using `msbuild` prior to Mono 4.8, explicitly set the `$(FrameworkOverridePath)` property to a valid value. [0]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-linux/173/ [1]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/207/consoleText [2]: https://github.com/mono/msbuild/commit/9d7b4b5cf9ba50e3e26a202e3d3e0d35cc50da19 --- build-tools/scripts/MonoAndroidFramework.props | 11 +++++++++++ build-tools/scripts/msbuild.mk | 7 +++++++ src/Mono.Android.Export/Mono.Android.Export.csproj | 13 ++++++++++++- src/Mono.Android/Mono.Android.csproj | 11 ++++++++++- src/Mono.Android/Mono.Android.targets | 2 +- src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj | 2 +- src/Mono.Posix/Mono.Posix.csproj | 2 +- src/OpenTK-1.0/OpenTK.csproj | 2 +- .../System.Drawing.Primitives.csproj | 2 +- .../System.EnterpriseServices.csproj | 9 +++++++++ .../Xamarin.Android.NUnitLite.csproj | 1 + 11 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 build-tools/scripts/MonoAndroidFramework.props diff --git a/build-tools/scripts/MonoAndroidFramework.props b/build-tools/scripts/MonoAndroidFramework.props new file mode 100644 index 00000000000..99be168b14f --- /dev/null +++ b/build-tools/scripts/MonoAndroidFramework.props @@ -0,0 +1,11 @@ + + + + + $(AndroidFrameworkVersion) + $(MSBuildThisFileDirectory)..\..\bin\$(Configuration)\lib\xbuild-frameworks + $(TargetFrameworkRootPath)\MonoAndroid\v1.0 + + diff --git a/build-tools/scripts/msbuild.mk b/build-tools/scripts/msbuild.mk index bb99fdc7278..5a4e19fd5ff 100644 --- a/build-tools/scripts/msbuild.mk +++ b/build-tools/scripts/msbuild.mk @@ -27,3 +27,10 @@ MSBUILD_FLAGS = /p:Configuration=$(CONFIGURATION) $(MSBUILD_ARGS) ifneq ($(V),0) MSBUILD_FLAGS += /v:diag endif # $(V) != 0 + +ifeq ($(MSBUILD),msbuild) +_BROKEN_MSBUILD := $(shell if ! pkg-config --atleast-version=4.8 mono ; then echo Broken; fi ) +ifeq ($(_BROKEN_MSBUILD),Broken) +MSBUILD_FLAGS += /p:_XAFixMSBuildFrameworkPathOverride=True +endif # $(_BROKEN_MSBUILD) == Broken +endif # $(MSBUILD) == msbuild diff --git a/src/Mono.Android.Export/Mono.Android.Export.csproj b/src/Mono.Android.Export/Mono.Android.Export.csproj index 6e4f08296ef..86297c0a0cf 100644 --- a/src/Mono.Android.Export/Mono.Android.Export.csproj +++ b/src/Mono.Android.Export/Mono.Android.Export.csproj @@ -7,11 +7,15 @@ Library Mono.Android.Export Mono.Android.Export - v4.5 true ..\..\product.snk + + MonoAndroid + $(AndroidFrameworkVersion) + ..\..\bin\$(Configuration)\lib\xbuild-frameworks + true full @@ -54,6 +58,10 @@ $(OutputPath)..\v1.0\Java.Interop.dll False + + $(OutputPath)..\v1.0\Facades\System.Runtime.dll + False + @@ -108,6 +116,9 @@ + + False + {66CF299A-CE95-4131-BCD8-DB66E30C4BF7} diff --git a/src/Mono.Android/Mono.Android.csproj b/src/Mono.Android/Mono.Android.csproj index 47f96ee4e68..33b4eee3bc7 100644 --- a/src/Mono.Android/Mono.Android.csproj +++ b/src/Mono.Android/Mono.Android.csproj @@ -7,11 +7,15 @@ Library Android Mono.Android - v4.5 true ..\..\product.snk + + MonoAndroid + $(AndroidFrameworkVersion) + ..\..\bin\$(Configuration)\lib\xbuild-frameworks + true full @@ -65,6 +69,10 @@ $(OutputPath)..\v1.0\Java.Interop.dll False + + $(OutputPath)..\v1.0\Facades\System.Runtime.dll + False + @@ -302,6 +310,7 @@ + False $(IntermediateOutputPath)android-$(AndroidApiLevel)\ diff --git a/src/Mono.Android/Mono.Android.targets b/src/Mono.Android/Mono.Android.targets index 8a9659b97cd..9b7e876dc7d 100644 --- a/src/Mono.Android/Mono.Android.targets +++ b/src/Mono.Android/Mono.Android.targets @@ -197,7 +197,7 @@ /> diff --git a/src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj b/src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj index 4deeef17488..28cab7a22e0 100644 --- a/src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj +++ b/src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj @@ -18,8 +18,8 @@ false + - $(AndroidFrameworkVersion) $(MonoSourceFullPath)\mcs\class\mono.pub diff --git a/src/Mono.Posix/Mono.Posix.csproj b/src/Mono.Posix/Mono.Posix.csproj index bfd4c614d3a..38623200664 100644 --- a/src/Mono.Posix/Mono.Posix.csproj +++ b/src/Mono.Posix/Mono.Posix.csproj @@ -18,8 +18,8 @@ false + - $(AndroidFrameworkVersion) $(MonoSourceFullPath)\mcs\class\mono.pub diff --git a/src/OpenTK-1.0/OpenTK.csproj b/src/OpenTK-1.0/OpenTK.csproj index a4f82c328a4..5d878526453 100644 --- a/src/OpenTK-1.0/OpenTK.csproj +++ b/src/OpenTK-1.0/OpenTK.csproj @@ -23,8 +23,8 @@ false + - $(AndroidFrameworkVersion) $(MonoSourceFullPath)\mcs\class\mono.pub diff --git a/src/System.Drawing.Primitives/System.Drawing.Primitives.csproj b/src/System.Drawing.Primitives/System.Drawing.Primitives.csproj index bedfa443455..0fb93e4ef8f 100644 --- a/src/System.Drawing.Primitives/System.Drawing.Primitives.csproj +++ b/src/System.Drawing.Primitives/System.Drawing.Primitives.csproj @@ -15,8 +15,8 @@ false + - $(AndroidFrameworkVersion) $(MonoSourceFullPath)\mcs\class\mono.pub diff --git a/src/System.EnterpriseServices/System.EnterpriseServices.csproj b/src/System.EnterpriseServices/System.EnterpriseServices.csproj index 44590940c1c..3a837497e59 100644 --- a/src/System.EnterpriseServices/System.EnterpriseServices.csproj +++ b/src/System.EnterpriseServices/System.EnterpriseServices.csproj @@ -11,6 +11,8 @@ true ..\..\product.snk + + true full @@ -40,4 +42,11 @@ + + + {66CF299A-CE95-4131-BCD8-DB66E30C4BF7} + Mono.Android + False + + \ No newline at end of file diff --git a/src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj b/src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj index b0feaeb6d16..2e309047008 100644 --- a/src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj +++ b/src/Xamarin.Android.NUnitLite/Xamarin.Android.NUnitLite.csproj @@ -17,6 +17,7 @@ false + true full