Skip to content

Commit 6180752

Browse files
jonpryorradekdoulik
authored andcommitted
[Xamarin.Android-Tests] Split out "full" apps (dotnet#146)
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: <!-- src/Mono.Android/Test/Mono.Android-Tests.csproj --> <Reference Include="Xamarin.Android.NUnitLite" /> 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]: dotnet@a16673d [1]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/20/console [2]: dotnet#147 [^3]: [PR dotnet#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 dotnet#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
1 parent 6bbadd5 commit 6180752

File tree

6 files changed

+55
-33
lines changed

6 files changed

+55
-33
lines changed

Makefile

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ OS := $(shell uname)
22
OS_ARCH := $(shell uname -m)
33
V ?= 0
44
CONFIGURATION = Debug
5-
MSBUILD = xbuild /p:Configuration=$(CONFIGURATION) $(MSBUILD_ARGS)
5+
MSBUILD = xbuild
6+
MSBUILD_FLAGS = /p:Configuration=$(CONFIGURATION) $(MSBUILD_ARGS)
67
RUNTIME := $(shell if [ -f `which mono64` ] ; then echo mono64 ; else echo mono; fi) --debug=casts
8+
SOLUTION = Xamarin.Android.sln
79

810
NUNIT_TESTS = \
911
bin/Test$(CONFIGURATION)/Xamarin.Android.Build.Tests.dll
@@ -12,27 +14,31 @@ NUNIT_CONSOLE = packages/NUnit.ConsoleRunner.3.2.1/tools/nunit3-console.exe
1214

1315
ifneq ($(V),0)
1416
MONO_OPTIONS += --debug
15-
MSBUILD += /v:d
17+
MSBUILD_FLAGS += /v:d
1618
endif
1719

1820
ifneq ($(MONO_OPTIONS),)
1921
export MONO_OPTIONS
2022
endif
2123

22-
all:
23-
$(MSBUILD)
24+
all::
25+
$(MSBUILD) $(MSBUILD_FLAGS) $(SOLUTION)
26+
27+
all-tests::
28+
tools/scripts/xabuild $(MSBUILD_FLAGS) Xamarin.Android-Tests.sln
2429

2530
prepare:: prepare-external prepare-props
2631

2732
prepare-external:
2833
git submodule update --init --recursive
29-
nuget restore
30-
(cd `$(MSBUILD) /p:DoNotLoadOSProperties=True /nologo /v:minimal /t:GetJavaInteropFullPath build-tools/scripts/Paths.targets` && nuget restore)
34+
nuget restore $(SOLUTION)
35+
nuget restore Xamarin.Android-Tests.sln
36+
(cd `$(MSBUILD) $(MSBUILD_FLAGS) /p:DoNotLoadOSProperties=True /nologo /v:minimal /t:GetJavaInteropFullPath build-tools/scripts/Paths.targets` && nuget restore)
3137

3238
prepare-props:
3339
cp Configuration.Java.Interop.Override.props external/Java.Interop/Configuration.Override.props
3440
./build-tools/scripts/generate-os-info Configuration.OperatingSystem.props
35-
cp `$(MSBUILD) /nologo /v:minimal /t:GetMonoSourceFullPath build-tools/scripts/Paths.targets`/mcs/class/msfinal.pub .
41+
cp `$(MSBUILD) $(MSBUILD_FLAGS) /nologo /v:minimal /t:GetMonoSourceFullPath build-tools/scripts/Paths.targets`/mcs/class/msfinal.pub .
3642

3743
include build-tools/scripts/BuildEverything.mk
3844

@@ -91,7 +97,8 @@ endif
9197
run-all-tests: run-nunit-tests run-apk-tests
9298

9399
clean:
94-
$(MSBUILD) /t:Clean
100+
$(MSBUILD) $(MSBUILD_FLAGS) /t:Clean Xamarin.Android.sln
101+
tools/scripts/xabuild $(MSBUILD_FLAGS) /t:Clean Xamarin.Android-Tests.sln
95102

96103
distclean:
97104
# 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 = \
122129
define RUN_TEST_APK
123130
# Must use xabuild to ensure correct assemblies are resolved
124131
tools/scripts/xabuild /t:SignAndroidPackage $(1) && \
125-
$(MSBUILD) /t:UnDeploy $(1) && \
126-
$(MSBUILD) /t:Deploy $(1) && \
127-
$(MSBUILD) /t:RunTests $(1) $(if $(ADB_TARGET),"/p:AdbTarget=$(ADB_TARGET)",)
132+
$(MSBUILD) $(MSBUILD_FLAGS) /t:UnDeploy $(1) && \
133+
$(MSBUILD) $(MSBUILD_FLAGS) /t:Deploy $(1) && \
134+
$(MSBUILD) $(MSBUILD_FLAGS) /t:RunTests $(1) $(if $(ADB_TARGET),"/p:AdbTarget=$(ADB_TARGET)",)
128135
endef
129136

130137
run-apk-tests:

Xamarin.Android-Tests.sln

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Android-Tests", "src\Mono.Android\Test\Mono.Android-Tests.csproj", "{40EAD437-216B-4DF4-8258-3F47E1672C3A}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorld", "samples\HelloWorld\HelloWorld.csproj", "{2305B00D-DE81-4744-B0DA-357835CAFE5A}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{2305B00D-DE81-4744-B0DA-357835CAFE5A}.Release|Any CPU.Build.0 = Release|Any CPU
22+
EndGlobalSection
23+
EndGlobal

Xamarin.Android.sln

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xamarin.ProjectTools", "src
6565
EndProject
6666
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}"
6767
EndProject
68-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Android-Tests", "src\Mono.Android\Test\Mono.Android-Tests.csproj", "{40EAD437-216B-4DF4-8258-3F47E1672C3A}"
69-
EndProject
7068
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.EnterpriseServices", "src\System.EnterpriseServices\System.EnterpriseServices.csproj", "{2868FC32-A4E7-4008-87C8-2C7879CACB58}"
7169
EndProject
7270
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "unix-distribution-setup", "build-tools\unix-distribution-setup\unix-distribution-setup.mdproj", "{2CF172E5-BDAE-4ABA-8BC8-08040ED3E77A}"
@@ -275,18 +273,6 @@ Global
275273
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
276274
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
277275
{53E4ABF0-1085-45F9-B964-DCAE4B819998}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
278-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
279-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Debug|AnyCPU.Build.0 = Debug|Any CPU
280-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.ActiveCfg = Release|Any CPU
281-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.Release|AnyCPU.Build.0 = Release|Any CPU
282-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU
283-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU
284-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU
285-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU
286-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU
287-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU
288-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU
289-
{40EAD437-216B-4DF4-8258-3F47E1672C3A}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU
290276
{2868FC32-A4E7-4008-87C8-2C7879CACB58}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU
291277
{2868FC32-A4E7-4008-87C8-2C7879CACB58}.Debug|AnyCPU.Build.0 = Debug|Any CPU
292278
{2868FC32-A4E7-4008-87C8-2C7879CACB58}.Release|AnyCPU.ActiveCfg = Release|Any CPU
@@ -432,7 +418,6 @@ Global
432418
{4D603AA3-3BFD-43C8-8050-0CD6C2601126} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
433419
{2DD1EE75-6D8D-4653-A800-0A24367F7F38} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
434420
{53E4ABF0-1085-45F9-B964-DCAE4B819998} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
435-
{40EAD437-216B-4DF4-8258-3F47E1672C3A} = {CAB438D8-B0F5-4AF0-BEBD-9E2ADBD7B483}
436421
{2868FC32-A4E7-4008-87C8-2C7879CACB58} = {04E3E11E-B47D-4599-8AFC-50515A95E715}
437422
{2CF172E5-BDAE-4ABA-8BC8-08040ED3E77A} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62}
438423
{1A4B041A-842F-40B3-A50D-49E01D30BD18} = {04E3E11E-B47D-4599-8AFC-50515A95E715}

build-tools/scripts/BuildEverything.mk

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ FRAMEWORK_ASSEMBLIES = \
6161
leeroy jenkins: prepare $(RUNTIME_LIBRARIES) $(TASK_ASSEMBLIES) $(FRAMEWORK_ASSEMBLIES)
6262

6363
$(TASK_ASSEMBLIES): bin/%/lib/xbuild/Xamarin/Android/Xamarin.Android.Build.Tasks.dll:
64-
$(MSBUILD) /p:Configuration=$* $(_MSBUILD_ARGS)
64+
$(MSBUILD) $(MSBUILD_FLAGS) /p:Configuration=$* $(_MSBUILD_ARGS) $(SOLUTION)
6565

