Skip to content

Commit 2197a45

Browse files
authored
[apksigner] Serialize gradlew: depend on java-source-utils (#7134)
Context: 944f88a Commit 944f88a enabled parallel builds by removing `dotnet build -m:1` usage, which allows for faster incremental builds. One of the problems encountered was around `gradlew` usage: `gradlew` doesn't support multiple concurrent executions, and will *block* waiting for other `gradlew` builds to complete, which can result in timeouts and failed builds. Commit 944f88a fixed this by "serializing" all projects which involve `gradlew`: * `r8.csproj` is the "entrypoint" * `r8.csproj` references `manifestmerger.csproj` * `manifestmerger.csproj` references `apksigner.csproj` This arrangement would cause `dotnet build` to sequentially build `r8.csproj`, `manifestmerger.csproj`, and `apksigner.csproj`, ensuring that only one `gradlew` command was run at a time. Unfortunately, we overlooked `external/Java.Interop/tools/java-source-utils/java-source-utils.csproj`. Thus, we occasionally see the Windows build fail: Timeout waiting to connect to the Gradle daemon. … …/java-source-utils.targets(10,5): error MSB3073: The command ""C:\a\_work\1\s\external\Java.Interop\build-tools\gradle\gradlew" …" exited with code 1. Update `apksigner.csproj` to reference `java-source-utils.csproj`, extending the "sequential order" of `gradlew`-using projects. This should make the Windows build more reliable. Additionally, move the `<Target/>`s out of `apksigner.csproj` and into `apksigner.targets`. This is more consistent with other projects, and reduces the likelihood of VSMac rewriting (and removing the formatting of) `apksigner.csproj`.
1 parent e161187 commit 2197a45

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

src/Mono.Android/Mono.Android.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@
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. -->
377377
<ProjectReference Include="..\..\external\Java.Interop\tools\generator\generator.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=net472"/>
378-
<ProjectReference Include="..\..\external\Java.Interop\tools\java-source-utils\java-source-utils.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=$(DotNetTargetFramework)" />
379378
<ProjectReference Include="..\..\external\Java.Interop\tools\jcw-gen\jcw-gen.csproj" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" AdditionalProperties="TargetFramework=net472" />
380379
<ProjectReference Include="..\..\src\java-runtime\java-runtime.csproj" ReferenceOutputAssembly="false" />
381380
<ProjectReference Include="..\r8\r8.csproj" ReferenceOutputAssembly="False" />

src/apksigner/apksigner.csproj

+6-18
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,11 @@
1616
<None Include="build\libs\apksigner.jar" CopyToOutputDirectory="PreserveNewest" Link="apksigner.jar" />
1717
</ItemGroup>
1818

19-
<Target Name="_BuildGradle"
20-
BeforeTargets="GetCopyToOutputDirectoryItems"
21-
Inputs="$(MSBuildThisFile);build.gradle"
22-
Outputs="build\libs\apksigner.jar">
23-
<Exec
24-
Command="&quot;$(GradleWPath)&quot; jar $(GradleArgs) -PjavaSourceVer=$(JavacSourceVersion) -PjavaTargetVer=$(JavacTargetVersion)"
25-
EnvironmentVariables="JAVA_HOME=$(Java8SdkDirectory);APP_HOME=$(GradleHome)"
26-
WorkingDirectory="$(MSBuildThisFileDirectory)"
27-
/>
28-
<Touch Files="build\libs\apksigner.jar" />
29-
</Target>
19+
<ItemGroup>
20+
<!-- There isn't an actual dependency here, but we can only build one 'gradlew' project
21+
at a time, and adding <ProjectReference> between them ensures they run sequentially. -->
22+
<ProjectReference Include="..\..\external\Java.Interop\tools\java-source-utils\java-source-utils.csproj" ReferenceOutputAssembly="False" SkipGetTargetFrameworkProperties="True" AdditionalProperties="TargetFramework=$(DotNetTargetFramework)" />
23+
</ItemGroup>
3024

31-
<Target Name="_CleanGradle" BeforeTargets="Clean">
32-
<Exec
33-
Command="&quot;$(GradleWPath)&quot; clean $(GradleArgs)"
34-
EnvironmentVariables="JAVA_HOME=$(Java8SdkDirectory);APP_HOME=$(GradleHome)"
35-
WorkingDirectory="$(MSBuildThisFileDirectory)"
36-
/>
37-
</Target>
25+
<Import Project="apksigner.targets" />
3826
</Project>

src/apksigner/apksigner.targets

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.Build.NoTargets">
2+
3+
<Target Name="_BuildGradle"
4+
BeforeTargets="GetCopyToOutputDirectoryItems"
5+
Inputs="$(MSBuildThisFile);build.gradle"
6+
Outputs="build\libs\apksigner.jar">
7+
<Exec
8+
Command="&quot;$(GradleWPath)&quot; jar $(GradleArgs) -PjavaSourceVer=$(JavacSourceVersion) -PjavaTargetVer=$(JavacTargetVersion)"
9+
EnvironmentVariables="JAVA_HOME=$(Java8SdkDirectory);APP_HOME=$(GradleHome)"
10+
WorkingDirectory="$(MSBuildThisFileDirectory)"
11+
/>
12+
<Touch Files="build\libs\apksigner.jar" />
13+
</Target>
14+
15+
<Target Name="_CleanGradle" BeforeTargets="Clean">
16+
<Exec
17+
Command="&quot;$(GradleWPath)&quot; clean $(GradleArgs)"
18+
EnvironmentVariables="JAVA_HOME=$(Java8SdkDirectory);APP_HOME=$(GradleHome)"
19+
WorkingDirectory="$(MSBuildThisFileDirectory)"
20+
/>
21+
</Target>
22+
23+
</Project>

0 commit comments

Comments
 (0)