CARVIEW |
Select Language
HTTP/2 200
date: Sun, 27 Jul 2025 09:26:35 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-repository-download: git clone https://github.com/dotnet/android.git
etag: W/"d0fe4e4ae1cb3585e3126c6d19e2ad0d"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=MTw0Wvko1WgzD9kfWikfYhmNPWkhMdgb5zxkyNqDxUm33t2XzemUOt%2FJkjiGYrWXw2T%2FOuwOgTKJxYeFU9eRgSsqHNKscWjJS28cbiTA9lzqOGE%2BqzqowcSygo1Tmc3v2W%2BV04MZnJCsbsDxXwLsQZyO%2FT80E7MmCMlZW6YwxGSCxS9ggfXaNjLbCm%2FTTYsvnOAnDBwIlk6VC%2BLYRkCOqObkUyhvOvHyptU5EusaNN2cmoXeQgjvW7As%2BQa18kK7W0y09b3wjnnZhm%2B4mt1g1A%3D%3D--vu51BbBPCTWbM6RC--%2BMKtjLIJ4fdZNcCxxueHeg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1932087662.1753608394; Path=/; Domain=github.com; Expires=Mon, 27 Jul 2026 09:26:34 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Mon, 27 Jul 2026 09:26:34 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: 8738:0A61:324075:43C67E:6885F0CA
[Xamarin.Android.Build.Tasks] no temp files in GenerateJavaStubs (#2535) · dotnet/android@c362fe5 · GitHub
Copy file name to clipboardExpand all lines: src/Xamarin.Android.Build.Tasks/Generator/Generator.cs
Copy file name to clipboardExpand all lines: src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Copy file name to clipboardExpand all lines: src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesigner.cs
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 555
Commit c362fe5
[Xamarin.Android.Build.Tasks] no temp files in GenerateJavaStubs (#2535)
Context: #2505
This is based on #2505, but I incorporated the Java.Interop changes
so that `<GenerateJavaStubs/>` uses no temp files at all.
In many places throughout the Xamarin.Android build, we have a
pattern of:
- Generate a temp file.
- Use `MonoAndroidHelper.CopyIfChanged()` to put the file in the
destination. This reads *both* files, doing a hash comparison
before deciding to write or not.
- Delete the temp file.
Sometimes the temp file is actually in `%TEMP%`, but other times we
append `.new` to the destination file. The case of `.new` can
collide if two builds are running at once (example caused by a known
VS for Mac issue).
Thinking about this, in cases with small files, we can make a simple
optimization:
- Generate the file in-memory.
- Use a new `MonoAndroidHelper.CopyStreamIfChanged()` method.
This has several benefits:
- We never write a file to disk when there are no changes.
- We don't have to *remember* to delete the file.
- The code, in general, is slightly simpler.
The only place we likely shouldn't use this new pattern, would be if
the file was huge.
~~ Changes ~~
I added new APIs for:
- `Files.HasStreamChanged()` - to compare a `Stream` in memory
- `Files.HasBytesChanged()` - to compare a `byte[]` in memory
- `Files.CopyIfStreamChanged()`
- `Files.CopyIfStringChanged()` - some cases we have a `string`
- `Files.CopyIfBytesChanged()` - this supports `string`
- `MonoAndroidHelper.CopyIfStreamChanged()`
- `MonoAndroidHelper.CopyIfStringChanged()`
- `MonoAndroidHelper.CopyIfBytesChanged()`
I changed the following MSBuild tasks, mostly to test out the new
behavior:
- `<GenerateResourceDesigner/>` was using a `.new` file.
- `<GenerateJavaStubs/>` was using temp files in many places.
I was able to fix up all of these.
- There is now a `ManifestDocument.Save(Stream)` overload.
- `Generator` now uses `CopyIfStreamChanged()` and a new
`GetDestinationPath()` method from Java.Interop. It reuses a
single `MemoryStream`, and I moved the `<GenerateJavaSource/>`
method into `<CreateJavaSources/>` for simplicity.
I made other general refactoring in `<GenerateJavaStubs/>`:
- Since we don't have to worry about deleting a `temp_map_file`, we
can return earlier if `Generator.CreateJavaSources()` fails.
- A `GetResource<T>()` method, cleans up the places reading from
`@(EmbeddedResource)` files. I also changed it up to properly
`Dispose()` things.
- A `save` anonymous method/delegate should just be a
`SaveResource()` *regular* method.
- A few places were calling `Path.GetFullPath()` unnecessarily.
Since this method accesses the file system, we should skip it
unless the full path is actually needed.
- Avoid using `StringWriter` and `string.Format()`.
- Use capacity and `StringComparer.Ordinal` when creating
dictionaries: https://www.dotnetperls.com/dictionary-stringcomparer
- Preallocate `MemoryStream` with `java_types.Length * 32`
I also added some tests for the new APIs in `MonoAndroidHelper`.
~~ Results ~~
I did three test runs, because I was getting varying times for
`<GenerateJavaStubs/>`. This is the Xamarin.Forms integration
project in this repo:
Before (Clean Build):
1. 1433 ms GenerateJavaStubs 1 calls
2. 1594 ms GenerateJavaStubs 1 calls
3. 1353 ms GenerateJavaStubs 1 calls
After (Clean Build):
1. 1201 ms GenerateJavaStubs 1 calls
2. 1137 ms GenerateJavaStubs 1 calls
3. 1136 ms GenerateJavaStubs 1 calls
Before (Incremental):
1. 1184 ms GenerateJavaStubs 1 calls
2. 1181 ms GenerateJavaStubs 1 calls
3. 1172 ms GenerateJavaStubs 1 calls
After (Incremental):
1. 1035 ms GenerateJavaStubs 1 calls
2. 1049 ms GenerateJavaStubs 1 calls
3. 1036 ms GenerateJavaStubs 1 calls
`<GenerateJavaStubs/>` is now about 250ms faster on initial build and
150ms faster on incremental builds.
I could not see a difference in `<GenerateResourceDesigner/>`, likely
since it wrote only a single temp file.
Next steps would be to make changes in other MSBuild tasks as well.1 parent b333490 commit c362fe5Copy full SHA for c362fe5
File tree
Expand file treeCollapse file tree
8 files changed
+373
-144
lines changedFilter options
- src/Xamarin.Android.Build.Tasks
- Generator
- Tasks
- Tests/Xamarin.Android.Build.Tests
- Utilities
- Utilities
Expand file treeCollapse file tree
8 files changed
+373
-144
lines changedsrc/Xamarin.Android.Build.Tasks/Generator/Generator.cs
Copy file name to clipboardExpand all lines: src/Xamarin.Android.Build.Tasks/Generator/Generator.cs+39-36Lines changed: 39 additions & 36 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
7 | 7 |
| |
8 | 8 |
| |
9 | 9 |
| |
| 10 | + | |
10 | 11 |
| |
11 | 12 |
| |
12 | 13 |
| |
| |||
15 | 16 |
| |
16 | 17 |
| |
17 | 18 |
| |
18 |
| - | |
19 |
| - | |
20 |
| - | |
21 |
| - | |
22 |
| - | |
23 |
| - | |
24 |
| - | |
25 |
| - | |
26 |
| - | |
27 |
| - | |
28 |
| - | |
29 |
| - | |
30 |
| - | |
31 |
| - | |
32 |
| - | |
33 |
| - | |
34 |
| - | |
35 |
| - | |
36 |
| - | |
37 |
| - | |
38 |
| - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
39 | 24 |
| |
40 |
| - | |
41 |
| - | |
42 |
| - | |
43 |
| - | |
44 |
| - | |
45 |
| - | |
46 |
| - | |
47 |
| - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
48 | 34 |
| |
49 |
| - | |
50 |
| - | |
51 |
| - | |
52 |
| - | |
53 |
| - | |
54 |
| - | |
55 |
| - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
56 | 58 |
| |
| 59 | + | |
57 | 60 |
| |
58 | 61 |
| |
59 | 62 |
|
src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs
Copy file name to clipboardExpand all lines: src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs+91-98Lines changed: 91 additions & 98 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
76 | 76 |
| |
77 | 77 |
| |
78 | 78 |
| |
79 |
| - | |
80 |
| - | |
| 79 | + | |
81 | 80 |
| |
82 | 81 |
| |
83 | 82 |
| |
| |||
99 | 98 |
| |
100 | 99 |
| |
101 | 100 |
| |
102 |
| - | |
103 |
| - | |
104 | 101 |
| |
105 | 102 |
| |
106 | 103 |
| |
| |||
111 | 108 |
| |
112 | 109 |
| |
113 | 110 |
| |
114 |
| - | |
| 111 | + | |
| 112 | + | |
115 | 113 |
| |
116 |
| - | |
| 114 | + | |
117 | 115 |
| |
118 | 116 |
| |
119 | 117 |
| |
| |||
130 | 128 |
| |
131 | 129 |
| |
132 | 130 |
| |
133 |
| - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
134 | 134 |
| |
135 | 135 |
| |
136 |
| - | |
| 136 | + | |
137 | 137 |
| |
138 | 138 |
| |
139 |
| - | |
| 139 | + | |
140 | 140 |
| |
141 | 141 |
| |
142 | 142 |
| |
143 | 143 |
| |
144 |
| - | |
145 |
| - | |
| 144 | + | |
| 145 | + | |
146 | 146 |
| |
147 | 147 |
| |
148 |
| - | |
149 |
| - | |
150 |
| - | |
151 |
| - | |
152 |
| - | |
153 |
| - | |
154 |
| - | |
155 |
| - | |
156 |
| - | |
157 |
| - | |
158 |
| - | |
159 |
| - | |
160 |
| - | |
161 |
| - | |
162 |
| - | |
163 |
| - | |
164 |
| - | |
165 |
| - | |
166 |
| - | |
167 |
| - | |
168 |
| - | |
169 |
| - | |
170 |
| - | |
171 |
| - | |
172 |
| - | |
173 |
| - | |
174 |
| - | |
175 |
| - | |
176 |
| - | |
177 |
| - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
178 | 196 |
| |
179 |
| - | |
180 |
| - | |
181 |
| - | |
182 |
| - | |
183 |
| - | |
184 |
| - | |
185 |
| - | |
186 |
| - | |
187 |
| - | |
188 |
| - | |
189 |
| - | |
190 |
| - | |
191 |
| - | |
192 |
| - | |
193 |
| - | |
194 |
| - | |
195 |
| - | |
196 |
| - | |
197 |
| - | |
198 |
| - | |
199 |
| - | |
200 |
| - | |
201 | 197 |
| |
202 |
| - | |
| 198 | + | |
| 199 | + | |
203 | 200 |
| |
204 | 201 |
| |
205 | 202 |
| |
| |||
219 | 216 |
| |
220 | 217 |
| |
221 | 218 |
| |
222 |
| - | |
223 |
| - | |
| 219 | + | |
| 220 | + | |
224 | 221 |
| |
225 |
| - | |
226 |
| - | |
227 |
| - | |
228 |
| - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
229 | 225 |
| |
230 | 226 |
| |
231 | 227 |
| |
232 |
| - | |
| 228 | + | |
233 | 229 |
| |
234 | 230 |
| |
235 |
| - | |
236 |
| - | |
237 |
| - | |
238 |
| - | |
239 |
| - | |
240 |
| - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
241 | 234 |
| |
242 | 235 |
| |
243 | 236 |
| |
244 |
| - | |
245 |
| - | |
246 |
| - | |
247 |
| - | |
248 |
| - | |
249 |
| - | |
250 |
| - | |
251 |
| - | |
252 |
| - | |
253 |
| - | |
254 | 237 |
| |
255 | 238 |
| |
256 | 239 |
| |
| |||
262 | 245 |
| |
263 | 246 |
| |
264 | 247 |
| |
265 |
| - | |
| 248 | + | |
266 | 249 |
| |
267 |
| - | |
| 250 | + | |
268 | 251 |
| |
269 | 252 |
| |
270 | 253 |
| |
271 | 254 |
| |
272 |
| - | |
273 |
| - | |
274 |
| - | |
275 |
| - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
276 | 270 |
| |
277 | 271 |
| |
278 | 272 |
| |
| |||
287 | 281 |
| |
288 | 282 |
| |
289 | 283 |
| |
290 |
| - | |
291 |
| - | |
292 |
| - | |
293 |
| - | |
294 |
| - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
295 | 288 |
| |
296 | 289 |
| |
297 | 290 |
|
src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesigner.cs
Copy file name to clipboardExpand all lines: src/Xamarin.Android.Build.Tasks/Tasks/GenerateResourceDesigner.cs+2-6Lines changed: 2 additions & 6 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
239 | 239 |
| |
240 | 240 |
| |
241 | 241 |
| |
242 |
| - | |
243 |
| - | |
244 |
| - | |
245 |
| - | |
246 |
| - | |
247 |
| - | |
| 242 | + | |
| 243 | + | |
248 | 244 |
| |
249 | 245 |
| |
250 | 246 |
| |
|
You can’t perform that action at this time.
0 commit comments