Repository navigation
[build] Isolate Java naming policy in build tools - #13537
Conversation
Assembly modification no longer generates Java names. Retain the task input for compatibility without changing process-wide naming policy. Co-authored-by: Copilot App <[email protected]>
Use the existing banned API analyzer to reject direct policy reads and writes. Preserve imported warning-as-error settings so RS0030 remains an error. Co-authored-by: Copilot App <[email protected]>
Delete the no-op input and its MSBuild binding. Remove the earlier input-setting test; the banned API analyzer still rejects global policy access in tasks. Co-authored-by: Copilot App <[email protected]>
Add explicit-policy naming overloads while preserving existing runtime and tooling entry points. Migrate the generator and legacy manifest helper callers, and ban the implicit-policy APIs in both build projects. Co-authored-by: Copilot App <[email protected]>
Retain the missing policy-isolation check without repeating policy, nested-name, registered-name and framework-name coverage. Co-authored-by: Copilot App <[email protected]>
Merge naming restrictions into BannedSymbols.txt and reuse the common analyzer import. Update generator resolutions required by the existing Cecil restrictions without changing naming policy selection. Co-authored-by: Copilot App <[email protected]>
Share the operation TypeDefinitionCache through generation options so importer interface, base-type and field resolutions are cached rather than bypassing the banned Resolve API through the module resolver. Co-authored-by: Copilot App <[email protected]>
7b43e0d to
328be58
Compare
| JavaNativeTypeManager.PackageNamingPolicy = Enum.TryParse (PackageNamingPolicy, out PackageNamingPolicyEnum pnp) ? pnp : PackageNamingPolicyEnum.LowercaseCrc64; | ||
|
|
There was a problem hiding this comment.
This was static state that wouldn't work under -mt.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the changes isolating Java naming policy from process-wide state.
No open issues 🎉
What changed in this PR
Isolates Java naming policy in host build tools from process-wide state, building on the manifest cleanup in #13525 while preserving existing public naming overloads.
Changes:
- Removes the unused naming-policy task input and global-state write.
- Passes
LowercaseCrc64explicitly in the binding generator and shares its type-resolution cache. - Adds analyzer guards against implicit-policy APIs and a regression test for explicit-policy isolation.
| File | Description |
|---|---|
tests/Java.Interop.Tools.JavaCallableWrappers-Tests/Java.Interop.Tools.JavaCallableWrappers/JavaNativeTypeManagerTests.cs |
Tests that explicit naming policy ignores global-state changes. |
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets |
Stops passing the unused naming-policy task input. |
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj |
Preserves inherited warnings-as-errors settings. |
src/Xamarin.Android.Build.Tasks/Tasks/AssemblyModifierPipeline.cs |
Removes the policy input and process-wide mutation. |
src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs |
Adds explicit-policy overloads while retaining existing APIs. |
src/generator/Java.Interop.Tools.Generator.Importers/CecilApiImporter.cs |
Routes type resolution through the shared cache. |
src/generator/generator.csproj |
Enables banned-API analyzer rules. |
src/generator/CodeGenerator.cs |
Uses explicit naming policy, shares the cache, and removes redundant resolution. |
src/generator/CodeGenerationOptions.cs |
Provides the shared type-resolution cache. |
build-tools/banned-apis/BannedSymbols.txt |
Bans global naming-state access and implicit-policy APIs in consuming build projects. |
Review effort: Balanced
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
LGTM. Moving the naming policy off the mutable JavaNativeTypeManager.PackageNamingPolicy static and banning it in Build.Tasks and the generator looks right for -mt.
- At this head nothing in Build.Tasks, Microsoft.Android.Build.Tasks or the JCW library reads the static anymore, so the
AssemblyModifierPipelinesetter you removed was effectively dead.$(AndroidPackageNamingPolicy)still reaches native config (GenerateNativeApplicationConfigSources) and the trimmable typemap explicitly, so non-default policies aren't regressed. - The generator never set the static, so passing
LowercaseCrc64explicitly keeps its output identical. RoutingResolve()throughTypeCacheis the same memoised resolution. - I found no remaining banned symbols in either project, including linked sources (the only
.Resolve()left in Build.Tasks isMemberReference.ResolveinLinkDesignerBase.cs), so turning RS0030 into an error shouldn't break the build. - The expected
crc642048bf8bbd1f1138checks out against the CRC-64 used byCrc64Helper.
Minor, not blocking: removing the public PackageNamingPolicy task parameter would break any external targets that set it (MSB4064), but nothing in the repo does and the task is SDK-internal.
Static read-only review; nothing was built or run.
Stacked on #13525. This layer contains no manifest deletion or generator behavior fix.
AssemblyModifierPipelinestill wrote the process-wide Java naming policy after its naming consumers were removed. Delete that write and unused task input. Pass policy explicitly in the binding generator, retaining its existingLowercaseCrc64behavior, and ban the implicit-policy APIs in both build projects.Keep existing public naming overloads for runtime and external tooling callers. Add one focused test showing explicit policy calls ignore changes to global state. Task MT remains disabled.
Local validation: SDK build and 112 tests passed
Commands used this worktree's pinned SDK and rebuilt outputs:
The first parallel test-build attempt hit a shared-output file lock; the naming suite passed when rerun after the generator build.
Host-only app checks also passed for both supported policies:
Inspection of 253 rebuilt SDK tool assemblies found no path from their naming calls to the static policy getter. No device tests were run; this changes host build tools only.