Skip to content

[tools] Remove most static state from the tools.#25619

Merged
rolfbjarne merged 3 commits into
mainfrom
dev/rolf/tools-less-static-state
Jun 4, 2026
Merged

[tools] Remove most static state from the tools.#25619
rolfbjarne merged 3 commits into
mainfrom
dev/rolf/tools-less-static-state

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

The remaining static state is mostly caching of environment variables (which won't
change during a process' lifetime).

This is necessary, because soon we'll include some of this code in MSBuild tasks,
which shouldn't have static state.

The remaining static state is mostly caching of environment variables (which won't
change during a process' lifetime).

This is necessary, because soon we'll include some of this code in MSBuild tasks,
which shouldn't have static state.
Copilot AI review requested due to automatic review settings June 2, 2026 15:19
@rolfbjarne rolfbjarne requested a review from mauroa as a code owner June 2, 2026 15:19
@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

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 continues the tools refactor to reduce (or eliminate) static state so the same code can be safely reused from MSBuild tasks. Most of the remaining static state becomes either immutable (readonly) or scoped to a specific tool/configuration instance (including per-link-context caches).

Changes:

  • Moved a number of previously-static configuration values to Application / IToolLog (ex: Xcode/SDK/target framework, platform, warning-level state).
  • Updated linker steps and helpers to use the instance-scoped Application (App) instead of Driver/static globals.
  • Reworked a few caches to avoid process-wide static dictionaries (ex: via ConditionalWeakTable), and marked shared immutable values as readonly.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tools/mtouch/AssemblyResolver.cs Makes Cecil ReaderParameters defaults immutable (readonly).
tools/linker/CoreTypeMapStep.cs Removes static cache state; makes CI filter cache instance-scoped.
tools/dotnet-linker/Steps/TrimmableRegistrarStep.cs Uses App.TargetFramework instead of Driver.TargetFramework to avoid static state.
tools/dotnet-linker/Steps/ConfigurationAwareStep.cs Uses ProductException.IsError (App) to correctly classify warnings/errors per-configuration.
tools/dotnet-linker/SetupStep.cs Removes static ErrorHelper.Platform initialization (platform now comes from log/app).
tools/dotnet-linker/LinkerConfiguration.cs Routes configuration through Application and updates warning parsing/reporting to be app-aware; improves “no configuration available” fallback.
tools/dotnet-linker/BackingFieldDelayHandler.cs Scopes cached method bodies per link context via ConditionalWeakTable.
tools/common/StringUtils.cs Marks static quoting state as readonly.
tools/common/StaticRegistrar.cs Switches Xcode version access to App instead of Driver.
tools/common/Optimizations.cs Marks static option metadata arrays as readonly.
tools/common/IToolLog.cs Adds Platform to IToolLog so error prefixing and warning escalation can be log/app scoped.
tools/common/Frameworks.cs Marks sentinel version as readonly.
tools/common/FileCopier.cs Removes Driver.Force dependency from up-to-date checks.
tools/common/ErrorHelper.tools.cs Replaces static global warning-level storage with per-log state (ConditionalWeakTable), and derives error prefix from IToolLog.Platform.
tools/common/error.cs Refactors ProductException severity calculation to be log-aware (IsError (log)), and formats prefix via ErrorHelper.GetPrefix.
tools/common/Driver.cs Moves various values from static Driver into Application (SdkRoot, DeveloperDirectory, Xcode version/product version, framework dir).
tools/common/cache.cs Removes Driver.Force from cache comparisons (now purely content/mtime based).
tools/common/Application.cs Introduces instance properties for target framework/Xcode/SDK state and moves default hidden-warning initialization to the instance.
src/bgen/BindingTouch.cs Implements IToolLog.Platform for bgen so shared error logic can select the right prefix.
msbuild/Xamarin.MacDev.Tasks/ErrorHelper.msbuild.cs Aligns prefix API with tools-side GetPrefix (IToolLog?) signature for the partial ErrorHelper.
Comments suppressed due to low confidence (1)

tools/common/ErrorHelper.tools.cs:310

  • When a warning is promoted to an error (WarnAsError), mte.IsError (log) may return true, but the printed diagnostic still uses ProductException.ToString() which calls ToString (null) and will always format promoted warnings as warning ... instead of error .... This can confuse MSBuild parsing and users; pass the log into ToString so severity/prefix are consistent with IsError (log).
				if (!error && GetWarningLevel (log, mte.Code) == WarningLevel.Disable)
					return false; // This is an ignored warning.

				log.LogError (mte.ToString ());

				ShowInner (log, e);

public string FrameworkCurrentDirectory {
get {
if (framework_dir is null)
throw new InvalidOperationException ($"Teh current framework directory hasn't been set.");
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@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.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 3 pipeline(s).

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

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

Pipeline on Agent
Hash: 1340f200af928e81ad53c5ae3dd1ed13fc0e43f4 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #1340f20] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 1340f200af928e81ad53c5ae3dd1ed13fc0e43f4 [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: 1340f200af928e81ad53c5ae3dd1ed13fc0e43f4 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #1340f20] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 1340f200af928e81ad53c5ae3dd1ed13fc0e43f4 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #1340f20] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 193 tests passed 🎉

Tests counts

✅ 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 6 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 23 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 23 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: 1340f200af928e81ad53c5ae3dd1ed13fc0e43f4 [PR build]

@rolfbjarne rolfbjarne merged commit 90011e1 into main Jun 4, 2026
55 checks passed
@rolfbjarne rolfbjarne deleted the dev/rolf/tools-less-static-state branch June 4, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants