Skip to content

[tests] Improve trimmer warning diagnostics#11981

Merged
jonathanpeppers merged 2 commits into
mainfrom
dev/simonrozsival/buildtest2-trimmer-warning-diagnostics
Jul 6, 2026
Merged

[tests] Improve trimmer warning diagnostics#11981
jonathanpeppers merged 2 commits into
mainfrom
dev/simonrozsival/buildtest2-trimmer-warning-diagnostics

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Jul 4, 2026

Copy link
Copy Markdown
Member

Improve the failure message in BuildHasTrimmerWarnings by parsing the warning summary and printing the warning lines found when the expected count does not match.

Split out from #11669 so the RuntimeFeature PR stays focused.

Report the parsed warning summary and the warning lines found when BuildHasTrimmerWarnings gets an unexpected warning count.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 4, 2026 19:05

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

Improves diagnostics in the BuildHasTrimmerWarnings test to make trimmer-warning failures easier to understand by extracting the warning summary count and printing the warning lines found when expectations don’t match.

Changes:

  • Parse the MSBuild warning summary line (N Warning(s)) and compare the parsed count to the expected total.
  • Collect and print up to 25 warning lines (: warning ) in assertion failures to aid debugging.
  • Add a local helper (GetWarningCount) to parse the summary line.
Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs Enhances BuildHasTrimmerWarnings failure output by parsing the warning summary and printing captured warning lines.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment on lines +607 to +611
string warningSummaryLine = b.LastBuildOutput.LastOrDefault (line => line.Contains ("Warning(s)", StringComparison.Ordinal)) ?? "";
var actualWarnings = GetWarningCount (warningSummaryLine);

var allWarningLines = b.LastBuildOutput
.Where (line => line.Contains (": warning ", StringComparison.OrdinalIgnoreCase))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot address this feedback and optimize this code

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.

Fixed in 8b7a09c — b.LastBuildOutput is now materialized into a string[] once, and all three usages (LastOrDefault, Where/Take, and the per-code ContainsText loop) operate on that array.

@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Jul 4, 2026
Co-authored-by: simonrozsival <374616+simonrozsival@users.noreply.github.com>
@jonathanpeppers
jonathanpeppers merged commit fb5ea48 into main Jul 6, 2026
42 checks passed
@jonathanpeppers
jonathanpeppers deleted the dev/simonrozsival/buildtest2-trimmer-warning-diagnostics branch July 6, 2026 13:42
jonathanpeppers pushed a commit that referenced this pull request Jul 7, 2026
… conflict warnings (#11669)

### Summary

`Microsoft.Android.Runtime.RuntimeFeature` was compiled into **two** assemblies:

- `Mono.Android.Runtime.dll` (`src/Mono.Android.Runtime/Mono.Android.Runtime.csproj`)
- `Mono.Android.dll` (`src/Mono.Android/Mono.Android.csproj`)

Because `Mono.Android` references `Mono.Android.Runtime`, compiling `Mono.Android.dll` emitted duplicate-type warnings like:

```text
warning CS0436: The type 'RuntimeFeature' in
'src/Mono.Android/Microsoft.Android.Runtime/RuntimeFeature.cs' conflicts with the
imported type 'RuntimeFeature' in 'Mono.Android.Runtime'.
```

This PR makes `RuntimeFeature` live in **exactly one** assembly: `Mono.Android.Runtime.dll`.

### Changes

- **`Mono.Android.csproj`** — removes the duplicate `<Compile>` of `RuntimeFeature.cs`, so the type is no longer compiled into `Mono.Android.dll`.
- **`AndroidRuntime.cs`, `JNIEnv.cs`, `TypeManager.cs`** — adds `using RuntimeFeature = Microsoft.Android.Runtime.RuntimeFeature;` because once `RuntimeFeature` is imported instead of source-compiled into `Mono.Android`, the bare name conflicts with `System.Runtime.CompilerServices.RuntimeFeature`.
- **`Mono.Android.Runtime.csproj` / `Mono.Android.Runtime.targets`** — migrates assembly metadata from the hand-written `Properties/AssemblyInfo.cs.in` template to MSBuild `GenerateAssemblyInfo`:
  - Deletes `Properties/AssemblyInfo.cs.in` and the `_BuildAssemblyInfo_cs` target (which ran `ReplaceFileContents` on the template) from `Mono.Android.Runtime.targets`.
  - Sets `<GenerateAssemblyInfo>true</GenerateAssemblyInfo>` with `GenerateAssemblyConfigurationAttribute`, `GenerateAssemblyFileVersionAttribute`, `GenerateAssemblyVersionAttribute`, `GenerateRepositoryUrlAttribute`, and `IncludeSourceRevisionInInformationalVersion` all set to `false` so no new attributes are introduced vs. the old template.
  - Moves the attribute values to properties/items: `AssemblyTitle`, `Product`, `Company`, and the `InternalsVisibleTo` items. A new `_SetGeneratedAssemblyInfoProperties` target (before `GetAssemblyAttributes`) supplies `InformationalVersion`, `TargetPlatformIdentifier`/`TargetPlatformVersion`, and `SupportedOSPlatformVersion` from the existing `GetXAVersionInfo` version info.
  - Adds `InternalsVisibleTo` for `Microsoft.Android.Runtime.NativeAOT` and `Mono.Android.NET-Tests`, which previously reached `RuntimeFeature` through `Mono.Android.dll`.
  - Marks `Mono.Android.Runtime.dll` trimmable with `<IsTrimmable>true</IsTrimmable>`. This keeps the cross-assembly `RuntimeFeature` feature switches visible to ILLink in partial-trimmed apps.

### Why `IsTrimmable` is needed

Moving `RuntimeFeature` into `Mono.Android.Runtime.dll` makes `Mono.Android.dll` consume feature-switch properties across an assembly boundary. In partial trimming, ILLink only substitutes feature-switch getters in assemblies it processes. Without marking `Mono.Android.Runtime.dll` trimmable, some runtime-specific branches stayed live, causing the CoreCLR APK size-regression test to fail.

Marking `Mono.Android.Runtime.dll` trimmable lets ILLink fold those `RuntimeFeature` guards again.

### Relationship to #11625

This is a focused subset of #11625. It intentionally avoids the broader class rename (`RuntimeFeature` → `AndroidRuntimeFeature`) and resolves the resulting `CS0104` ambiguity with local `using` aliases instead.

### Follow-up

The `BuildHasTrimmerWarnings` diagnostic improvement was split out into #11981 so this PR remains focused on the `RuntimeFeature` single-assembly change.

### Verification

Latest PR validation: [dotnet-android #1496564](https://dev.azure.com/dnceng-public/cbb18261-c48f-4abb-8651-8cdcb5474649/_build/results?buildId=1496564) ✅

The produced `Mono.Android.Runtime.dll` from that build was inspected to confirm the `GenerateAssemblyInfo` migration is faithful — all attributes from the old `AssemblyInfo.cs.in` (`AssemblyTitle`, `Product`, `Company`, `AssemblyInformationalVersion`, `TargetPlatform=Android37.0`, `SupportedOSPlatform=Android24.0`, `InternalsVisibleTo` for `Mono.Android`) are present, the new `InternalsVisibleTo` (NativeAOT, NET-Tests) and `IsTrimmable` metadata are added, and no unexpected attributes (`AssemblyConfiguration`, `AssemblyFileVersion`, `AssemblyVersion`, `RepositoryUrl`) were introduced.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants