Skip to content

Conversation

@jonpryor
Copy link
Contributor

@jonpryor jonpryor commented Jul 7, 2022

Ever since commit 2197a45, CI builds for the main branch have been
incredibly flakey: 918613d through 27647d2 all failed to complete
the Mac stage -- which must pass in order for most unit tests
to run -- then dbadf13 built, then f149c25 failed.

9 commits in the past week have failed to adequately build.
(PR builds, meanwhile, were largely fine.)

Most of these failures are from make all-tests:

_ExtractJavadocsFromJavaSourceJars:
  /Users/runner/android-toolchain/jdk-11/bin/java -jar /Users/runner/work/1/s/xamarin-android/bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar @/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/tmp1cf0947e.tmp 
JAVASOURCEUTILS : warning : Invalid or corrupt jarfile /Users/runner/work/1/s/xamarin-android/bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/Xamarin.Android.McwGen-Tests.csproj]
…
BINDINGSGENERATOR : warning BG8600: Invalid XML file '/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/obj/Release/javadoc-xamarin-test-sources-F6F5170BF7A8BC71.xml': Could not find file "/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/obj/Release/javadoc-xamarin-test-sources-F6F5170BF7A8BC71.xml".  For details, see verbose output. [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/Xamarin.Android.McwGen-Tests.csproj]
  System.IO.FileNotFoundException: Could not find file "/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/obj/Release/javadoc-xamarin-test-sources-F6F5170BF7A8BC71.xml"
…
"/Users/runner/work/1/s/xamarin-android/Xamarin.Android-Tests.sln" (default target) (1:2) ->
"/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj" (default target) (12:6) ->
(CoreCompile target) -> 
  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(78,37): error CS1061: 'DataEventArgs' does not contain a definition for 'FromNode' and no accessible extension method 'FromNode' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(79,40): error CS1061: 'DataEventArgs' does not contain a definition for 'FromChannel' and no accessible extension method 'FromChannel' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(80,40): error CS1061: 'DataEventArgs' does not contain a definition for 'PayloadType' and no accessible extension method 'PayloadType' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(81,28): error CS1061: 'DataEventArgs' does not contain a definition for 'Payload' and no accessible extension method 'Payload' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(82,29): error CS1061: 'DataEventArgs' does not contain a definition for 'Payload' and no accessible extension method 'Payload' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(84,51): error CS1061: 'DataEventArgs' does not contain a definition for 'Payload' and no accessible extension method 'Payload' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(85,10): error CS1061: 'DataEventArgs' does not contain a definition for 'Payload' and no accessible extension method 'Payload' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]

java-source-utils.jar is (apparently) corrupt, so
javadoc-xamarin-test-sources-F6F5170BF7A8BC71.xml is never created,
which means no parameter name information is present, which means the
generated DataEventArgs type doesn't have the appropriate property
names, as the property names come from parameter names, and since we
don't have parameter names we instead have property names like P0,
P1, P2, etc.

Why, then, is java-source-utils.jar corrupt? The current guess is
that it is being built concurrently; from a
msbuild-20220706T175333-leeroy-all.binlog build log file from one
of the offending builds, we see:

17:53:44.526 59:11>Target "_BuildJava: (TargetId:490)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
17:53:44.526 59:11>Building target "_BuildJava" completely.
  Output file "/Users/runner/work/1/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/33.0.0/tools/java-source-utils.jar" does not exist.
…
17:54:19.564 59:12>Target "DispatchToInnerBuilds: (TargetId:1637)" in file "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/sdk/7.0.100-preview.7.22354.2/Microsoft.Common.CrossTargeting.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (target "Build" depends on it):
  Task "MSBuild" (TaskId:1099)
    Task Parameter:BuildInParallel=True (TaskId:1099)
    Task Parameter:Targets=Build (TaskId:1099)
    Task Parameter:
        Projects=
            java-source-utils.csproj
                    AdditionalProperties=TargetFramework=net7.0 (TaskId:1099)
    Additional Properties for project "java-source-utils.csproj": (TaskId:1099)
      TargetFramework=net7.0 (TaskId:1099)
…
17:54:19.592 59:12>Target "_BuildJava: (TargetId:1640)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
  Building target "_BuildJava" completely.
  Output file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/../../bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar" does not exist.
…
17:54:41.034 59:11>Done building target "_BuildJava" in project "java-source-utils.csproj".: (TargetId:490)

What appears to be happening -- and there is lots of conjecture here,
as the build log is enormous and it's difficult to piece everything
together -- is that java-source-utils.csproj is built twice:

Once via Xamarin.Android.sln, and once via apksigner.csproj, as
it appears that setting %(PackageReference.AdditionalProperties)
triggers a nested build; note the DispatchToInnerBuilds target
which invokes the <MSBuild/> Task with the specified
AdditionalProperties.

