From 6b7f744e0b0a5044cb9ee44e4946b9f00aa13650 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Thu, 4 Aug 2016 16:26:40 -0400 Subject: [PATCH] [Xamarin.Android-Tests] Split out "full" apps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're trying to get [`make jenkins`][0] working on Jenkins, and [it's failing][1], as one might expect when a particular repo and associated build system has never been run on Jenkins before: Android.App/ApplicationTest.cs(9,7): error CS0246: The type or namespace name `NUnit' could not be found. Are you missing an assembly reference? This error occurs while building `src/Mono.Android/Test/Mono.Android-Tests.csproj`, and happens because the `Xamarin.Android.NUnitLite.dll` assembly isn't referenced... because it isn't *found*: Microsoft.Common.targets: warning : Reference 'Xamarin.Android.NUnitLite' not resolved This returns us to a long-standing issue which I thought was mentioned in a commit somewhere, but I can't find at present: MSBuild doesn't support updating the assembly resolution directories *while MSBuild is running*. For example, we build `Xamarin.Android.NUniteLite.dll` into `bin/$(Configuration/lib/xbuild-frameworks/MonoAndroid/v1.0`, but "normal Xamarin.Android referencing projects" don't use a `@(ProjectReference)` to `Xamarin.Android.NUnitLite.csproj`, but instead a `@(Reference)` to the assembly: The *requirement* for a "proper" Xamarin.Android SDK install is that `Xamarin.Android.NUnitLite.dll` can be found through a normal `@(Reference)`. In order to satisfy this requirement, we need to tell MSBuild where to find it, which can be with `xbuild` via the `$MSBuildExtensionsPath` and `$XBUILD_FRAMEWORK_FOLDERS_PATH` *environment variables*. *Environment variables*. MSBuild doesn't provide a way to update environment variables, short of writing a new Task which calls `Environment.SetEnvironmentVariable()`, and while [this works][2], it doesn't *actually* work [^3]. The short of all this is that it isn't possible, *within a single `xbuild` invocation*, to both build the Xamarin.Android SDK "environment" *and use that environment* as intended for "normal" apps. The fix, as is often the case, is to bend with the wind. Instead of requiring the impossible, move `src/Mono.Android/Test/Mono.Android-Tests.csproj` into a *new* `Xamarin.Android-Tests.sln` solution, *out of* `Xamarin.Android.sln`. This allows building `Xamarin.Android.sln` without error in a pristine environment -- that is, one that doesn't already have a system-wide Xamarin.Android install -- and separately building the tests by using `tools/scripts/xabuild`, which *can* export environment variables to manipulate `xbuild` behavior so that things Just Work™. Building `Mono.Android-Tests.csproj` and similar projects (`HelloWorld.csproj`!) can be done by using the new `make all-tests` make target. [0]: https://github.com/xamarin/xamarin-android/commit/a16673d3eb2c4945c3a74f5f8154603d7658fc9a [1]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/20/console [2]: https://github.com/xamarin/xamarin-android/pull/147 [^3]: [PR #147][2] isn't viable because of [xbuild's `AsssemblyResolver`][4]. There's no way to clear/invalidate `target_framework_cache`. The idea of PR #147 was to "hack things up" so that `Xamarin.Android.NuniteLite.dll` would be properly resolved during the build of `Mono.Android-Tests.csproj` *when building everything*. The problem is *this can't work*, because `xbuild` has a "target framework cache," with no way to invalidate it, and the cache is populated the first time the target framework is used. Due to build ordering issues, this first use is *before* `Xamarin.Android.NunitLite.dll` was built, and thus it doesn't exist in the cache. The result: Task "ResolveAssemblyReference" .... TargetFrameworkDirectories: /Volumes/Seagate4TB/work/xamarin-android/bin/Debug/lib/xbuild-frameworks/MonoAndroid/v7.0 /Volumes/Seagate4TB/work/xamarin-android/bin/Debug/lib/xbuild-frameworks/MonoAndroid/v1.0 /Volumes/Seagate4TB/work/xamarin-android/bin/Debug/lib/xbuild-frameworks/MonoAndroid/v1.0/Facades/ ... Primary Reference System.Xml Reference System.Xml resolved to /Volumes/Seagate4TB/work/xamarin-android/bin/Debug/lib/xbuild-frameworks/MonoAndroid/v1.0/System.Xml.dll. CopyLocal = False ... Primary Reference Xamarin.Android.NUnitLite Microsoft.Common.targets: warning : Reference 'Xamarin.Android.NUnitLite' not resolved For searchpath {TargetFrameworkDirectory} Considered target framework dir /Volumes/Seagate4TB/work/xamarin-android/bin/Debug/lib/xbuild-frameworks/MonoAndroid/v7.0, assembly named 'Xamarin.Android.NUnitLite' not found. Considered target framework dir /Volumes/Seagate4TB/work/xamarin-android/bin/Debug/lib/xbuild-frameworks/MonoAndroid/v1.0, assembly named 'Xamarin.Android.NUnitLite' not found. Considered target framework dir /Volumes/Seagate4TB/work/xamarin-android/bin/Debug/lib/xbuild-frameworks/MonoAndroid/v1.0/Facades/, assembly named 'Xamarin.Android.NUnitLite' not found. ... Consequently, the `mcs` invocation is missing a `/reference:path/to/Xamarin.Android.NUniteLite.dll`, and compilation fails: Android.App/ApplicationTest.cs(9,7): error CS0246: The type or namespace name `NUnit' could not be found. Are you missing an assembly reference? ...plus 29 others... [4]: https://github.com/mono/mono/blob/dd8aadf/mcs/class/Microsoft.Build.Tasks/Microsoft.Build.Tasks/AssemblyResolver.cs#L131 --- Makefile | 29 ++++++++++++++++---------- Xamarin.Android-Tests.sln | 23 ++++++++++++++++++++ Xamarin.Android.sln | 15 ------------- build-tools/scripts/BuildEverything.mk | 10 ++++----- samples/HelloWorld/HelloWorld.csproj | 5 ++++- tools/scripts/xabuild | 6 +++++- 6 files changed, 55 insertions(+), 33 deletions(-) create mode 100644 Xamarin.Android-Tests.sln diff --git a/Makefile b/Makefile index 678ceee527b..bbe4bb981f2 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,10 @@ OS := $(shell uname) OS_ARCH := $(shell uname -m) V ?= 0 CONFIGURATION = Debug -MSBUILD = xbuild /p:Configuration=$(CONFIGURATION) $(MSBUILD_ARGS) +MSBUILD = xbuild +MSBUILD_FLAGS = /p:Configuration=$(CONFIGURATION) $(MSBUILD_ARGS) RUNTIME := $(shell if [ -f `which mono64` ] ; then echo mono64 ; else echo mono; fi) --debug=casts +SOLUTION = Xamarin.Android.sln NUNIT_TESTS = \ bin/Test$(CONFIGURATION)/Xamarin.Android.Build.Tests.dll @@ -12,27 +14,31 @@ NUNIT_CONSOLE = packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe ifneq ($(V),0) MONO_OPTIONS += --debug -MSBUILD += /v:d +MSBUILD_FLAGS += /v:d endif ifneq ($(MONO_OPTIONS),) export MONO_OPTIONS endif -all: - $(MSBUILD) +all:: + $(MSBUILD) $(MSBUILD_FLAGS) $(SOLUTION) + +all-tests:: + tools/scripts/xabuild $(MSBUILD_FLAGS) Xamarin.Android-Tests.sln prepare:: prepare-external prepare-props prepare-external: git submodule update --init --recursive - nuget restore - (cd `$(MSBUILD) /p:DoNotLoadOSProperties=True /nologo /v:minimal /t:GetJavaInteropFullPath build-tools/scripts/Paths.targets` && nuget restore) + nuget restore $(SOLUTION) + nuget restore Xamarin.Android-Tests.sln + (cd `$(MSBUILD) $(MSBUILD_FLAGS) /p:DoNotLoadOSProperties=True /nologo /v:minimal /t:GetJavaInteropFullPath build-tools/scripts/Paths.targets` && nuget restore) prepare-props: cp Configuration.Java.Interop.Override.props external/Java.Interop/Configuration.Override.props ./build-tools/scripts/generate-os-info Configuration.OperatingSystem.props - cp `$(MSBUILD) /nologo /v:minimal /t:GetMonoSourceFullPath build-tools/scripts/Paths.targets`/mcs/class/msfinal.pub . + cp `$(MSBUILD) $(MSBUILD_FLAGS) /nologo /v:minimal /t:GetMonoSourceFullPath build-tools/scripts/Paths.targets`/mcs/class/msfinal.pub . include build-tools/scripts/BuildEverything.mk @@ -91,7 +97,8 @@ endif run-all-tests: run-nunit-tests run-apk-tests clean: - $(MSBUILD) /t:Clean + $(MSBUILD) $(MSBUILD_FLAGS) /t:Clean Xamarin.Android.sln + tools/scripts/xabuild $(MSBUILD_FLAGS) /t:Clean Xamarin.Android-Tests.sln distclean: # It may fail if we're cleaning a half-built tree, no harm done if we ignore it @@ -122,9 +129,9 @@ TEST_APK_PROJECTS = \ define RUN_TEST_APK # Must use xabuild to ensure correct assemblies are resolved tools/scripts/xabuild /t:SignAndroidPackage $(1) && \ - $(MSBUILD) /t:UnDeploy $(1) && \ - $(MSBUILD) /t:Deploy $(1) && \ - $(MSBUILD) /t:RunTests $(1) $(if $(ADB_TARGET),"/p:AdbTarget=$(ADB_TARGET)",) + $(MSBUILD) $(MSBUILD_FLAGS) /t:UnDeploy $(1) && \ + $(MSBUILD) $(MSBUILD_FLAGS) /t:Deploy $(1) && \ + $(MSBUILD) $(MSBUILD_FLAGS) /t:RunTests $(1) $(if $(ADB_TARGET),"/p:AdbTarget=$(ADB_TARGET)",) endef run-apk-tests: diff --git a/Xamarin.Android-Tests.sln b/Xamarin.Android-Tests.sln new file mode 100644 index 00000000000..8e31b055480 --- /dev/null +++ b/Xamarin.Android-Tests.sln @@ -0,0 +1,23 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Android-Tests", "src\Mono.Android\Test\Mono.Android-Tests.csproj", "{40EAD437-216B-4DF4-8258-3F47E1672C3A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "samples\HelloWorld\HelloWorld.csproj", "{2305B00D-DE81-4744-B0DA-357835CAFE5A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|Any CPU.Build.0 = Release|Any CPU + {2305B00D-DE81-4744-B0DA-357835CAFE5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2305B00D-DE81-4744-B0DA-357835CAFE5A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2305B00D-DE81-4744-B0DA-357835CAFE5A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2305B00D-DE81-4744-B0DA-357835CAFE5A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Xamarin.Android.sln b/Xamarin.Android.sln index e9bee5053e7..61302a1b9e9 100644 --- a/Xamarin.Android.sln +++ b/Xamarin.Android.sln @@ -63,8 +63,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.ProjectTools", "src EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.Android.Build.Tests", "src\Xamarin.Android.Build.Tasks\Tests\Xamarin.Android.Build.Tests\Xamarin.Android.Build.Tests.csproj", "{53E4ABF0-1085-45F9-B964-DCAE4B819998}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Android-Tests", "src\Mono.Android\Test\Mono.Android-Tests.csproj", "{40EAD437-216B-4DF4-8258-3F47E1672C3A}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.EnterpriseServices", "src\System.EnterpriseServices\System.EnterpriseServices.csproj", "{2868FC32-A4E7-4008-87C8-2C7879CACB58}" EndProject Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "unix-distribution-setup", "build-tools\unix-distribution-setup\unix-distribution-setup.mdproj", "{2CF172E5-BDAE-4ABA-8BC8-08040ED3E77A}" @@ -273,18 +271,6 @@ Global {53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU {53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU {53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.Build.0 = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.ActiveCfg = Release|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.Build.0 = Release|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU - {40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU {2868FC32-A4E7-4008-87C8-2C7879CACB58}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU {2868FC32-A4E7-4008-87C8-2C7879CACB58}.Debug|AnyCPU.Build.0 = Debug|Any CPU {2868FC32-A4E7-4008-87C8-2C7879CACB58}.Release|AnyCPU.ActiveCfg = Release|Any CPU @@ -429,7 +415,6 @@ Global {4D603AA3-3BFD-43C8-8050-0CD6C2601126} = {04E3E11E-B47D-4599-8AFC-50515A95E715} {2DD1EE75-6D8D-4653-A800-0A24367F7F38} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483} {53E4ABF0-1085-45F9-B964-DCAE4B819998} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483} - {40EAD437-216B-4DF4-8258-3F47E1672C3A} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483} {2868FC32-A4E7-4008-87C8-2C7879CACB58} = {04E3E11E-B47D-4599-8AFC-50515A95E715} {2CF172E5-BDAE-4ABA-8BC8-08040ED3E77A} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62} {1A4B041A-842F-40B3-A50D-49E01D30BD18} = {04E3E11E-B47D-4599-8AFC-50515A95E715} diff --git a/build-tools/scripts/BuildEverything.mk b/build-tools/scripts/BuildEverything.mk index 494389b6dd4..e630e5d69d6 100644 --- a/build-tools/scripts/BuildEverything.mk +++ b/build-tools/scripts/BuildEverything.mk @@ -61,13 +61,13 @@ FRAMEWORK_ASSEMBLIES = \ leeroy jenkins: prepare $(RUNTIME_LIBRARIES) $(TASK_ASSEMBLIES) $(FRAMEWORK_ASSEMBLIES) $(TASK_ASSEMBLIES): bin/%/lib/xbuild/Xamarin/Android/Xamarin.Android.Build.Tasks.dll: - $(MSBUILD) /p:Configuration=$* $(_MSBUILD_ARGS) + $(MSBUILD) $(MSBUILD_FLAGS) /p:Configuration=$* $(_MSBUILD_ARGS) $(SOLUTION) $(FRAMEWORK_ASSEMBLIES): $(foreach a, $(API_LEVELS), \ - $(MSBUILD) src/Mono.Android/Mono.Android.csproj /p:Configuration=Debug $(_MSBUILD_ARGS) /p:AndroidApiLevel=$(a) /p:AndroidFrameworkVersion=$(word $(a), $(ALL_FRAMEWORKS)); \ - $(MSBUILD) src/Mono.Android/Mono.Android.csproj /p:Configuration=Release $(_MSBUILD_ARGS) /p:AndroidApiLevel=$(a) /p:AndroidFrameworkVersion=$(word $(a), $(ALL_FRAMEWORKS)); ) + $(MSBUILD) $(MSBUILD_FLAGS) src/Mono.Android/Mono.Android.csproj /p:Configuration=Debug $(_MSBUILD_ARGS) /p:AndroidApiLevel=$(a) /p:AndroidFrameworkVersion=$(word $(a), $(ALL_FRAMEWORKS)); \ + $(MSBUILD) $(MSBUILD_FLAGS) src/Mono.Android/Mono.Android.csproj /p:Configuration=Release $(_MSBUILD_ARGS) /p:AndroidApiLevel=$(a) /p:AndroidFrameworkVersion=$(word $(a), $(ALL_FRAMEWORKS)); ) $(RUNTIME_LIBRARIES): - $(MSBUILD) /p:Configuration=Debug $(_MSBUILD_ARGS) - $(MSBUILD) /p:Configuration=Release $(_MSBUILD_ARGS) + $(MSBUILD) $(MSBUILD_FLAGS) /p:Configuration=Debug $(_MSBUILD_ARGS) $(SOLUTION) + $(MSBUILD) $(MSBUILD_FLAGS) /p:Configuration=Release $(_MSBUILD_ARGS) $(SOLUTION) diff --git a/samples/HelloWorld/HelloWorld.csproj b/samples/HelloWorld/HelloWorld.csproj index 5697c811fc8..29ebf50835d 100644 --- a/samples/HelloWorld/HelloWorld.csproj +++ b/samples/HelloWorld/HelloWorld.csproj @@ -8,7 +8,6 @@ Library HelloWorld HelloWorld - v5.0 True Resources\Resource.designer.cs Resource @@ -17,6 +16,10 @@ Assets true + + + $(AndroidFrameworkVersion) + true full diff --git a/tools/scripts/xabuild b/tools/scripts/xabuild index 3a8b3a6b0ae..0b3578e3f51 100755 --- a/tools/scripts/xabuild +++ b/tools/scripts/xabuild @@ -5,6 +5,10 @@ if [ -z "$CONFIGURATION" ] ; then CONFIGURATION=Debug fi +if [ -z "$MSBUILD" ] ; then + MSBUILD=xbuild +fi + export TARGETS_DIR="$topdir/bin/$CONFIGURATION/lib/xbuild" export MSBuildExtensionsPath="$TARGETS_DIR" export MONO_ANDROID_PATH="$topdir/bin/$CONFIGURATION" @@ -18,7 +22,7 @@ ANDROID_SDK_PATH=$(echo $ANDROID_SDK_PATH | sed 's/^\w*//g') export ANDROID_NDK_PATH export ANDROID_SDK_PATH -exec xbuild /p:Configuration=Release $MSBUILD_OPTIONS \ +exec $MSBUILD /p:Configuration=$CONFIGURATION $MSBUILD_OPTIONS \ /p:AndroidNdkDirectory="$ANDROID_NDK_PATH" \ /p:AndroidSdkDirectory="$ANDROID_SDK_PATH" \ /p:MonoDroidInstallDirectory="$MONO_ANDROID_PATH" \