Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/8.0.2xx] [Xamarin.Android.Build.Tasks] DTBs should not rm generator output #8835

Merged

Conversation

jonathanpeppers
Copy link
Member

Backport of: #8706

Fixes: #8658
Fixes: #8698

Design-time builds don't play nicely with binding project builds:

% dotnet new androidlib
% cat > Example.java <<EOF
package e;

public class Example {
    public static void e() {
    }
}
EOF
% dotnet build -p:DesignTimeBuild=true -v:diag

After this initial Design-Time build, we have the following generated source code for the binding:

% find obj -iname \*.cs | xargs ls -l
-rw-r--r--  1 user staff   197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs
-rw-r--r--  1 user staff   441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs
-rw-r--r--  1 user staff  2975 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/E.Example.cs
-rw-r--r--  1 user staff  1518 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/Java.Interop.__TypeRegistrations.cs
-rw-r--r--  1 user staff   696 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/__NamespaceMapping__.cs
-rw-r--r--  1 user staff  1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs
-rw-r--r--  1 user staff   407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs

Run a Design-Time build again:

% dotnet build -p:DesignTimeBuild=true -v:diag

…and we're now missing files (?!):

% find obj -iname \*.cs | xargs ls -l
-rw-r--r--  1 user staff   197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs
-rw-r--r--  1 user staff   441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs
-rw-r--r--  1 user staff  1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs
-rw-r--r--  1 user staff   407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs

In particular, $(IntermediateOutputPath)generated/*/**.cs is gone, including E.Example.cs!

The result of this is that Design-Time builds and "normal" builds "fight" each other, constantly generating and deleting files, slowing down incremental builds.

The root of the problem is the _ClearGeneratedManagedBindings target: It was designed to clean out the generated folder in the case where no binding libraries were present. However, it turns out it was running during a design time build! During design time builds the binding library item groups are not evaluated, so the _ClearGeneratedManagedBindings target would run, deleting everything.

Fix this by ensuring we only run the _ClearGeneratedManagedBindings target in in "standard"/non-Design-Time builds.

Fixes: dotnet#8658
Fixes: dotnet#8698

Design-time builds don't play nicely with binding project builds:

	% dotnet new androidlib
	% cat > Example.java <<EOF
	package e;

	public class Example {
	    public static void e() {
	    }
	}
	EOF
	% dotnet build -p:DesignTimeBuild=true -v:diag

After this initial Design-Time build, we have the following generated
source code for the binding:

	% find obj -iname \*.cs | xargs ls -l
	-rw-r--r--  1 user staff   197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs
	-rw-r--r--  1 user staff   441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs
	-rw-r--r--  1 user staff  2975 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/E.Example.cs
	-rw-r--r--  1 user staff  1518 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/Java.Interop.__TypeRegistrations.cs
	-rw-r--r--  1 user staff   696 Mar 25 19:22 obj/Debug/net8.0-android/generated/src/__NamespaceMapping__.cs
	-rw-r--r--  1 user staff  1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs
	-rw-r--r--  1 user staff   407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs

Run a Design-Time build *again*:

	% dotnet build -p:DesignTimeBuild=true -v:diag

…and we're now missing files (?!):

	% find obj -iname \*.cs | xargs ls -l
	-rw-r--r--  1 user staff   197 Mar 25 19:22 obj/Debug/net8.0-android/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs
	-rw-r--r--  1 user staff   441 Mar 25 19:22 obj/Debug/net8.0-android/__Microsoft.Android.Resource.Designer.cs
	-rw-r--r--  1 user staff  1094 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.AssemblyInfo.cs
	-rw-r--r--  1 user staff   407 Mar 25 19:22 obj/Debug/net8.0-android/gxa-8706.GlobalUsings.g.cs

In particular, `$(IntermediateOutputPath)generated/*/**.cs` is gone,
including `E.Example.cs`!

The result of this is that Design-Time builds and "normal" builds
"fight" each other, constantly generating and deleting files, slowing
down incremental builds.

The root of the problem is the `_ClearGeneratedManagedBindings`
target: It was designed to clean out the `generated` folder in the
case where no binding libraries were present.  However, it turns out
it was running during a design time build!  During design time builds
the binding library item groups are not evaluated, so the
`_ClearGeneratedManagedBindings` target would run, deleting everything.

Fix this by ensuring we only run the `_ClearGeneratedManagedBindings`
target in in "standard"/*non*-Design-Time builds.
@jonathanpeppers
Copy link
Member Author

There are a couple test failures, we can ignore:

APK tests have a few:

System.Net.Http.HttpRequestException : net_http_message_not_success_statuscode_reason, 404, Not Found

Then 1 MSBuild test:

Exceeded expected time of 13500ms, actual 21371.052ms

But when I download the .binlog it's not any of our tasks:
image

There seems to be 10 lost seconds in MSBuild somewhere?

image

Going to just ignore, might be general slowness on the build machine.

@jonathanpeppers jonathanpeppers merged commit 20d9605 into dotnet:release/8.0.2xx Mar 26, 2024
43 of 46 checks passed
@jonathanpeppers jonathanpeppers deleted the backport-8706 branch March 26, 2024 22:14
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 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.

2 participants