Thus, instead of the single java-source-utils.csproj build which
commit 2197a45 was attempting to introduce, we had two potentially
concurrent builds.

Attempt to fix this by removing the "offending"
%(ProjectReference.AdditionalProperties).

description TBD.  It'll be long.
@jonpryor jonpryor changed the title Try things [apksigner] Remove AdditionalProperties on java-source-utils.csproj Jul 7, 2022
@jonpryor
Copy link
Contributor Author

jonpryor commented Jul 7, 2022

Further investigation suggests that this isn't the fix I was hoping for. My hope was that with this change, java-source-utils.csproj would have it's _BuildJava target executed only once. Locally, it is still executed twice.

Compare to the _BuildGradle target in apksigner.targets, which is only executed once.

I'm still missing something; not sure what yet.

@jonpryor
Copy link
Contributor Author

jonpryor commented Jul 7, 2022

Through the glory is that is (1) the MSBuild Structured Log Viewer (which I really should use more often) and (2) the "target path window" at the bottom of the Windows MSBuild Structured Log Viewer app -- which quite nicely answers the question "how did I get here?" -- I now see why _BuildJava is running twice locally.

java-source-utils.csproj uses $(TargetFrameworks) (plural!), which means there can be (are!) "outer" builds and "inner" builds.

Thus, the two _BuildJava target invocations? One is from the "outer" build, and one is from the "inner" build, wherein the DispatchToInnerBuilds target is in the target path window.

jonpryor added a commit to jonpryor/java.interop that referenced this pull request Jul 7, 2022
Context: dotnet/android#7157

Ever since commit 69e1b80, `java-source-utils.csproj` used the
`$(TargetFrameworks)` plural form, even though it only specified a
single framework.  I don't remember underlying reason for this, other
than "that's what I needed for it to build," which might have been
because the `_BuildJava` target was "wrong".

This arrangement was "fine", until dotnet/android@2197a459,
after which the xamarin-android/main CI builds started behaving
"weird": frequently `make all-tests` would fail, because
`make jenkins` would produce an invalid or corrupt
`java-source-utils.jar`, *apparently* because it was attempting to
*concurrently build* `java-source-utils.csproj` (?!).

One of these concurrent builds *appeared* to be an "outer build" from
`Xamarin.Android.sln`, while another one appeared to be an "inner
build" via `apksigner.csproj` and
`%(ProjectReference.AdditionalProperties)`:

	17:53:44.526 59:11>Target "_BuildJava: (TargetId:490)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	17:53:44.526 59:11>Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/33.0.0/tools/java-source-utils.jar" does not exist.
	…
	17:54:19.564 59:12>Target "DispatchToInnerBuilds: (TargetId:1637)" in file "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/sdk/7.0.100-preview.7.22354.2/Microsoft.Common.CrossTargeting.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (target "Build" depends on it):
	  Task "MSBuild" (TaskId:1099)
	    Task Parameter:BuildInParallel=True (TaskId:1099)
	    Task Parameter:Targets=Build (TaskId:1099)
	    Task Parameter:
	        Projects=
	            java-source-utils.csproj
	                    AdditionalProperties=TargetFramework=net7.0 (TaskId:1099)
	    Additional Properties for project "java-source-utils.csproj": (TaskId:1099)
	      TargetFramework=net7.0 (TaskId:1099)
	…
	17:54:19.592 59:12>Target "_BuildJava: (TargetId:1640)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	  Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/../../bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar" does not exist.
	…
	17:54:41.034 59:11>Done building target "_BuildJava" in project "java-source-utils.csproj".: (TargetId:490)

We attempted to fix this by removing
`%(ProjectReference.AdditionalProperties)`, which only slightly
changed things: the "outer build via `Xamarin.Android.sln`" build was
removed, but we instead saw a scenario in which
`java-source-utils.csproj` was built "once", and as part of that
build the "outer" and "inner" builds were run concurrently.

A commonality here is `$(TargetFrameworks)` requires "outer" and
"inner" builds, and that is a complication that we should remove.

Update `java-source-utils.csproj` so that `$(TargetFramework)` is
used, not `$(TargetFrameworks)`.

Update the `_BuildJava` target so that it runs before the
`GetCopyToOutputDirectoryItems` target.  This is consistent with how
the [`_BuildGradle` target in `apksigner.csproj`][0] works.  Without
this change -- and the removal of the empty `Build` target -- the
`java-source-utils.csproj` build didn't behave correctly (`gradlew`
wasn't run).

Hopefully once only a single `$(TargetFramework)` is built, we will
be able to restore build system sanity to xamarin-android.

[0]: https://github.com/xamarin/xamarin-android/blob/c537dd28c30f482f365ef756214be35aa1553da2/src/apksigner/apksigner.targets#L3-L13
jonpryor added a commit to jonpryor/java.interop that referenced this pull request Jul 7, 2022
Context: dotnet/android#7157

Ever since commit 69e1b80, `java-source-utils.csproj` used the
`$(TargetFrameworks)` plural form, even though it only specified a
single framework.  I don't remember underlying reason for this, other
than "that's what I needed for it to build," which might have been
because the `_BuildJava` target was "wrong".

This arrangement was "fine", until dotnet/android@2197a459,
after which the xamarin-android/main CI builds started behaving
"weird": frequently `make all-tests` would fail, because
`make jenkins` would produce an invalid or corrupt
`java-source-utils.jar`, *apparently* because it was attempting to
*concurrently build* `java-source-utils.csproj` (?!).

One of these concurrent builds *appeared* to be an "outer build" from
`Xamarin.Android.sln`, while another one appeared to be an "inner
build" via `apksigner.csproj` and
`%(ProjectReference.AdditionalProperties)`:

	17:53:44.526 59:11>Target "_BuildJava: (TargetId:490)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	17:53:44.526 59:11>Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/33.0.0/tools/java-source-utils.jar" does not exist.
	…
	17:54:19.564 59:12>Target "DispatchToInnerBuilds: (TargetId:1637)" in file "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/sdk/7.0.100-preview.7.22354.2/Microsoft.Common.CrossTargeting.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (target "Build" depends on it):
	  Task "MSBuild" (TaskId:1099)
	    Task Parameter:BuildInParallel=True (TaskId:1099)
	    Task Parameter:Targets=Build (TaskId:1099)
	    Task Parameter:
	        Projects=
	            java-source-utils.csproj
	                    AdditionalProperties=TargetFramework=net7.0 (TaskId:1099)
	    Additional Properties for project "java-source-utils.csproj": (TaskId:1099)
	      TargetFramework=net7.0 (TaskId:1099)
	…
	17:54:19.592 59:12>Target "_BuildJava: (TargetId:1640)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	  Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/../../bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar" does not exist.
	…
	17:54:41.034 59:11>Done building target "_BuildJava" in project "java-source-utils.csproj".: (TargetId:490)

We attempted to fix this by removing
`%(ProjectReference.AdditionalProperties)`, which only slightly
changed things: the "outer build via `Xamarin.Android.sln`" build was
removed, but we instead saw a scenario in which
`java-source-utils.csproj` was built "once", and as part of that
build the "outer" and "inner" builds were run concurrently.

A commonality here is `$(TargetFrameworks)` requires "outer" and
"inner" builds, and that is a complication that we should remove.

Update `java-source-utils.csproj` so that `$(TargetFramework)` is
used, not `$(TargetFrameworks)`.

Update the `_BuildJava` target so that it runs before the
`GetCopyToOutputDirectoryItems` target.  This is consistent with how
the [`_BuildGradle` target in `apksigner.csproj`][0] works.  Without
this change -- and the removal of the empty `Build` target -- the
`java-source-utils.csproj` build didn't behave correctly (`gradlew`
wasn't run).

Unfortunately, this seemingly simple change hits a little "snag":
`Directory.Build.props` is imported [very early][1]:

> *Directory.Build.props* is imported very early in
> *Microsoft.Common.props*, and properties defined later are
> unavailable to it.

"Properties defined later are unavailable to it." Properties such as
`$(TargetFramework)`.  Which means that every property we have in
`Directory.Build.props` which "depend" on `$(TargetFramework)`
*are not **actually** usable*.  They've only *appeared* to work
because they would default to "classic" paths, but as soon as you try
to build with `$(TargetFramework)`=net7.0 -- as was attempted with
`java-source-utils.csproj`, and previously with `Java.Base.csproj`
(bc5bcf4) -- you'll find that the "wrong" directories are used for
`$(OutputPath)`.

This has been a long-standing deficiency in my MSBuild understanding.

Fix this by adding a new `TargetFrameworkDependentValues.props` file,
and `<Import/>`ing this file in *every* `.csproj` which sets MSBuild
properties with values dependent upon `$(TargetFramework)` *before*
those properties are set.

Old and busted:

	<PropertyGroup>
	  <TargetFramework>net7.0</TargetFramework>
	  <OutputPath>$(UtilityOutputFullPath)</OutputPath>
	</PropertyGroup>

New hawtness:

	<PropertyGroup>
	  <TargetFramework>net7.0</TargetFramework>
	</PropertyGroup>
	<Import Project="..\..\TargetFrameworkDependentValues.props" />
	<PropertyGroup>
	  <OutputPath>$(UtilityOutputFullPath)</OutputPath>
	</PropertyGroup>

[0]: https://github.com/xamarin/xamarin-android/blob/c537dd28c30f482f365ef756214be35aa1553da2/src/apksigner/apksigner.targets#L3-L13
[1]: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2022#import-order
jonpryor added a commit to jonpryor/java.interop that referenced this pull request Jul 7, 2022
Context: dotnet/android#7157

