Skip to content

[tools] Refactor the assembly-preparer code a bit. - #25743

Merged
rolfbjarne merged 9 commits into
mainfrom
dev/rolf/refactor-assembly-preparer
Jun 22, 2026
Merged

rolfbjarne merged 9 commits into
mainfrom
dev/rolf/refactor-assembly-preparer

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

Create separate steps for a few tasks.

There should be no behavioral difference.

It's probably easiest to review this PR commit-by-commit.

@rolfbjarne
rolfbjarne requested a review from Copilot June 18, 2026 16:51
@rolfbjarne

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ .NET for Apple Platforms PR Reviewer completed successfully!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AssemblyInfos to LinkerConfiguration (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 IsCILAssembly flag 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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 💡 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 ❌ 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

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

rolfbjarne and others added 2 commits June 19, 2026 09:35
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>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

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>
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ .NET for Apple Platforms PR Reviewer completed successfully!

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IsCILAssembly flag properly tracks non-managed assemblies
  • The required keyword on AssemblyInfos enforces 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

@github-actions
github-actions Bot dismissed their stale review June 22, 2026 14:15

Superseded by updated review from same workflow.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne marked this pull request as ready for review June 22, 2026 16:35
@rolfbjarne
rolfbjarne enabled auto-merge (squash) June 22, 2026 16:37
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #b50950a] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: b50950a3112496432bf9c8f2ec294faeeedd4027 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #b50950a] Build passed (Build packages) ✅

Pipeline on Agent
Hash: b50950a3112496432bf9c8f2ec294faeeedd4027 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: b50950a3112496432bf9c8f2ec294faeeedd4027 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #b50950a] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: b50950a3112496432bf9c8f2ec294faeeedd4027 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [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
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 20 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: b50950a3112496432bf9c8f2ec294faeeedd4027 [PR build]

@rolfbjarne
rolfbjarne merged commit 360e7b3 into main Jun 22, 2026
56 checks passed
@rolfbjarne
rolfbjarne deleted the dev/rolf/refactor-assembly-preparer branch June 22, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants