Skip to content

Commit 944f88a

Browse files
authored
[build] Fix issues preventing parallel builds (#7068)
Changes: dotnet/java-interop@d0ef9e3...51c3dae * dotnet/java-interop@51c3dae7: [Java.Interop-MonoAndroid.csproj] Add jnienv-gen ProjectReference (#990) Remove all instances of `dotnet build -m:1` from the build system, and fix all issues which prevent it from appearing to work. (Testing was via 4 consecutive CI builds without errors. This does not mean it's a complete fix, but it seems good enough to merge.) Fixes include: Using `build-tools/create-android-api` (9987069) to build `JNIEnv.g.cs` only once, instead of once per `$(TargetFrameworkVersion)`. This prevents sharing violations when multiple `Mono.Android.csproj` builds attempt to create it simultaneously: System.IO.IOException: The process cannot access the file 'C:\a\_work\1\s\src\Mono.Android\Android.Runtime\JNIEnv.g.cs' because it is being used by another process. *Serialize* gradlew-using project references, such that `r8.csproj` has a `@(ProjectReference)` to `manifestmerger.csproj`, and `manifestmerger.csproj` has a `@(ProjectReference)` to `apksigner.csproj`. `gradlew` execution can time out when multiple `gradlew` instances are run concurrently, even if `gradlew --no-daemon` is used. Serializing these project references avoids the errors: org.gradle.launcher.daemon.client.DaemonConnectionException: Timeout waiting to connect to the Gradle daemon. The file lock is held by a different Gradle process. Add a `@(ProjectReference)` on `Microsoft.Android.Sdk.ILLink.csproj` to `Xamarin.Android.Build.Tasks.csproj`, so that `Xamarin.Android.Build.Tasks\obj\$(Configuration)\Profile.g.cs` is available for compilation. Fixes: CSC error CS2001: Source file 'C:\code\xamarin-android\src\Microsoft.Android.Sdk.ILLink\..\Xamarin.Android.Build.Tasks\obj\Debug\Profile.g.cs' could not be found. Commit dotnet/java-interop@51c3dae7, which adds a `@(ProjectReference)` on `Java.Interop-MonoAndroid.csproj` to `jnienv-gen.csproj`, which ensures that `jnienv-gen.exe` exists when `Java.Interop-MonoAndroid.csproj` is built. Fix errors such as: '"C:\a\_work\1\s\external\Java.Interop\bin\BuildRelease\jnienv-gen.exe"' is not recognized as an internal or external command, operable program or batch file. or …/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop.targets(19,5): error MSB3073: The command "mono "…/xamarin-android/external/Java.Interop/bin/BuildDebug/jnienv-gen.exe" Java.Interop/JniEnvironment.g.cs obj/Debug/jni.c" exited with code 2. […/xamarin-android/external/Java.Interop/src/Java.Interop/Java.Interop-MonoAndroid.csproj]
1 parent 8259f6d commit 944f88a

File tree

10 files changed

+34
-18
lines changed

10 files changed

+34
-18
lines changed

Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
<ProduceReferenceAssemblyInOutDir>true</ProduceReferenceAssemblyInOutDir>
2222
<!-- Ensure command-line apps can use a newer .NET -->
2323
<RollForward>Major</RollForward>
24+
<!-- We don't need to be warned that we are using a preview .NET -->
25+
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
2426
</PropertyGroup>
2527

2628
<PropertyGroup Condition=" '$(MSBuildRuntimeType)' == 'Core' ">

build-tools/automation/azure-pipelines.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ stages:
208208
parameters:
209209
project: Xamarin.Android.sln
210210
arguments: >-
211-
-t:BuildDotNet,PackDotNet -c $(XA.Build.Configuration) -m:1 -v:n
211+
-t:BuildDotNet,PackDotNet -c $(XA.Build.Configuration) -v:n
212212
-bl:$(System.DefaultWorkingDirectory)\bin\Build$(XA.Build.Configuration)\dotnet-build.binlog
213213
displayName: Build Solution
214214
continueOnError: false

build-tools/create-android-api/create-android-api.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ProjectReference Include="..\..\external\Java.Interop\tools\class-parse\class-parse.csproj" ReferenceOutputAssembly="False" />
1313
<ProjectReference Include="..\api-xml-adjuster\api-xml-adjuster.csproj" ReferenceOutputAssembly="False" />
1414
<ProjectReference Include="..\api-merge\api-merge.csproj" ReferenceOutputAssembly="False" />
15+
<ProjectReference Include="..\jnienv-gen\jnienv-gen.csproj" ReferenceOutputAssembly="False" SkipGetTargetFrameworkProperties="True" AdditionalProperties="TargetFramework=net472" />
1516
</ItemGroup>
1617

1718
<PropertyGroup>
@@ -117,6 +118,17 @@
117118
Command="$(ManagedRuntime) $(ManagedRuntimeArgs) $(ApiMerge) -config=$(_ConfigurationFile) -config-input-dir=$(_ConfigurationInputBaseDirectory) -config-output-dir=$(_ConfigurationOutputBaseDirectory)" />
118119

119120
</Target>
121+
122+
<!-- Generates 'JNIEnv.g.cs' file. We do this here because it should only run once, not per-TF. -->
123+
<Target Name="_BuildJNIEnv"
124+
BeforeTargets="Build"
125+
Inputs="..\..\bin\Build$(Configuration)\jnienv-gen.exe"
126+
Outputs="../../src/Mono.Android/Android.Runtime/JNIEnv.g.cs">
127+
<Exec
128+
Command="$(ManagedRuntime) $(ManagedRuntimeArgs) &quot;../../bin/Build$(Configuration)/jnienv-gen.exe&quot; -o ../../src/Mono.Android/Android.Runtime/JNIEnv.g.cs --use-java-interop"
129+
/>
130+
<Touch Files="../../src/Mono.Android/Android.Runtime/JNIEnv.g.cs" />
131+
</Target>
120132

121133
<!-- Clean up generated API files -->
122134
<Target Name="_CleanApiXml"

build-tools/scripts/BuildEverything.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ endif
2727
leeroy: leeroy-all framework-assemblies
2828

2929
leeroy-all:
30-
$(call DOTNET_BINLOG,leeroy-all) $(SOLUTION) -m:1 $(_MSBUILD_ARGS)
30+
$(call DOTNET_BINLOG,leeroy-all) $(SOLUTION) $(_MSBUILD_ARGS)
3131
$(call DOTNET_BINLOG,setup-workload) -t:ConfigureLocalWorkload build-tools/create-packs/Microsoft.Android.Sdk.proj
3232
$(call MSBUILD_BINLOG,leeroy-all,$(_SLN_BUILD)) /restore tools/xabuild/xabuild.csproj /p:Configuration=$(CONFIGURATION) $(_MSBUILD_ARGS)

external/Java.Interop

src/Microsoft.Android.Sdk.ILLink/Microsoft.Android.Sdk.ILLink.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<PackageReference Include="Microsoft.NET.ILLink" Version="$(MicrosoftNETILLinkTasksPackageVersion)" />
1313
<PackageReference Include="XliffTasks" Version="$(XliffTasksVersion)" PrivateAssets="all" />
1414
<ProjectReference Include="..\..\external\Java.Interop\src\Java.Interop.Export\Java.Interop.Export.csproj" />
15+
<ProjectReference Include="..\Xamarin.Android.Build.Tasks\Xamarin.Android.Build.Tasks.csproj" ReferenceOutputAssembly="False" />
1516

1617
<Compile Include="..\Xamarin.Android.Build.Tasks\obj\$(Configuration)\Profile.g.cs" Link="Profile.g.cs" />
1718

src/Mono.Android/Mono.Android.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@
374374
<ItemGroup>
375375
<ProjectReference Include="..\..\build-tools\create-android-api\create-android-api.csproj" ReferenceOutputAssembly="false" />
376376
<!-- Explicitly pass the target framework of the project so we don't have conflicts with the multiple targets in this file. -->
377-
<ProjectReference Include="..\..\build-tools\jnienv-gen\jnienv-gen.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=net472" />
378377
<ProjectReference Include="..\..\external\Java.Interop\tools\generator\generator.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=net472"/>
379378
<ProjectReference Include="..\..\external\Java.Interop\tools\java-source-utils\java-source-utils.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=$(DotNetTargetFramework)" />
380379
<ProjectReference Include="..\..\external\Java.Interop\tools\jcw-gen\jcw-gen.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=net472" />

src/Mono.Android/Mono.Android.targets

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
<_GlobalProperties>
3131
JavaInteropProfile=Net45;
3232
XAInstallPrefix=$(XAInstallPrefix);
33-
TargetFrameworkIdentifier=MonoAndroid;
34-
TargetFrameworkVersion=v1.0;
35-
TargetFrameworkRootPath=$(XAInstallPrefix)xbuild-frameworks;
3633
</_GlobalProperties>
3734
</PropertyGroup>
35+
<MSBuild
36+
Projects="$(JavaInteropFullPath)\build-tools\jnienv-gen\jnienv-gen.csproj"
37+
Properties="TargetFramework=net472;"
38+
/>
3839
<MSBuild
3940
Projects="$(JavaInteropFullPath)\src\Java.Interop\Java.Interop-MonoAndroid.csproj"
4041
Properties="$(_GlobalProperties)"
@@ -120,17 +121,6 @@
120121
<Touch Files="$(_AndroidJavadocXml)" />
121122
</Target>
122123

123-
<!-- Generates 'JNIEnv.g.cs' file -->
124-
<Target Name="_BuildJNIEnv"
125-
BeforeTargets="CoreCompile"
126-
Inputs="..\..\bin\Build$(Configuration)\jnienv-gen.exe"
127-
Outputs="Android.Runtime\JNIEnv.g.cs">
128-
<Exec
129-
Command="$(ManagedRuntime) $(ManagedRuntimeArgs) &quot;../../bin/Build$(Configuration)/jnienv-gen.exe&quot; -o Android.Runtime/JNIEnv.g.cs --use-java-interop"
130-
/>
131-
<Touch Files="Android.Runtime\JNIEnv.g.cs" />
132-
</Target>
133-
134124
<!-- Copies common 'api-X.xml' to the 'obj' directory.
135125
This is needed because 'generator' writes intermediate files like 'api-X.xml.fixed' next to the source
136126
'api-X.xml' and multiple profiles are using the source, so these files will clobber each other. -->

src/manifestmerger/manifestmerger.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
</PropertyGroup>
88

99
<Import Project="..\..\Configuration.props" />
10+
11+
<ItemGroup>
12+
<!-- There isn't an actual dependency here, but we can only build one 'gradlew' project
13+
at a time, and adding <ProjectReference> between them ensures they run sequentially. -->
14+
<ProjectReference Include="..\apksigner\apksigner.csproj" ReferenceOutputAssembly="False" />
15+
</ItemGroup>
1016

1117
<Import Project="manifestmerger.targets" />
1218
</Project>

src/r8/r8.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
<OutputPath Condition="'$(OutputPath)'==''">bin\$(Configuration)</OutputPath>
99
</PropertyGroup>
1010

11+
<ItemGroup>
12+
<!-- There isn't an actual dependency here, but we can only build one 'gradlew' project
13+
at a time, and adding <ProjectReference> between them ensures they run sequentially. -->
14+
<ProjectReference Include="..\manifestmerger\manifestmerger.csproj" ReferenceOutputAssembly="False" />
15+
</ItemGroup>
16+
1117
<Import Project="..\..\Configuration.props" />
1218
<Import Project="r8.targets" />
1319
</Project>

0 commit comments

Comments
 (0)