Ever since commit 69e1b80, `java-source-utils.csproj` used the
`$(TargetFrameworks)` plural form, even though it only specified a
single framework.  I don't remember underlying reason for this, other
than "that's what I needed for it to build," which might have been
because the `_BuildJava` target was "wrong".

This arrangement was "fine", until dotnet/android@2197a459,
after which the xamarin-android/main CI builds started behaving
"weird": frequently `make all-tests` would fail, because
`make jenkins` would produce an invalid or corrupt
`java-source-utils.jar`, *apparently* because it was attempting to
*concurrently build* `java-source-utils.csproj` (?!).

One of these concurrent builds *appeared* to be an "outer build" from
`Xamarin.Android.sln`, while another one appeared to be an "inner
build" via `apksigner.csproj` and
`%(ProjectReference.AdditionalProperties)`:

	17:53:44.526 59:11>Target "_BuildJava: (TargetId:490)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	17:53:44.526 59:11>Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/33.0.0/tools/java-source-utils.jar" does not exist.
	…
	17:54:19.564 59:12>Target "DispatchToInnerBuilds: (TargetId:1637)" in file "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/sdk/7.0.100-preview.7.22354.2/Microsoft.Common.CrossTargeting.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (target "Build" depends on it):
	  Task "MSBuild" (TaskId:1099)
	    Task Parameter:BuildInParallel=True (TaskId:1099)
	    Task Parameter:Targets=Build (TaskId:1099)
	    Task Parameter:
	        Projects=
	            java-source-utils.csproj
	                    AdditionalProperties=TargetFramework=net7.0 (TaskId:1099)
	    Additional Properties for project "java-source-utils.csproj": (TaskId:1099)
	      TargetFramework=net7.0 (TaskId:1099)
	…
	17:54:19.592 59:12>Target "_BuildJava: (TargetId:1640)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	  Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/../../bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar" does not exist.
	…
	17:54:41.034 59:11>Done building target "_BuildJava" in project "java-source-utils.csproj".: (TargetId:490)

We attempted to fix this by removing
`%(ProjectReference.AdditionalProperties)`, which only slightly
changed things: the "outer build via `Xamarin.Android.sln`" build was
removed, but we instead saw a scenario in which
`java-source-utils.csproj` was built "once", and as part of that
build the "outer" and "inner" builds were run concurrently.

A commonality here is `$(TargetFrameworks)` requires "outer" and
"inner" builds, and that is a complication that we should remove.

Update `java-source-utils.csproj` so that `$(TargetFramework)` is
used, not `$(TargetFrameworks)`.

Update the `_BuildJava` target so that it runs before the
`GetCopyToOutputDirectoryItems` target.  This is consistent with how
the [`_BuildGradle` target in `apksigner.csproj`][0] works.  Without
this change -- and the removal of the empty `Build` target -- the
`java-source-utils.csproj` build didn't behave correctly (`gradlew`
wasn't run).

Unfortunately, this seemingly simple change hits a little "snag":
`Directory.Build.props` is imported [very early][1]:

> *Directory.Build.props* is imported very early in
> *Microsoft.Common.props*, and properties defined later are
> unavailable to it.

"Properties defined later are unavailable to it." Properties such as
`$(TargetFramework)`.  Which means that every property we have in
`Directory.Build.props` which "depend" on `$(TargetFramework)`
*are not **actually** usable*.  They've only *appeared* to work
because they would default to "classic" paths, but as soon as you try
to build with `$(TargetFramework)`=net7.0 -- as was attempted with
`java-source-utils.csproj`, and previously with `Java.Base.csproj`
(bc5bcf4) -- you'll find that the "wrong" directories are used for
`$(OutputPath)`.

This has been a long-standing deficiency in my MSBuild understanding.

Fix this by adding a new `TargetFrameworkDependentValues.props` file,
and `<Import/>`ing this file in *every* `.csproj` which sets MSBuild
properties with values dependent upon `$(TargetFramework)` *before*
those properties are set.

Old and busted:

	<PropertyGroup>
	  <TargetFramework>net7.0</TargetFramework>
	  <OutputPath>$(UtilityOutputFullPath)</OutputPath>
	</PropertyGroup>

New hawtness:

	<PropertyGroup>
	  <TargetFramework>net7.0</TargetFramework>
	</PropertyGroup>
	<Import Project="..\..\TargetFrameworkDependentValues.props" />
	<PropertyGroup>
	  <OutputPath>$(UtilityOutputFullPath)</OutputPath>
	</PropertyGroup>

