Commit 970da9e
[Xamarin.Android.Build.Tasks] fix incremental builds for Xamarin.Forms projects (#2088)
@StephaneDelcroix noticed a build performance problem when building
Xamarin.Forms projects:
- Build
- Build again with no changes
- Slow targets such as `_UpdateAndroidResgen` and
`_GenerateJavaStubs` run again!
The cause appeared to be this:
Building target "_UpdateAndroidResgen" completely.
Input file "obj/Debug/res/layout/tabbar.xml" is newer than output file "obj/Debug/R.cs.flag".
I modified the `CheckTimestamps()` test to replicate this issue:
- Added Xamarin.Forms NuGet packages
- Added `Tabbar.axml` from the Xamarin.Forms template
This surfaced several problems with timestamps and Xamarin.Android
building incrementally.
~~ Problem 1 ~~
In the `_GenerateJavaStubs` target, the `<ConvertResourcesCases/>`
MSBuild task is not supplied an `AndroidConversionFlagFile`. It uses
this file to compare timestamps and decide if XML files need to be
fixed up or not.
Supplying `$(_AndroidResgenFlagFile)` seemed to be the way to go here,
since `_UpdateAndroidResgen` runs right before this task. It also
solves the original problem from the `Tabbar.axml` file.
I also realized we should be using a "stamp" file for the
`_GenerateJavaStubs` MSBuild target, in general.
This gives us several benefits:
- `<ConvertResourcesCases/>` has a proper
`AndroidConversionFlagFile` it can use for checking timestamps
- The `Outputs` of the target are drastically simplified, which may
help performance in MSBuild evaluating if the target should run
- It is likely more precise/correct.
So I added a new file in `$(IntermediateOutputPath)`,
`obj\Debug\_javastubs.stamp` we use to determine if
`_GenerateJavaStubs` should run.
I also tried to do things "the right way", such as:
- Adding the stamp file to the `@(FileWrites)` item group
- Made sure the file is deleted during a `Clean`
After these changes, two instances of `<ConvertResourcesCases/>` were
*still* fighting each other. They would always run and update the
timestamps on one file, causing the other one to run.
`ConvertResourcesCases` runs twice:
- In the `_UpdateAndroidResgen` target
- In the `_GenerateJavaStubs` target
But these are both working with the same files, so in the second case,
we need to make sure `_GenerateJavaStubs` updates the timestamp on the
*first* flag file so the target doesn't run every time.
~~ Problem 2 ~~
Timestamps of Xamarin.Forms assemblies in `obj\Debug\linksrc` were
out of date!
I updated the `_CopyIntermediateAssemblies` target to update the
timestamps of all files within this directory. It did not appear to
be doing it correctly, and was only running `<Touch/>` on a subset of
assemblies.
~~ Problem 3 ~~
After fixing Problem 2, the next problem I noticed were `*.pdb` and
`*.mdb` files in `obj\Debug\linksrc` were out of date!
The problem here was a call to `<Touch />`:
<Touch Files="@(_DebugFilesCopiedToLinkerSrc)" />
The `@(_DebugFilesCopiedToLinkerSrc)` did not appear to contain any
items!
I updated the `_CopyPdbFiles` and `_CopyMdbFiles` targets to use the
correct item groups.
~~ Problem 4 ~~
Lastly, after fixing the previous three problems, the timestamps of
output assemblies in `obj\Release\android\assets` were not correct
for `Release` builds.
I had made a change for this in the past, which was making `Debug`
builds work correctly:
#2028
At the time I wrote #2028, since the test wasn't using Xamarin.Forms,
I did not see the problem occurring in `Release` mode. It *does*
occur if you are using NuGet packages.
I replicated what I changed in the `_LinkAssembliesNoShrink` target,
and also renamed the item groups to be unique:
- `_LinkAssembliesNoShrinkFiles`
- `_LinkAssembliesShrinkFiles`
~~ Other changes ~~
The `CheckTimestamps()` test also was verifying timestamps in
`$(OutputPath)` such as `bin\Debug`.
It appears the core MSBuild targets are leaving timestamps as-is in
the `CopyFilesToOutputDirectory` and `_CopyFilesMarkedCopyLocal`
targets. Assemblies from Xamarin.Forms NuGet are out of date here, but
I don't think we should do anything, since the core MSBuild targets
are doing this.
For now, I removed the checks for `$(OutputPath)` in this test, and
cleaned up the test a bit.
Update `Files.ExtractAll()` so that the timestamps of extracted files
are set to "now", in order to fix some failing unit tests on macOS.1 parent 07d4563 commit 970da9e
File tree
3 files changed
+65
-18
lines changed- src/Xamarin.Android.Build.Tasks
- Tests/Xamarin.Android.Build.Tests
- Utilities
3 files changed
+65
-18
lines changedLines changed: 39 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
262 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
263 | 289 | | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
271 | 296 | | |
272 | 297 | | |
273 | 298 | | |
274 | 299 | | |
275 | | - | |
276 | 300 | | |
277 | 301 | | |
278 | 302 | | |
| |||
291 | 315 | | |
292 | 316 | | |
293 | 317 | | |
294 | | - | |
295 | | - | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
296 | 325 | | |
297 | 326 | | |
298 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
248 | 251 | | |
249 | 252 | | |
250 | 253 | | |
| |||
Lines changed: 23 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1952 | 1952 | | |
1953 | 1953 | | |
1954 | 1954 | | |
1955 | | - | |
1956 | | - | |
1957 | 1955 | | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
1958 | 1960 | | |
1959 | 1961 | | |
1960 | 1962 | | |
| |||
2028 | 2030 | | |
2029 | 2031 | | |
2030 | 2032 | | |
2031 | | - | |
| 2033 | + | |
2032 | 2034 | | |
2033 | 2035 | | |
2034 | 2036 | | |
| |||
2050 | 2052 | | |
2051 | 2053 | | |
2052 | 2054 | | |
2053 | | - | |
| 2055 | + | |
2054 | 2056 | | |
2055 | 2057 | | |
2056 | 2058 | | |
| |||
2079 | 2081 | | |
2080 | 2082 | | |
2081 | 2083 | | |
2082 | | - | |
| 2084 | + | |
2083 | 2085 | | |
2084 | | - | |
| 2086 | + | |
2085 | 2087 | | |
2086 | 2088 | | |
2087 | 2089 | | |
| |||
2116 | 2118 | | |
2117 | 2119 | | |
2118 | 2120 | | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
2119 | 2127 | | |
2120 | 2128 | | |
2121 | 2129 | | |
| |||
2198 | 2206 | | |
2199 | 2207 | | |
2200 | 2208 | | |
2201 | | - | |
| 2209 | + | |
2202 | 2210 | | |
2203 | 2211 | | |
2204 | 2212 | | |
| |||
2225 | 2233 | | |
2226 | 2234 | | |
2227 | 2235 | | |
2228 | | - | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
| 2240 | + | |
| 2241 | + | |
| 2242 | + | |
2229 | 2243 | | |
2230 | 2244 | | |
2231 | 2245 | | |
| |||
3057 | 3071 | | |
3058 | 3072 | | |
3059 | 3073 | | |
| 3074 | + | |
3060 | 3075 | | |
3061 | 3076 | | |
3062 | 3077 | | |
| |||
0 commit comments