Skip to content

Commit

Permalink
[ci] Build without -m:1. (#941)
Browse files Browse the repository at this point in the history
`dotnet build Java.Interop.sln` didn't work unless `-m:1` was used:

	% make prepare-core JI_MAX_JDK=8
	% dotnet build -target:Prepare -p:MaxJdkVersion=8 Java.Interop.sln
	% dotnet build Java.Interop.sln
	…
	…/tests/Java.Interop.Export-Tests/Java.Interop.Export-Tests.csproj(35,5): error MSB3073: The command ""/Users/jon/android-toolchain/jdk-1.8/bin/javac" -classpath …" exited with code 1.
	…/tests/Java.Interop.Export-Tests/Java.Interop.Export-Tests.csproj(35,5): error MSB3073: The command ""/Users/jon/android-toolchain/jdk-1.8/bin/javac" -classpath …" exited with code 1.
	…/tests/Java.Interop-Tests/Java.Interop-Tests.csproj(60,5): error MSB3073: The command ""/Users/jon/android-toolchain/jdk-1.8/bin/javac" -source 1.8 -target 1.8 -bootclasspath …" exited with code 1.
	…/tests/Java.Interop-Tests/Java.Interop-Tests.csproj(60,5): error MSB3073: The command ""/Users/jon/android-toolchain/jdk-1.8/bin/javac" -source 1.8 -target 1.8 -bootclasspath …" exited with code 1.

Using `dotnet build -m:1` avoids the above MSB3073 errors; see also
commit 1de5501, which added `-m:1` to CI builds.

Fix these parallel build issues so that `-m:1` isn't needed.  This is
principally done by removing `Java.Interop.BootstrapTasks.csproj`
from `Java.Interop.sln`, and adding it to a new
`Java.Interop.BootstrapTasks.sln` solution.  The `Prepare` target is
updated to explicitly Restore and Build the new
`Java.Interop.BootstrapTasks.dll` solution.

Note that the Restore and Build target invocations must be separate;
using [`Targets="Restore;Build"` will not work][0].

Update `Java.Interop.BootstrapTasks.csproj` to *no longer* `<Import/>`
`VersionInfo.targets`, as this causes a circular dependency
(`VersionInfo.targets` uses tasks from
`Java.Interop.BootstrapTasks.dll`).  This is fine, as
`Java.Interop.BootstrapTasks.dll` doesn't need to be versioned.

Review our custom `.targets` files, and replace
`BeforeTargets="BeforeBuild"` with `BeforeTargets="Build"` or
`BeforeTargets="BeforeCompile"` (as appropriate).
Building before the `BeforeBuild` target is problematic, as the
`BeforeBuild` target runs before `@(ProjectReference)`d projects are
built, meaning dependencies may not exist.  (Oops.)

TODO: Instead of having two `.sln` files, try to instead use
`<UsingTask/>` with `AssemblyFile` and `TasFactory` set, as done in
[rainersigwald/build-task-in-solution-demo][1] and the
[`InvokeCustomTaskDemo` target][2].  This *may* avoid the need for
a separate `.sln` (and `Prepare` target invocation?).

[0]: dotnet/msbuild#2811 (comment)
[1]: https://github.com/rainersigwald/build-task-in-solution-demo
[2]: https://github.com/rainersigwald/build-task-in-solution-demo/blob/17508937bb9edb0b817820146f85adf0da331515/Task/DemoFunctionality.targets#L4-L10
  • Loading branch information
jpobst authored Jan 24, 2022
1 parent 13def0e commit 88d6093
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
7 changes: 0 additions & 7 deletions Java.Interop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.JavaCall
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.GenericMarshaler", "src\Java.Interop.GenericMarshaler\Java.Interop.GenericMarshaler.csproj", "{D1243BAB-23CA-4566-A2A3-3ADA2C2DC3AF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.BootstrapTasks", "build-tools\Java.Interop.BootstrapTasks\Java.Interop.BootstrapTasks.csproj", "{3E8E5C8C-59A6-4A9A-B55D-46AB14431B2A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.AndroidSdk", "external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj", "{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.Tools.JavaSource-Tests", "tests\Java.Interop.Tools.JavaSource-Tests\Java.Interop.Tools.JavaSource-Tests.csproj", "{093B5E94-7FB7-499F-9C11-30944BAFEE25}"
Expand Down Expand Up @@ -242,10 +240,6 @@ Global
{D1243BAB-23CA-4566-A2A3-3ADA2C2DC3AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1243BAB-23CA-4566-A2A3-3ADA2C2DC3AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1243BAB-23CA-4566-A2A3-3ADA2C2DC3AF}.Release|Any CPU.Build.0 = Release|Any CPU
{3E8E5C8C-59A6-4A9A-B55D-46AB14431B2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E8E5C8C-59A6-4A9A-B55D-46AB14431B2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E8E5C8C-59A6-4A9A-B55D-46AB14431B2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E8E5C8C-59A6-4A9A-B55D-46AB14431B2A}.Release|Any CPU.Build.0 = Release|Any CPU
{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -338,7 +332,6 @@ Global
{52C7D9B6-E8C8-47D0-9471-652D278D7D77} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
{D1243BAB-23CA-4566-A2A3-3ADA2C2DC3AF} = {4C173212-371D-45D8-BA83-9226194F48DC}
{3E8E5C8C-59A6-4A9A-B55D-46AB14431B2A} = {172B608B-E6F3-41CC-9949-203A76BA247C}
{E34BCFA0-CAA4-412C-AA1C-75DB8D67D157} = {172B608B-E6F3-41CC-9949-203A76BA247C}
{093B5E94-7FB7-499F-9C11-30944BAFEE25} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
{0E3AF6C1-7638-464D-9174-485D494499DC} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
</ProjectReference>
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)..\scripts\VersionInfo.targets" />

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32104.313
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Java.Interop.BootstrapTasks", "Java.Interop.BootstrapTasks.csproj", "{47C54705-71BA-455D-9F72-780487DE861C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Xamarin.Android.Tools.AndroidSdk", "..\..\external\xamarin-android-tools\src\Xamarin.Android.Tools.AndroidSdk\Xamarin.Android.Tools.AndroidSdk.csproj", "{2F8744CF-C265-440A-B976-DEC021324A3E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{47C54705-71BA-455D-9F72-780487DE861C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47C54705-71BA-455D-9F72-780487DE861C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47C54705-71BA-455D-9F72-780487DE861C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47C54705-71BA-455D-9F72-780487DE861C}.Release|Any CPU.Build.0 = Release|Any CPU
{2F8744CF-C265-440A-B976-DEC021324A3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F8744CF-C265-440A-B976-DEC021324A3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F8744CF-C265-440A-B976-DEC021324A3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F8744CF-C265-440A-B976-DEC021324A3E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8C64DB4C-E064-43CA-B1AB-100760FEF870}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion build-tools/automation/templates/core-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ steps:
displayName: Build Solution
inputs:
projects: Java.Interop.sln
arguments: '-c $(Build.Configuration) -m:1'
arguments: '-c $(Build.Configuration)'
8 changes: 5 additions & 3 deletions build-tools/scripts/Prepare.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
<UsingTask AssemblyFile="$(_TopDir)\bin\Build$(Configuration)\Java.Interop.BootstrapTasks.dll" TaskName="Java.Interop.BootstrapTasks.JdkInfo" />
<Target Name="Prepare">
<Exec Command="git submodule update --init --recursive" WorkingDirectory="$(_TopDir)" />
<MSBuild Projects="$(MSBuildThisFileDirectory)..\..\build-tools\Java.Interop.BootstrapTasks\Java.Interop.BootstrapTasks.csproj"
Targets="Build;GenerateVersionInfo"
RunEachTargetSeparately="true"
<MSBuild Projects="$(MSBuildThisFileDirectory)..\..\build-tools\Java.Interop.BootstrapTasks\Java.Interop.BootstrapTasks.sln"
Targets="Restore"
/>
<MSBuild Projects="$(MSBuildThisFileDirectory)..\..\build-tools\Java.Interop.BootstrapTasks\Java.Interop.BootstrapTasks.sln"
Targets="Build"
/>
<PropertyGroup>
<_MaxJdk>$(MaxJdkVersion)</_MaxJdk>
Expand Down
2 changes: 1 addition & 1 deletion tests/Java.Interop-Tests/Java.Interop-Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<JavaInteropTestJar Include="$(MSBuildThisFileDirectory)java\com\xamarin\interop\TestType.java" />
</ItemGroup>

<Target Name="BuildInteropTestJar" BeforeTargets="BeforeBuild" Inputs="@(JavaInteropTestJar)" Outputs="$(OutputPath)interop-test.jar">
<Target Name="BuildInteropTestJar" BeforeTargets="Build" Inputs="@(JavaInteropTestJar)" Outputs="$(OutputPath)interop-test.jar">
<MakeDir Directories="$(IntermediateOutputPath)it-classes" />
<Exec Command="&quot;$(JavaCPath)&quot; $(_JavacSourceOptions) -d &quot;$(IntermediateOutputPath)it-classes&quot; -classpath &quot;$(OutputPath)../$(Configuration)/java-interop.jar&quot; @(JavaInteropTestJar->'%(Identity)', ' ')" />
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)interop-test.jar&quot; -C &quot;$(IntermediateOutputPath)it-classes&quot; ." />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<JavaExportTestJar Include="$(MSBuildThisFileDirectory)java\com\xamarin\interop\export\ExportType.java" />
</ItemGroup>

<Target Name="BuildExportTestJar" BeforeTargets="BeforeBuild" Inputs="@(JavaExportTestJar)" Outputs="$(OutputPath)export-test.jar">
<Target Name="BuildExportTestJar" BeforeTargets="Build" Inputs="@(JavaExportTestJar)" Outputs="$(OutputPath)export-test.jar">
<MakeDir Directories="$(IntermediateOutputPath)et-classes" />
<Exec Command="&quot;$(JavaCPath)&quot; -classpath &quot;$(OutputPath)../$(Configuration)/java-interop.jar&quot; $(_JavacSourceOptions) -d &quot;$(IntermediateOutputPath)et-classes&quot; @(JavaExportTestJar->'%(Identity)', ' ')" />
<Exec Command="&quot;$(JarPath)&quot; cf &quot;$(OutputPath)export-test.jar&quot; -C &quot;$(IntermediateOutputPath)et-classes&quot; ." />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<Target Name="BuildClasses"
BeforeTargets="BeforeBuild"
BeforeTargets="BeforeCompile"
Inputs="@(TestJar);@(TestJarNoParameters)"
Outputs="@(_BuildClassOutputs)">
<MakeDir Directories="$(IntermediateOutputPath)classes" />
Expand All @@ -28,7 +28,7 @@
-->
<Target Name="BuildKotlinClasses"
Condition=" '$(KotlinCPath)' != '' "
BeforeTargets="BeforeBuild"
BeforeTargets="Build"
Inputs="@(TestKotlinJar)"
Outputs="@(TestKotlinJar->'%(RecursiveDir)%(Filename).class')">
<Exec Command="&quot;$(KotlinCPath)&quot; @(TestKotlinJar->'%(Identity)', ' ') -d &quot;kotlin&quot;" />
Expand Down

0 comments on commit 88d6093

Please sign in to comment.