Skip to content

Conversation

@jonpryor
Copy link
Contributor

Whenever external/mono is bumped, the
xamarin-android-msbuild job breaks:

Building target "_Make" completely.
...
Task "Touch" (TaskId:1642)
  Task Parameter:
    Files=
      …/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/x64/libzip.dll
        CMake=/Users/builder/android-toolchain/mxe-b9cbb53/bin/x86_64-w64-mingw32.static-cmake
        CMakeFlags=
        CopyToOutputDirectory=Always
        OutputLibrary=x64/libzip.dll
        OutputLibraryPath=lib/libzip.dll
      …/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/libzip.dll
        CMake=/Users/builder/android-toolchain/mxe-b9cbb53/bin/i686-w64-mingw32.static-cmake
        CMakeFlags=
        CopyToOutputDirectory=Always
        OutputLibrary=libzip.dll
        OutputLibraryPath=lib/libzip.dll (TaskId:1642)
  Touching "…/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/x64/libzip.dll". (TaskId:1642)
…/build-tools/libzip/libzip.targets(52,5): error MSB3375: The file "…/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/libzip.dll" does not exist. […/build-tools/libzip-windows/libzip-windows.csproj]
Done executing task "Touch" -- FAILED. (TaskId:1642)

This is due to an "xbuild-ism" we were inadvertently using which
msbuild doesn't like: when item metadata is used in
//Target/@Inputs, MSBuild Target Batching is not used.

Case in point, the _Make target:

<!-- BAD! -->
<Target Name="_Make"
    Condition=" '@(_LibZipTarget)' != '' "
    Inputs="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile"
    Outputs="@(Content)">

Because this used "inline" item metadata, the target wasn't being
batched as intended (and as xbuild does). Consequently,
@(_LibZipTarget) was only being built for mxe-Win64, not
mxe-Win32, which is why the <Touch/> use within the _Make target
failed.

The fix? Don't Do That™. Instead, use a new @(_LibZipTargetMakefile)
item group for the //Target/@Inputs, which allows msbuild to
properly batch the _Make target contents:

<ItemGroup>
  <_LibZipTargetMakefile Include="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile" />
</ItemGroup>
<Target Name="_Make"
    Condition=" '@(_LibZipTarget)' != '' "
    Inputs="@(_LibZipTargetMakefile)"
    Outputs="@(Content)">

Review other files matching git grep 'Inputs=.*%' and fix them too.

@jonpryor jonpryor added the full-mono-integration-build For PRs; run a full build (~6-10h for mono bumps), not the faster PR subset (~2h for mono bumps) label Mar 29, 2018
@jonpryor
Copy link
Contributor Author

build

@jonpryor
Copy link
Contributor Author

The macOS+xbuild PR Build errors should be unrelated to this PR.

The macOS+msbuild PR Build timed out (it only had a 6h timeout, not 10h).

I have updated the timeout value and restarted the macOS+msbuild PR Build.

Whenever `external/mono` is bumped, the
[`xamarin-android-msbuild` job breaks][0]:

[0]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-msbuild/838/

	Building target "_Make" completely.
	...
	Task "Touch" (TaskId:1642)
	  Task Parameter:
	    Files=
	      …/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/x64/libzip.dll
	        CMake=/Users/builder/android-toolchain/mxe-b9cbb53/bin/x86_64-w64-mingw32.static-cmake
	        CMakeFlags=
	        CopyToOutputDirectory=Always
	        OutputLibrary=x64/libzip.dll
	        OutputLibraryPath=lib/libzip.dll
	      …/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/libzip.dll
	        CMake=/Users/builder/android-toolchain/mxe-b9cbb53/bin/i686-w64-mingw32.static-cmake
	        CMakeFlags=
	        CopyToOutputDirectory=Always
	        OutputLibrary=libzip.dll
	        OutputLibraryPath=lib/libzip.dll (TaskId:1642)
	  Touching "…/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/x64/libzip.dll". (TaskId:1642)
	…/build-tools/libzip/libzip.targets(52,5): error MSB3375: The file "…/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/libzip.dll" does not exist. […/build-tools/libzip-windows/libzip-windows.csproj]
	Done executing task "Touch" -- FAILED. (TaskId:1642)

This is due to an "`xbuild`-ism" we were inadvertently using which
`msbuild` doesn't like: when item metadata is used in
`//Target/@Inputs`, [MSBuild Target Batching][1] is *not* used.

[1]: https://msdn.microsoft.com/en-us/library/ms171473.aspx

Case in point, the `_Make` target:

	<!-- BAD! -->
	<Target Name="_Make"
	    Condition=" '@(_LibZipTarget)' != '' "
	    Inputs="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile"
	    Outputs="@(Content)">

Because this used "inline" item metadata, the target wasn't being
batched as intended (and as `xbuild` does). Consequently,
`@(_LibZipTarget)` was only being built for mxe-Win64, *not*
mxe-Win32, which is why the `<Touch/>` use within the `_Make` target
failed.