6666
$(FRAMEWORK_ASSEMBLIES):
6767
$(foreach a, $(API_LEVELS), \
68-
$(MSBUILD) src/Mono.Android/Mono.Android.csproj /p:Configuration=Debug $(_MSBUILD_ARGS) /p:AndroidApiLevel=$(a) /p:AndroidFrameworkVersion=$(word $(a), $(ALL_FRAMEWORKS)); \
69-
$(MSBUILD) src/Mono.Android/Mono.Android.csproj /p:Configuration=Release $(_MSBUILD_ARGS) /p:AndroidApiLevel=$(a) /p:AndroidFrameworkVersion=$(word $(a), $(ALL_FRAMEWORKS)); )
68+
$(MSBUILD) $(MSBUILD_FLAGS) src/Mono.Android/Mono.Android.csproj /p:Configuration=Debug $(_MSBUILD_ARGS) /p:AndroidApiLevel=$(a) /p:AndroidFrameworkVersion=$(word $(a), $(ALL_FRAMEWORKS)); \
69+
$(MSBUILD) $(MSBUILD_FLAGS) src/Mono.Android/Mono.Android.csproj /p:Configuration=Release $(_MSBUILD_ARGS) /p:AndroidApiLevel=$(a) /p:AndroidFrameworkVersion=$(word $(a), $(ALL_FRAMEWORKS)); )
7070

7171
$(RUNTIME_LIBRARIES):
72-
$(MSBUILD) /p:Configuration=Debug $(_MSBUILD_ARGS)
73-
$(MSBUILD) /p:Configuration=Release $(_MSBUILD_ARGS)
72+
$(MSBUILD) $(MSBUILD_FLAGS) /p:Configuration=Debug $(_MSBUILD_ARGS) $(SOLUTION)
73+
$(MSBUILD) $(MSBUILD_FLAGS) /p:Configuration=Release $(_MSBUILD_ARGS) $(SOLUTION)

samples/HelloWorld/HelloWorld.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
<OutputType>Library</OutputType>
99
<RootNamespace>HelloWorld</RootNamespace>
1010
<AssemblyName>HelloWorld</AssemblyName>
11-
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
1211
<AndroidApplication>True</AndroidApplication>
1312
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
1413
<AndroidResgenClass>Resource</AndroidResgenClass>
@@ -17,6 +16,10 @@
1716
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
1817
<AndroidUseLatestPlatformSdk>true</AndroidUseLatestPlatformSdk>
1918
</PropertyGroup>
19+
<Import Project="..\..\..\Configuration.props" />
20+
<PropertyGroup>
21+
<TargetFrameworkVersion>$(AndroidFrameworkVersion)</TargetFrameworkVersion>
22+
</PropertyGroup>
2023
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2124
<DebugSymbols>true</DebugSymbols>
2225
<DebugType>full</DebugType>

tools/scripts/xabuild

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ if [ -z "$CONFIGURATION" ] ; then
55
CONFIGURATION=Debug
66
fi
77

8+
if [ -z "$MSBUILD" ] ; then
9+
MSBUILD=xbuild
10+
fi
11+
812
export TARGETS_DIR="$topdir/bin/$CONFIGURATION/lib/xbuild"
913
export MSBuildExtensionsPath="$TARGETS_DIR"
1014
export MONO_ANDROID_PATH="$topdir/bin/$CONFIGURATION"
@@ -18,7 +22,7 @@ ANDROID_SDK_PATH=$(echo $ANDROID_SDK_PATH | sed 's/^\w*//g')
1822
export ANDROID_NDK_PATH
1923
export ANDROID_SDK_PATH
2024

21-
exec xbuild /p:Configuration=Release $MSBUILD_OPTIONS \
25+
exec $MSBUILD /p:Configuration=$CONFIGURATION $MSBUILD_OPTIONS \
2226
/p:AndroidNdkDirectory="$ANDROID_NDK_PATH" \
2327
/p:AndroidSdkDirectory="$ANDROID_SDK_PATH" \
2428
/p:MonoDroidInstallDirectory="$MONO_ANDROID_PATH" \

0 commit comments

Comments
 (0)