Commit 6ed93c7
[TrimmableTypeMap] Extract TrimmableTypeMapGenerator from MSBuild task (#11034)
## Summary
Extract the core generation pipeline (scan → typemaps → JCW → acw-map) from the `GenerateTrimmableTypeMap` MSBuild task into a standalone `TrimmableTypeMapGenerator` class. The generator is **IO-free** — it accepts `PEReader` instances and returns in-memory content. The MSBuild task owns all filesystem IO.
## Motivation
The generator logic was tightly coupled to MSBuild types (`TaskLoggingHelper`, `ITaskItem`) and performed filesystem IO directly (creating directories, checking timestamps, writing files). This made it hard to test without full MSBuild ceremony and temp directories. Extracting it with an IO-free API enables fast, focused unit tests using xUnit + `TestFixtures.dll` that assert on in-memory content.
## Changes
### New files
- `TrimmableTypeMapGenerator.cs` — orchestrates scan → typemaps → JCW pipeline as a pure transformation: `(name, PEReader)[]` in → `(GeneratedAssembly, GeneratedJavaSource)[]` out. No filesystem IO.
- `TrimmableTypeMapTypes.cs` — `TrimmableTypeMapResult`, `GeneratedAssembly(Name, MemoryStream)`, `GeneratedJavaSource(RelativePath, Content)` records
- `NullableExtensions.cs` — NRT-annotated `IsNullOrEmpty`/`IsNullOrWhiteSpace` for netstandard2.0
- `TrimmableTypeMapGeneratorTests.cs` — 6 xUnit tests covering the generator directly (empty input, no-peers output, null validation, PE validity, Java source structure). Tests are IO-free.
### Modified files
- `GenerateTrimmableTypeMap.cs` — rewritten as IO adapter: creates `PEReader` instances from files, calls the generator, writes all outputs to disk using `Files.CopyIfStreamChanged`. Owns directory creation, assembly writing, Java source writing, acw-map generation, and `MemoryStream` disposal in a `finally` block.
- `GenerateTrimmableTypeMapTests.cs` — 5 task-level NUnit tests: empty list, invalid TFV, valid TFV parsing (`v11.0`/`v10.0`/`11.0`), Mono.Android integration, incremental up-to-date check
- `AssemblyIndex.cs` — added `Create(PEReader, string)` overload, removed `FilePath` property, no longer owns `PEReader` disposal
- `JavaPeerScanner.cs` — added `Scan((string, PEReader)[])` overload with shared `ScanCore()`
- `JcwJavaSourceGenerator.cs` — added `GenerateContent()` returning `(relativePath, content)` pairs without filesystem writes, made `Generate(type, TextWriter)` public
- `PEAssemblyBuilder`, `RootTypeMapAssemblyGenerator`, `TypeMapAssemblyEmitter`, `TypeMapAssemblyGenerator` — removed file-path writing overloads, stream-based output only
### Design decisions
- `Action<string>` instead of `TaskLoggingHelper` — keeps TrimmableTypeMap project free of Microsoft.Build packages
- Generator accepts `PEReader` pairs (not file paths or raw streams) — `PEReader` already owns PE parsing; MSBuild task creates them from files, tests from in-memory bytes
- All `MemoryStream` outputs are disposed in a `finally` block in the MSBuild task
- `Files.CopyIfStreamChanged` prevents unnecessary file writes (preserving downstream incrementality)
- Scanner processes all assemblies — framework JCW pre-compilation is future work (#10792)
Co-authored-by: Jonathan Peppers <jonathan.peppers@microsoft.com>1 parent c6bf63d commit 6ed93c7
File tree
19 files changed
+490
-452
lines changed- src
- Microsoft.Android.Sdk.TrimmableTypeMap
- Generator
- Scanner
- Xamarin.Android.Build.Tasks
- Tasks
- Tests/Xamarin.Android.Build.Tests/Tasks
- tests
- Microsoft.Android.Sdk.TrimmableTypeMap.IntegrationTests
- Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Generator
19 files changed
+490
-452
lines changedLines changed: 13 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
| 45 | + | |
| 46 | + | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 50 | + | |
| 51 | + | |
59 | 52 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 53 | + | |
| 54 | + | |
71 | 55 | | |
72 | | - | |
| 56 | + | |
73 | 57 | | |
74 | | - | |
75 | | - | |
| 58 | + | |
76 | 59 | | |
77 | 60 | | |
78 | 61 | | |
79 | 62 | | |
80 | 63 | | |
81 | | - | |
| 64 | + | |
82 | 65 | | |
83 | 66 | | |
84 | 67 | | |
| |||
91 | 74 | | |
92 | 75 | | |
93 | 76 | | |
94 | | - | |
| 77 | + | |
95 | 78 | | |
96 | 79 | | |
97 | | - | |
98 | | - | |
| 80 | + | |
99 | 81 | | |
100 | 82 | | |
| 83 | + | |
101 | 84 | | |
102 | 85 | | |
103 | 86 | | |
| |||
Lines changed: 0 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | 97 | | |
112 | 98 | | |
113 | 99 | | |
| |||
Lines changed: 0 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | 34 | | |
57 | 35 | | |
58 | 36 | | |
| |||
Lines changed: 0 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | 121 | | |
138 | 122 | | |
139 | 123 | | |
| |||
Lines changed: 0 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | 21 | | |
35 | 22 | | |
36 | 23 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
Lines changed: 3 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
21 | | - | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
| |||
35 | 33 | | |
36 | 34 | | |
37 | 35 | | |
38 | | - | |
| 36 | + | |
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
42 | 40 | | |
43 | 41 | | |
44 | | - | |
45 | 42 | | |
46 | 43 | | |
47 | | - | |
| 44 | + | |
48 | 45 | | |
49 | | - | |
50 | 46 | | |
51 | | - | |
52 | | - | |
| 47 | + | |
53 | 48 | | |
54 | 49 | | |
55 | 50 | | |
| |||
477 | 472 | | |
478 | 473 | | |
479 | 474 | | |
480 | | - | |
481 | 475 | | |
482 | 476 | | |
483 | 477 | | |
| |||
Lines changed: 4 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
| 83 | + | |
83 | 84 | | |
84 | | - | |
85 | | - | |
86 | | - | |
| 85 | + | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
91 | 90 | | |
92 | | - | |
93 | 91 | | |
94 | 92 | | |
95 | 93 | | |
96 | | - | |
97 | | - | |
98 | 94 | | |
99 | | - | |
100 | 95 | | |
101 | 96 | | |
102 | 97 | | |
| |||
Lines changed: 83 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
0 commit comments