Skip to content

Conversation

@jonathanpeppers
Copy link
Member

When building xamarin-android, I noticed this always runs when there
are no changes:

Target Name=BuildJniEnvironment_g_cs Project=Java.Interop.csproj
Building target "BuildJniEnvironment_g_cs" completely.
Input file "C:\src\xamarin-android\external\Java.Interop\bin\BuildDebug\jnienv-gen.exe" is newer than output file "Java.Interop/JniEnvironment.g.cs".
...
Exec Task (345ms)

Reviewing the code in jnienv-gen.exe, it might not actually update
either of the Outputs if there are no changes.

So we can either:

  1. Add a <Touch/> call in the BuildJniEnvironment_g_cs MSBuild
    target.
  2. Make jnienv-gen.exe always update the files.

I think we should just go with option 2, as it was basically doing:

if (!File.Exists (jnienv_g_cs) || !string.Equals (content, File.ReadAllText (jnienv_g_cs)))
    File.WriteAllText (jnienv_g_cs, content);

The string.Equals call doesn't seem terrible efficient anyway--let's
just remove it and always write.

Now we get this on builds without changes:

Skipping target "BuildJniEnvironment_g_cs" because all output files are up-to-date with respect to the input files.

Fixing this seems to save the ~350ms per $(TargetFramework) in
Java.Interop.csproj.

When building `xamarin-android`, I noticed this always runs when there
are no changes:

    Target Name=BuildJniEnvironment_g_cs Project=Java.Interop.csproj
    Building target "BuildJniEnvironment_g_cs" completely.
    Input file "C:\src\xamarin-android\external\Java.Interop\bin\BuildDebug\jnienv-gen.exe" is newer than output file "Java.Interop/JniEnvironment.g.cs".
    ...
    Exec Task (345ms)

Reviewing the code in `jnienv-gen.exe`, it might not actually update
either of the `Outputs` if there are no changes.

So we can either:

1. Add a `<Touch/>` call in the `BuildJniEnvironment_g_cs` MSBuild
   target.
2. Make `jnienv-gen.exe` always update the files.

I think we should just go with option 2, as it was basically doing:

    if (!File.Exists (jnienv_g_cs) || !string.Equals (content, File.ReadAllText (jnienv_g_cs)))
        File.WriteAllText (jnienv_g_cs, content);

The `string.Equals` call doesn't seem terrible efficient anyway--let's
just remove it and always write.

Now we get this on builds without changes:

    Skipping target "BuildJniEnvironment_g_cs" because all output files are up-to-date with respect to the input files.

Fixing this seems to save the ~350ms per `$(TargetFramework)` in
`Java.Interop.csproj`.
@jpobst
Copy link
Contributor

jpobst commented Jul 8, 2020

I guess this part of the BuildJniEnvironment_g_cs target is no longer needed since we now have globs: https://github.com/xamarin/java.interop/blob/master/src/Java.Interop/Directory.Build.targets#L25-L27.

Prior to globs I assume this target needed to run every time in order to add the file to the compilations?

@jonpryor jonpryor merged commit 25458a5 into dotnet:master Jul 8, 2020
@jonathanpeppers jonathanpeppers deleted the fix-incremental-build branch July 8, 2020 16:32
@jonathanpeppers
Copy link
Member Author

@jpobst you could try removing this line:

https://github.com/xamarin/java.interop/blob/25458a5e579154c3a72e16325193010e3ade614f/src/Java.Interop/Directory.Build.targets#L25-L27

But since the file doesn't exist at MSBuild evaluation time and is created by this target, I think it would still be missing from @(Compile).

jonpryor pushed a commit that referenced this pull request Jul 22, 2020
When building `xamarin-android`, I noticed this always runs when
there are no changes:

	Target Name=BuildJniEnvironment_g_cs Project=Java.Interop.csproj
	Building target "BuildJniEnvironment_g_cs" completely.
	Input file "…\xamarin-android\external\Java.Interop\bin\BuildDebug\jnienv-gen.exe" is newer than output file "Java.Interop/JniEnvironment.g.cs".
	…
	Exec Task (345ms)

Reviewing the code in `jnienv-gen.exe`, it might not actually update
either of the `Outputs` if there are no changes.

So we can either:

 1. Add a `<Touch/>` call in the `BuildJniEnvironment_g_cs` MSBuild
    target.
 2. Make `jnienv-gen.exe` always update the files.

I think we should just go with option 2, as it was basically doing:

	if (!File.Exists (jnienv_g_cs) || !string.Equals (content, File.ReadAllText (jnienv_g_cs)))
	    File.WriteAllText (jnienv_g_cs, content);

The `string.Equals()` call doesn't seem terrible efficient anyway;
let's just remove it and always write.

Now we get this on builds without changes:

	Skipping target "BuildJniEnvironment_g_cs" because all output files are up-to-date with respect to the input files.

Fixing this seems to save the ~350ms per `$(TargetFramework)` in
`Java.Interop.csproj`.
@jpobst jpobst added this to the 10.5 (16.8 / 8.8) milestone Jul 28, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 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