The fix? Don't Do That™. Instead, use a new `@(_LibZipTargetMakefile)`
item group for the `//Target/@Inputs`, which allows `msbuild` to
properly batch the `_Make` target contents:

	<ItemGroup>
	  <_LibZipTargetMakefile Include="$(IntermediateOutputPath)\%(_LibZipTarget.Identity)\Makefile" />
	</ItemGroup>
	<Target Name="_Make"
	    Condition=" '@(_LibZipTarget)' != '' "
	    Inputs="@(_LibZipTargetMakefile)"
	    Outputs="@(Content)">

Review other files matching `git grep 'Inputs=.*%'` and fix them too.
@jonpryor jonpryor force-pushed the jonp-msbuild-libzip-windows branch from 596a08c to a8c3c72 Compare March 30, 2018 14:47
@jonpryor
Copy link
Contributor Author

jonpryor commented Apr 1, 2018

Current macOS+xbuild PR Build error:

22:32:55 	/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/src/proguard/proguard.targets: error : Disk full. Path /Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/external/proguard/lib/proguard.jar" or "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/proguard/lib/proguard.jar  at System.IO.File.Copy (System.String sourceFileName, System.String destFileName, System.Boolean overwrite) [0x00193] in /Users/builder/jenkins/workspace/build-package-osx-mono/2017-12/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/File.cs:111 

"Disk full." :-(

Considering that it previously built, and that it now builds on macOS+msbuild (which was the primary point to this PR), I'm more than happy to merge this.

@jonpryor jonpryor merged commit e3abe4b into dotnet:master Apr 1, 2018
akoeplinger pushed a commit to akoeplinger/xamarin-android that referenced this pull request Apr 4, 2018
Commit 9d131af introduced a [unit test failure][m573] on
xamarin-android/master:

[m573]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/573/

	Xamarin.Android.Build.Tests.BuildTest.XA4212
	Expected: String containing "warning XA4"
	 But was: <log file contents...>

Aside: The XA4212 test creates a project with a bad `IJavaObject`
type, builds the project -- which triggers an XA4212 error, which *is*
observed in the unit test -- then *rebuilds* the project, but this
time with `$(AndroidErrorOnCustomJavaObject)`=False.

The intention is that the second build should instead elicit an XA4212
*warning*, but otherwise continue just fine.

What's interesting about the log file contents is that it shows that
the `<GenerateJavaStubs/>` task isn't executed *at all*, but it's the
`<GenerateJavaStubs/>` task which is supposed to emit the warning!

	Skipping target "_GenerateJavaStubs" because its outputs are up-to-date.

Update the `<GenerateJavaStubs/>` task so that if it errors out, it
*removes* any `<GenerateJavaStubs/>` output files. This will ensure
that on subsequent builds, the `_GenerateJavaStubs` target won't be
inadvertently skipped.

(This issue *should* have been caught during the
[**macOS+xbuild PR builder** build for PR dotnet#797][pr1491]. It *wasn't*,
because the `Xamarin.Android.Build.Tests` tests weren't reported. For
example, PR dotnet#1491 ran 869 tests, while PR dotnet#1492 ran 1085! I'm not sure
what can be done to better detect and prevent this in the future.)

[pr1491]: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-pr-builder/1491/
@atsushieno
Copy link
Contributor

atsushieno commented Apr 5, 2018

This change broke build caching. Now api-*.xml.in is generated EVERY TIME, which adds tremendous aount of build time. And this build happens every time anything that depends on api-*.xml.in and all its subsequent dependencies. For example, Xamarin.Android.Build.Tasks build is suffered from it.

@atsushieno
Copy link
Contributor

This is why things broke. Basically it is due to hacky use of generated item list without existence verification.

Target "_ClassParse" has Inputs="@(_ApiParameterDescription)" which is expanded as follows:

/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-4.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-5.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-6.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-7.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-8.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-10.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-11.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-12.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-13.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-14.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-15.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-16.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-17.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-18.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-19.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-20.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-21.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-22.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-23.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-24.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-25.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-26.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-27.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-28.params.txt

Note that many of those (e.g. API Level 4-9) do not exist. For non-existent inputs, MSBuild targets always execute.

@atsushieno
Copy link
Contributor

Another problem with this condition: if I touch api-27.params.txt it rebuilds everything, not just api-27.

atsushieno added a commit to atsushieno/xamarin-android that referenced this pull request Apr 6, 2018
dotnet#1491 broke build caching.
Now api-*.xml.in is generated EVERY TIME, which adds tremendous amount of
build time. And this build happens every time anything that depends on
api-*.xml.in and all its subsequent dependencies.
For example, Xamarin.Android.Build.Tasks build is suffered from it.

The cause of the problem is this:

	Inputs="@(_ApiParameterDescription)"

which is expanded as follows:

	/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-4.params.txt;/sources/xamarin-android/build-tools/api-xml-adjuster/../../src/Mono.Android/Profiles/api-5.params.txt; ...

Note that many of those (e.g. API Level 4-9) do not exist.
For non-existent inputs, MSBuild targets always execute.

To fix the issue, add another build task that returns only existent files
and use it to determine the actual targets.

This is sadly a compromised solution that updates on ANY API level will
trigger generation of ALL API levels (but must be applied IMMEDIATELY
without excuse for "better solution". It's a BLOCKER for development.
No one can work on MSBuild tasks if this bug remains).
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

full-mono-integration-build For PRs; run a full build (~6-10h for mono bumps), not the faster PR subset (~2h for mono bumps)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants