Repository navigation
[tools] Refactor the assembly-preparer code a bit. - #25743
Conversation
…embly in the AssemblyPreparerInfo.
|
/review |
|
✅ .NET for Apple Platforms PR Reviewer completed successfully! |
There was a problem hiding this comment.
Pull request overview
This PR refactors the tools/assembly-preparer pipeline by extracting assembly loading/saving and a couple of preparatory tasks into separate ConfigurationAwareStep implementations, and threads the assembly list through LinkerConfiguration for those steps to consume.
Changes:
- Add
AssemblyInfostoLinkerConfiguration(assembly-preparer build) so steps can iterate the assemblies-to-prepare list. - Split assembly-preparer work into new steps: load assemblies, compute method overrides, collect
[Field]symbols, and save assemblies. - Add a per-assembly
IsCILAssemblyflag to support pass-through of non-managed assemblies.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/dotnet-linker/LinkerConfiguration.cs | Adds AssemblyInfos for ASSEMBLY_PREPARER and imports needed types. |
| tools/assembly-preparer/AssemblyPreparer.cs | Switches to running the new step-based pipeline and wires AssemblyInfos. |
| tools/assembly-preparer/LoadAssembliesStep.cs | New step to read assemblies, set link actions, and populate resolver cache. |
| tools/assembly-preparer/ComputeMethodOverridesStep.cs | New step to collect overrides into annotations. |
| tools/assembly-preparer/CollectFieldsStep.cs | New step to collect [Field] symbol names for InlineDlfcn compat mode. |
| tools/assembly-preparer/SaveAssembliesStep.cs | New step to write processed assemblies back to disk. |
There was a problem hiding this comment.
Review Summary
Verdict: ❌ Changes Requested
Issue Count:
- ❌ Errors: 1
⚠️ Warnings: 0- 💡 Suggestions: 1
Overview
This PR refactors assembly loading logic from AssemblyPreparer.cs into a new dedicated LoadAssembliesStep class. This is a good architectural change that aligns with the existing step-based pattern used throughout the linker pipeline.
Positive Callouts
✅ Good architectural improvement — Moving the assembly loading logic into a dedicated step makes the code more modular and follows the established pattern in the codebase.
✅ Code moved correctly — The logic appears to be extracted faithfully with proper references to Configuration properties instead of the previous local variables.
✅ Proper integration — The new step is correctly added to the pipeline in AssemblyPreparer.cs at line 122.
Issues to Address
The main issue is the missing license header (❌ error) — the file still has a placeholder comment instead of the actual license. Additionally, there's an unused using directive that should be cleaned up (💡 suggestion).
Once the license header is added, this refactoring will be ready to merge.
Generated by .NET for Apple Platforms PR Reviewer for issue #25743 · sonnet45 825.7K
Comment /review to run again
| // Copilot: add license | ||
|
|
||
| using Mono.Cecil; | ||
| using Mono.Cecil.Cil; |
There was a problem hiding this comment.
🤖 💡 Code organization — Unused using directive. Mono.Cecil.Cil is not used anywhere in this file and should be removed.
Rule: Remove unused code
| @@ -0,0 +1,124 @@ | |||
| // Copilot: add license | |||
There was a problem hiding this comment.
🤖 ❌ Documentation — Missing license header. Replace the placeholder comment with the standard license header:
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.This matches the pattern used in other files in the repository (e.g., AssemblyPreparer.cs).
Rule: License headers must be present in all source files
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
- Add proper MIT license headers to new files - Remove unused ModuleAttributes local variable in SaveAssembliesStep - Guard 'using Xamarin.Build' with #if ASSEMBLY_PREPARER in LinkerConfiguration.cs - Fix AssemblyInfos initialization to use Assemblies property (populated by configurator) instead of constructor parameter, fixing the repro path flow Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/review |
|
✅ .NET for Apple Platforms PR Reviewer completed successfully! |
There was a problem hiding this comment.
Code Review Summary
✅ LGTM — This is a clean refactoring that improves code organization without changing behavior.
Overview
This PR successfully extracts assembly-preparer logic into separate, focused step classes:
- LoadAssembliesStep — loads and validates assemblies
- ComputeMethodOverridesStep — builds method override map
- CollectFieldsStep — extracts field symbols for inline optimization
- SaveAssembliesStep — writes processed assemblies
The refactoring reduces the main Prepare() method from ~250 lines to ~25 lines by moving code into dedicated classes, making the codebase more maintainable.
Issues Found
💡 Suggestions: 1
- Exception swallowing in SaveAssembliesStep (consider if a warning is appropriate)
Positive Observations
✅ Good refactoring practices:
- Each new step class has a single, clear responsibility
- Error handling is preserved during the move
- The
IsCILAssemblyflag properly tracks non-managed assemblies - The
requiredkeyword onAssemblyInfosenforces initialization at compile time - Comments are updated to reflect the new structure
✅ No behavioral changes: The refactored code maintains the exact same logic flow and error handling as the original inline implementation.
✅ Consistent patterns: The new step classes follow the existing ConfigurationAwareStep pattern used throughout the codebase.
CI Status
Most tests are passing. The 2 failing test suites (linker_tvos, generator) appear unrelated to this refactoring based on the nature of the changes (pure code movement with no logic changes).
Generated by .NET for Apple Platforms PR Reviewer for issue #25743 · sonnet45 1.5M
Comment /review to run again
Superseded by updated review from same workflow.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #b50950a] Build passed (Detect API changes) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #b50950a] Build passed (Build packages) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [PR Build #b50950a] Build passed (Build macOS tests) ✅Pipeline on Agent |
🚀 [CI Build #b50950a] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 207 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Create separate steps for a few tasks.
There should be no behavioral difference.
It's probably easiest to review this PR commit-by-commit.