Commit d7e3a23
[Xamarin.Android.Build.Tasks] set timestamps on intermediate files (#1693)
When reviewing our build times, I was testing the following scenario:
- `msbuild Droid.csproj /t:Install /bl:first.binlog`
- `msbuild Droid.csproj /t:Install /bl:second.binlog`
In theory, the "second" build should be very fast and basically not
do anything. Unfortunately that was not the case.
In my example, I saw build logs such as:
Target _LinkAssembliesNoShrink
Building target "_LinkAssembliesNoShrink" partially, because some output files are out of date with respect to their input files.
[ResolvedUserAssemblies: Input=C:\Users\myuser\.nuget\packages\xamarin.forms\3.0.0.482510\lib\MonoAndroid10\FormsViewGroup.dll, Output=obj\Debug\android\assets\FormsViewGroup.dll] Input file is newer than output file.
[ResolvedUserAssemblies: Input=C:\Users\myuser\.nuget\packages\xamarin.forms\3.0.0.482510\lib\MonoAndroid10\Xamarin.Forms.Core.dll, Output=obj\Debug\android\assets\Xamarin.Forms.Core.dll] Input file is newer than output file.
[ResolvedUserAssemblies: Input=C:\Users\myuser\.nuget\packages\xamarin.forms\3.0.0.482510\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll, Output=obj\Debug\android\assets\Xamarin.Forms.Platform.Android.dll] Input file is newer than output file.
[ResolvedUserAssemblies: Input=C:\Users\myuser\.nuget\packages\xamarin.forms\3.0.0.482510\lib\MonoAndroid10\Xamarin.Forms.Platform.dll, Output=obj\Debug\android\assets\Xamarin.Forms.Platform.dll] Input file is newer than output file.
[ResolvedUserAssemblies: Input=C:\Users\myuser\.nuget\packages\xamarin.forms\3.0.0.482510\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll, Output=obj\Debug\android\assets\Xamarin.Forms.Xaml.dll] Input file is newer than output file.
LinkAssemblies
Looking at the `LinkAssemblies` MSBuild task, I didn't see anything
that would be setting the timestamps on copied files.
For timestamps to be correct, we should either:
- Use `MonoAndroidHelper.SetLastAccessAndWriteTimeUtc()` in C#
- Use the `<Touch/>` MSBuild task after using the `<Copy />`
MSBuild task
This lead me to write a `CheckTimestamps()` unit test that does the
following:
- Store `DateTime.UtcNow` in a variable (and subtract one second for
good measure)
- Build an app
- Make sure nothing in `bin` or `obj` are older than the start time
This uncovered even more out of date files such as:
- `mono.android.jar`
- Assemblies in `obj/Debug/linksrc` or `$(MonoAndroidLinkerInputDir)`
Fixes made in various places:
- `<LinkAssemblies/>` task needed to use
`MonoAndroidHelper.SetLastAccessAndWriteTimeUtc()` everywhere
`MonoAndroidHelper.CopyIfChanged()` is used
- The `_CopyIntermediateAssemblies` target appeared to have a typo.
It was running a `<Touch/>` on `@(ResolvedUserAssemblies)` where
it looked like it should be `@(ResolvedAssemblies)` from the
previous `<Copy />`
- The `_AddStaticResources` target needed a `<Touch/>` for
`mono.android.jar`
This fix should improve our incremental build times dramatically, as
these timestamps caused other targets to run that slow things down.
Finally, improve the `ResolveSdkTiming()` test to reduce random
failures:
Xamarin.Android.Build.Tests.ResolveSdksTaskTests.ResolveSdkTiming
Task should not take more than 1 second to run.
Expected: less than or equal to 00:00:01
But was: 00:00:01.9140742
To improve this, I changed:
- The timeout to 2 seconds
- Added `[NonParallelizable]`, so the test should not have to compete
for machine resources as much with other tests1 parent f500582 commit d7e3a23
File tree
4 files changed
+43
-7
lines changed- src/Xamarin.Android.Build.Tasks
- Tasks
- Tests/Xamarin.Android.Build.Tests
4 files changed
+43
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
171 | 174 | | |
172 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
173 | 179 | | |
174 | 180 | | |
175 | 181 | | |
176 | | - | |
177 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
178 | 188 | | |
179 | 189 | | |
180 | 190 | | |
| |||
Lines changed: 25 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
123 | 148 | | |
124 | 149 | | |
125 | 150 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1704 | 1704 | | |
1705 | 1705 | | |
1706 | 1706 | | |
| 1707 | + | |
1707 | 1708 | | |
1708 | 1709 | | |
1709 | 1710 | | |
| |||
1730 | 1731 | | |
1731 | 1732 | | |
1732 | 1733 | | |
1733 | | - | |
| 1734 | + | |
1734 | 1735 | | |
1735 | 1736 | | |
1736 | 1737 | | |
| |||
0 commit comments