[0]: https://github.com/xamarin/xamarin-android/blob/c537dd28c30f482f365ef756214be35aa1553da2/src/apksigner/apksigner.targets#L3-L13
[1]: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2022#import-order
jonpryor added a commit to jonpryor/java.interop that referenced this pull request Jul 7, 2022
Context: dotnet/android#7157

Ever since commit 69e1b80, `java-source-utils.csproj` used the
`$(TargetFrameworks)` plural form, even though it only specified a
single framework.  I don't remember underlying reason for this, other
than "that's what I needed for it to build," which might have been
because the `_BuildJava` target was "wrong".

This arrangement was "fine", until dotnet/android@2197a459,
after which the xamarin-android/main CI builds started behaving
"weird": frequently `make all-tests` would fail, because
`make jenkins` would produce an invalid or corrupt
`java-source-utils.jar`, *apparently* because it was attempting to
*concurrently build* `java-source-utils.csproj` (?!).

One of these concurrent builds *appeared* to be an "outer build" from
`Xamarin.Android.sln`, while another one appeared to be an "inner
build" via `apksigner.csproj` and
`%(ProjectReference.AdditionalProperties)`:

	17:53:44.526 59:11>Target "_BuildJava: (TargetId:490)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	17:53:44.526 59:11>Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/33.0.0/tools/java-source-utils.jar" does not exist.
	…
	17:54:19.564 59:12>Target "DispatchToInnerBuilds: (TargetId:1637)" in file "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/sdk/7.0.100-preview.7.22354.2/Microsoft.Common.CrossTargeting.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (target "Build" depends on it):
	  Task "MSBuild" (TaskId:1099)
	    Task Parameter:BuildInParallel=True (TaskId:1099)
	    Task Parameter:Targets=Build (TaskId:1099)
	    Task Parameter:
	        Projects=
	            java-source-utils.csproj
	                    AdditionalProperties=TargetFramework=net7.0 (TaskId:1099)
	    Additional Properties for project "java-source-utils.csproj": (TaskId:1099)
	      TargetFramework=net7.0 (TaskId:1099)
	…
	17:54:19.592 59:12>Target "_BuildJava: (TargetId:1640)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	  Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/../../bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar" does not exist.
	…
	17:54:41.034 59:11>Done building target "_BuildJava" in project "java-source-utils.csproj".: (TargetId:490)

We attempted to fix this by removing
`%(ProjectReference.AdditionalProperties)`, which only slightly
changed things: the "outer build via `Xamarin.Android.sln`" build was
removed, but we instead saw a scenario in which
`java-source-utils.csproj` was built "once", and as part of that
build the "outer" and "inner" builds were run concurrently.

A commonality here is `$(TargetFrameworks)` requires "outer" and
"inner" builds, and that is a complication that we should remove.

Update `java-source-utils.csproj` so that `$(TargetFramework)` is
used, not `$(TargetFrameworks)`.

Update the `_BuildJava` target so that it runs before the
`GetCopyToOutputDirectoryItems` target.  This is consistent with how
the [`_BuildGradle` target in `apksigner.csproj`][0] works.  Without
this change -- and the removal of the empty `Build` target -- the
`java-source-utils.csproj` build didn't behave correctly (`gradlew`
wasn't run).

Unfortunately, this seemingly simple change hits a little "snag":
`Directory.Build.props` is imported [very early][1]:

> *Directory.Build.props* is imported very early in
> *Microsoft.Common.props*, and properties defined later are
> unavailable to it.

"Properties defined later are unavailable to it." Properties such as
`$(TargetFramework)`.  Which means that every property we have in
`Directory.Build.props` which "depend" on `$(TargetFramework)`
*are not **actually** usable*.  They've only *appeared* to work
because they would default to "classic" paths, but as soon as you try
to build with `$(TargetFramework)`=net7.0 -- as was attempted with
`java-source-utils.csproj`, and previously with `Java.Base.csproj`
(bc5bcf4) -- you'll find that the "wrong" directories are used for
`$(OutputPath)`.

This has been a long-standing deficiency in my MSBuild understanding.

Fix this by adding a new `TargetFrameworkDependentValues.props` file,
and `<Import/>`ing this file in *every* `.csproj` which sets MSBuild
properties with values dependent upon `$(TargetFramework)` *before*
those properties are set.

Old and busted:

	<PropertyGroup>
	  <TargetFramework>net7.0</TargetFramework>
	  <OutputPath>$(UtilityOutputFullPath)</OutputPath>
	</PropertyGroup>

New hawtness:

	<PropertyGroup>
	  <TargetFramework>net7.0</TargetFramework>
	</PropertyGroup>
	<Import Project="..\..\TargetFrameworkDependentValues.props" />
	<PropertyGroup>
	  <OutputPath>$(UtilityOutputFullPath)</OutputPath>
	</PropertyGroup>

