[Build] Fix JNI remapping counts lost on incremental builds#11378
Draft
simonrozsival wants to merge 2 commits into
Draft
[Build] Fix JNI remapping counts lost on incremental builds#11378simonrozsival wants to merge 2 commits into
simonrozsival wants to merge 2 commits into
Conversation
GenerateJniRemappingNativeCode registers JNI remapping counts (type and method replacement counts) as an in-memory MSBuild task object. On incremental builds where the remap target is skipped (outputs up to date) but _GeneratePackageManagerJava re-runs (e.g. due to assembly changes), GenerateNativeApplicationConfigSources finds no registered task object and writes zero counts into environment.ll. This silently disables JNI method remapping at runtime (jniRemappingInUse = false). Fix by persisting the counts to a file (jni_remapping_info.txt) alongside the generated jni_remap.ll sources. GenerateNativeApplicationConfigSources falls back to reading this file when the task object is not available. The info file is also added to both the remap targets' Outputs and the _GeneratePackageManagerJava target's Inputs, ensuring proper incremental build invalidation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verifies that building a project with JNI remapping produces a jni_remapping_info.txt file with the correct type and method replacement counts, and that these counts match the values in the generated environment.ll. Without the fix in the previous commit, this file would not be created and the test would fail at the file existence assertion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix an incremental build bug where JNI method remapping gets silently disabled.
Problem
GenerateJniRemappingNativeCoderegisters remapping counts (type and method replacement counts) as an in-memory MSBuild task object viaBuildEngine4.RegisterTaskObjectAssemblyLocal. On incremental builds where the remap target is skipped (its outputs are up to date) but_GeneratePackageManagerJavare-runs (e.g. due to a changed framework assembly),GenerateNativeApplicationConfigSourcesfinds no registered task object and writes zero counts intoenvironment.ll. This setsjniRemappingInUse = falseat runtime, causingNoSuchMethodErrorfor any remapped methods.Repro
Mono.Android.NET-Tests)Mono.Android(not the remap config) and rebuild_GeneratePackageManagerJavare-runsenvironment.llnow hasjni_remapping_replacement_type_count = 0NoSuchMethodErrorFix
GenerateJniRemappingNativeCodenow persists the counts to ajni_remapping_info.txtfile alongside the generated.llsourcesGenerateNativeApplicationConfigSourcesfalls back to reading this file when the task object is not available (i.e. the remap target was skipped)Outputsand_GeneratePackageManagerJava'sInputs, ensuring proper incremental build invalidation in both directionsTest
JniRemappingInfoFileRoundTrip— builds a project with JNI remapping, verifiesjni_remapping_info.txtis created with correct counts, and confirms the counts match the generatedenvironment.ll