[0]: https://github.com/xamarin/xamarin-android/blob/c537dd28c30f482f365ef756214be35aa1553da2/src/apksigner/apksigner.targets#L3-L13
[1]: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2022#import-order
@jonpryor jonpryor force-pushed the jonp-fix-jsu-build branch from c32dba4 to 52eacd0 Compare July 7, 2022 23:29
@jonpryor
Copy link
Contributor Author

jonpryor commented Jul 7, 2022

PR dotnet/java-interop#1007 changes java-source-utils.csproj to use the singular $(TargetFramework) form, thus removing the need for "outer" and "inner" builds. Locally, _BuildJava is now built only once, not twice, so this looks like a good fix, assuming everything works…

<!-- There isn't an actual dependency here, but we can only build one 'gradlew' project
at a time, and adding <ProjectReference> between them ensures they run sequentially. -->
<ProjectReference Include="..\..\external\Java.Interop\tools\java-source-utils\java-source-utils.csproj" ReferenceOutputAssembly="False" SkipGetTargetFrameworkProperties="True" AdditionalProperties="TargetFramework=$(DotNetTargetFramework)" />
<ProjectReference Include="..\..\external\Java.Interop\tools\java-source-utils\java-source-utils.csproj" ReferenceOutputAssembly="False" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jpobst wrote:

i'm not sure about removing SkipGetTargetFrameworkProperties="True", i think that is to ignore the fact that apksigner is ns2.0, and it's trying to reference a net7.0 java-source-utils project
might need to make java-source-utils be ns2.0

Looks like it built! ¯\(ツ)

.gitmodules Outdated
path = external/Java.Interop
url = https://github.com/xamarin/java.interop.git
branch = main
url = https://github.com/jonpryor/java.interop.git
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes clearly need to be reverted before we can merge, and dotnet/java-interop#1007 needs to be merged, but otherwise

jonpryor added a commit to dotnet/java-interop that referenced this pull request Jul 8, 2022
Context: dotnet/android#7157

Ever since commit 69e1b80, `java-source-utils.csproj` used the
`$(TargetFrameworks)` plural form, even though it only specified a
single framework.  I don't remember underlying reason for this, other
than "that's what I needed for it to build," which might have been
because the `_BuildJava` target was "wrong".

This arrangement was "fine", until dotnet/android@2197a459,
after which the xamarin-android/main CI builds started behaving
"weird": frequently `make all-tests` would fail, because
`make jenkins` would produce an invalid or corrupt
`java-source-utils.jar`, *apparently* because it was attempting to
*concurrently build* `java-source-utils.csproj` (?!).

One of these concurrent builds *appeared* to be an "outer build" from
`Xamarin.Android.sln`, while another one appeared to be an "inner
build" via `apksigner.csproj` and
`%(ProjectReference.AdditionalProperties)`:

	17:53:44.526 59:11>Target "_BuildJava: (TargetId:490)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	17:53:44.526 59:11>Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/33.0.0/tools/java-source-utils.jar" does not exist.
	…
	17:54:19.564 59:12>Target "DispatchToInnerBuilds: (TargetId:1637)" in file "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/sdk/7.0.100-preview.7.22354.2/Microsoft.Common.CrossTargeting.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (target "Build" depends on it):
	  Task "MSBuild" (TaskId:1099)
	    Task Parameter:BuildInParallel=True (TaskId:1099)
	    Task Parameter:Targets=Build (TaskId:1099)
	    Task Parameter:
	        Projects=
	            java-source-utils.csproj
	                    AdditionalProperties=TargetFramework=net7.0 (TaskId:1099)
	    Additional Properties for project "java-source-utils.csproj": (TaskId:1099)
	      TargetFramework=net7.0 (TaskId:1099)
	…
	17:54:19.592 59:12>Target "_BuildJava: (TargetId:1640)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	  Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/../../bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar" does not exist.
	…
	17:54:41.034 59:11>Done building target "_BuildJava" in project "java-source-utils.csproj".: (TargetId:490)

We attempted to fix this by removing
`%(ProjectReference.AdditionalProperties)`, which only slightly
changed things: the "outer build via `Xamarin.Android.sln`" build was
removed, but we instead saw a scenario in which
`java-source-utils.csproj` was built "once", and as part of that
build the "outer" and "inner" builds were run concurrently.

A commonality here is `$(TargetFrameworks)` requires "outer" and
"inner" builds, and that is a complication that we should remove.

Update `java-source-utils.csproj` so that singular
`$(TargetFramework)` is used, not plural `$(TargetFrameworks)`.

Update the `_BuildJava` target so that it runs before the
`GetCopyToOutputDirectoryItems` target.  This is consistent with how
the [`_BuildGradle` target in `apksigner.csproj`][0] works.  Without
this change -- and the removal of the empty `Build` target -- the
`java-source-utils.csproj` build didn't behave correctly
(`gradlew` wasn't run).

Unfortunately, this seemingly simple change hits a little "snag":
`Directory.Build.props` is imported [very early][1]:

> *Directory.Build.props* is imported very early in
> *Microsoft.Common.props*, and properties defined later are
> unavailable to it.

"Properties defined later are unavailable to it." Properties such as
`$(TargetFramework)`.  Which means that every property we have in
`Directory.Build.props` which "depends" on `$(TargetFramework)`
*are not **actually** usable*.  They've only *appeared* to work
because they would default to "classic" paths, but as soon as you try
to build with `$(TargetFramework)`=net7.0 -- as was attempted with
`java-source-utils.csproj`, and previously with `Java.Base.csproj`
(bc5bcf4) -- you'll find that the "wrong" directories are used for
`$(OutputPath)`.

This has been a long-standing deficiency in my MSBuild understanding.

Fix this by adding a new `TargetFrameworkDependentValues.props` file,
and `<Import/>`ing this file in *every* `.csproj` which uses MSBuild
properties with values dependent upon `$(TargetFramework)` *before*
those properties are set.

Old and busted:

	<PropertyGroup>
	  <TargetFramework>net7.0</TargetFramework>
	  <OutputPath>$(UtilityOutputFullPath)</OutputPath>
	</PropertyGroup>

New hawtness:

	<PropertyGroup>
	  <TargetFramework>net7.0</TargetFramework>
	</PropertyGroup>
	<Import Project="..\..\TargetFrameworkDependentValues.props" />
	<PropertyGroup>
	  <OutputPath>$(UtilityOutputFullPath)</OutputPath>
	</PropertyGroup>

[0]: https://github.com/xamarin/xamarin-android/blob/c537dd28c30f482f365ef756214be35aa1553da2/src/apksigner/apksigner.targets#L3-L13
[1]: https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build?view=vs-2022#import-order
@jonpryor
Copy link
Contributor Author

jonpryor commented Jul 8, 2022

Commit message:

Bump to xamarin/java.interop/main@c942ab68 (#7157)

Fixes: https://github.com/xamarin/java.interop/issues/335
Fixes: https://github.com/xamarin/java.interop/issues/954
Fixes: https://github.com/xamarin/java.interop/issues/976
Fixes: https://github.com/xamarin/java.interop/issues/981
Fixes: https://github.com/xamarin/java.interop/issues/992

Changes: https://github.com/xamarin/java.interop/compare/7716ae53da79068e079b17dd4961d0c821bb2c34...c942ab683c12e88e0527ed584a13b411e005ea57

  * xamarin/java.interop@c942ab68: [java-source-utils] Build one `$(TargetFramework)` (#1007)
  * xamarin/java.interop@b7caa788: [Byecode] Hide `internal` Kotlin fields marked with `@JvmField` (#1004)
  * xamarin/java.interop@22d5687b: [generator] Add `@managedOverride` values `none` and `reabstract`. (#1000)
  * xamarin/java.interop@7f1d2d7a: [generator] Fix <remove-attr/> metadata (#999)
  * xamarin/java.interop@265ad762: [Java.Interop.Tools.JavaSource] Fix tag parsing errors (#997)
  * xamarin/java.interop@99c68a86: [Java.Interop] JniTypeSignature & CultureInfo, empty strings (#1002)
  * xamarin/java.interop@920ea648: [Java.Interop] optimize JniTypeManager.AssertSimpleReference() (#1001)
  * xamarin/java.interop@4b4fedd3: [generator] Process Javadoc for nested types (#996)

Ever since commit 2197a459, CI builds for the `main` branch have been
incredibly flakey: 918613d0 through 27647d2a all failed to complete
the **Mac** stage -- which *must* pass in order for most unit tests
to run -- then dbadf130 built, then f149c25c failed.

Nine commits in the past week have failed to adequately build.
(PR builds, meanwhile, were largely fine.)

Most of these failures are from `make all-tests`:

	_ExtractJavadocsFromJavaSourceJars:
	  /Users/runner/android-toolchain/jdk-11/bin/java -jar /Users/runner/work/1/s/xamarin-android/bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar @/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/tmp1cf0947e.tmp 
	JAVASOURCEUTILS : warning : Invalid or corrupt jarfile /Users/runner/work/1/s/xamarin-android/bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/Xamarin.Android.McwGen-Tests.csproj]
	
	BINDINGSGENERATOR : warning BG8600: Invalid XML file '/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/obj/Release/javadoc-xamarin-test-sources-F6F5170BF7A8BC71.xml': Could not find file "/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/obj/Release/javadoc-xamarin-test-sources-F6F5170BF7A8BC71.xml".  For details, see verbose output. [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/Xamarin.Android.McwGen-Tests.csproj]
	  System.IO.FileNotFoundException: Could not find file "/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.McwGen-Tests/obj/Release/javadoc-xamarin-test-sources-F6F5170BF7A8BC71.xml"
	
	"/Users/runner/work/1/s/xamarin-android/Xamarin.Android-Tests.sln" (default target) (1:2) ->
	"/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj" (default target) (12:6) ->
	(CoreCompile target) -> 
	  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(78,37): error CS1061: 'DataEventArgs' does not contain a definition for 'FromNode' and no accessible extension method 'FromNode' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
	  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(79,40): error CS1061: 'DataEventArgs' does not contain a definition for 'FromChannel' and no accessible extension method 'FromChannel' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
	  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(80,40): error CS1061: 'DataEventArgs' does not contain a definition for 'PayloadType' and no accessible extension method 'PayloadType' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
	  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(81,28): error CS1061: 'DataEventArgs' does not contain a definition for 'Payload' and no accessible extension method 'Payload' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
	  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(82,29): error CS1061: 'DataEventArgs' does not contain a definition for 'Payload' and no accessible extension method 'Payload' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
	  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(84,51): error CS1061: 'DataEventArgs' does not contain a definition for 'Payload' and no accessible extension method 'Payload' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]
	  /Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/BindingTests.cs(85,10): error CS1061: 'DataEventArgs' does not contain a definition for 'Payload' and no accessible extension method 'Payload' accepting a first argument of type 'DataEventArgs' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/1/s/xamarin-android/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj]

`java-source-utils.jar` is (apparently) corrupt, so
`javadoc-xamarin-test-sources-F6F5170BF7A8BC71.xml` is never created,
which means no parameter name information is present, which means the
generated `DataEventArgs` type doesn't have the appropriate property
names, as the property names come from parameter names, and since we
don't have parameter names we instead have property names like `P0`,
`P1`, `P2`, etc.

Why, then, is `java-source-utils.jar` corrupt?  The current guess is
that it is being built *concurrently*; from a
`msbuild-20220706T175333-leeroy-all.binlog` build log file from one
of the offending builds, we see:

	17:53:44.526 59:11>Target "_BuildJava: (TargetId:490)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	17:53:44.526 59:11>Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/33.0.0/tools/java-source-utils.jar" does not exist.
	
	17:54:19.564 59:12>Target "DispatchToInnerBuilds: (TargetId:1637)" in file "/Users/runner/work/1/s/xamarin-android/bin/Release/dotnet/sdk/7.0.100-preview.7.22354.2/Microsoft.Common.CrossTargeting.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (target "Build" depends on it):
	  Task "MSBuild" (TaskId:1099)
	    Task Parameter:BuildInParallel=True (TaskId:1099)
	    Task Parameter:Targets=Build (TaskId:1099)
	    Task Parameter:
	        Projects=
	            java-source-utils.csproj
	                    AdditionalProperties=TargetFramework=net7.0 (TaskId:1099)
	    Additional Properties for project "java-source-utils.csproj": (TaskId:1099)
	      TargetFramework=net7.0 (TaskId:1099)
	
	17:54:19.592 59:12>Target "_BuildJava: (TargetId:1640)" in file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.targets" from project "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/tools/java-source-utils/java-source-utils.csproj" (entry point):
	  Building target "_BuildJava" completely.
	  Output file "/Users/runner/work/1/s/xamarin-android/external/Java.Interop/../../bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/java-source-utils.jar" does not exist.
	
	17:54:41.034 59:11>Done building target "_BuildJava" in project "java-source-utils.csproj".: (TargetId:490)
 
What appears to be happening -- and there is lots of conjecture here,
as the build log is enormous and it's difficult to piece everything
together -- is that `java-source-utils.csproj` is built *twice*:
Once via `Xamarin.Android.sln`, and once via `apksigner.csproj`, as
it appears that setting `%(PackageReference.AdditionalProperties)`
triggers a *nested build*; note the `DispatchToInnerBuilds` target
which invokes the `<MSBuild/>` Task with the specified
`AdditionalProperties`.

However, that's not the only potential source of concurrent builds;
`java-source-utils.csproj` used `$(TargetFrameworks)` (plural), which
can *also* result in concurrent builds between the "outer" and "inner"
builds used as part of `$(TargetFrameworks)`.

Fix this problem by bumping to xamarin/java.interop@c942ab68, which
updates `java-source-utils.csproj` to use the singular
`$(TargetFramework)` property -- avoiding "outer" and "inner" build
problems -- and "for good measure" update `apksigner.csproj` to
remove `%(ProjectReference.AdditionalProperties)` on
`java-source-utils.csproj`.  This should ensure that
`java-source-utils.csproj` is only built *once*, which in turn should
ensure that `java-source-utils.jar` isn't corrupted, and our CI
builds become more reliable.

@jonpryor jonpryor merged commit 59352f8 into dotnet:main Jul 8, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants