Skip to content

Commit 631c046

Browse files
jonpryoratsushieno
authored andcommitted
[Xamarin.Android.Build.Tasks] Reduce rebuild cascades (#549)
Context: 518e57c The scenario: rebuild `Xamarin.Android.Build.Tasks.csproj`: $ xbuild src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj *If nothing has changed*, the expectation is that this should be reasonably quick, because *nothing has changed*. Unfortunately, that's not the case; a rebuild could take upwards of 30sec on my local machine, becaues of rebuild cascades: Target CoreCompile needs to be built as input file 'Xamarin.Android.Tools.BootstrapTasks/GenerateProfile.cs' is newer than output file 'obj/Debug/Xamarin.Android.Tools.BootstrapTasks.dll' Target _BuildJNIEnv needs to be built as input file '../../bin/BuildDebug/jnienv-gen.exe' is newer than output file 'Android.Runtime/JNIEnv.g.cs' Target CoreCompile needs to be built as input file 'Android.Runtime/JNIEnv.g.cs' is newer than output file 'obj/Debug/android-25/Mono.Android.dll' Target _GenerateMonoAndroidDex18 needs to be built as input file '../../bin/Debug/lib/xbuild-frameworks/MonoAndroid/v7.1/mono.android.jar' is newer than output file '../../bin/Debug/lib/xbuild-frameworks/MonoAndroid/v7.1/mono.android.dex' Target _CopyExtractedMultiDexJar needs to be built as input file '$HOME/android-toolchain/sdk/extras/android/m2repository/com/android/support/multidex/1.0.1/multidex-1.0.1.aar' is newer than output file '../../bin/Debug/lib/xbuild/Xamarin/Android/../../../mandroid/android-support-multidex.jar' ...and if I'm *really* unlucky: Target _BuildUnlessCached needs to be built as input file '.../xamarin-android/external/mono/autogen.sh' is newer than output file '../../bin/Debug//lib/xbuild-frameworks/MonoAndroid/v1.0/FSharp.Core.dll' ...as that means an `external/mono` rebuild (!). Most of these are due to missing `<Touch/>` task use, to ensure that a created/generated file is newer than the `Inputs` of the associated target. The `<GenerateProfile/>` task is slightly more complicated: in that case, we only want the file timestamp to change if the file contents have changed. Alter the `GenerateProfile.Execute()` logic to perform a content diff before writing to the file, resulting in a new timestamp. Finally, fix `GenerateJavaCallableWrappers` target use from `Mono.Android.csproj` by providing a "real" value for `$(JavaCallableWrapperAbsAssembly)` so that the `GenerateJavaCallableWrappers` target's `Inputs` and `Outputs` reference valid (existing) files. The previous value used a `$(JavaCallableWrapperOutputPathAbs)` property, which doesn't appear to have been defined anywhere, and thus was `""`. Performing these changes reduces my typical "no change" `Xamarin.Android.Build.Tasks.csproj` rebuild time from ~30sec down to a more reasonable ~10sec, which is much better (though more than I'd personally like).
1 parent ac0d65c commit 631c046

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

build-tools/mono-runtimes/mono-runtimes.targets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
WorkingDirectory="$(IntermediateOutputPath)\%(_MonoRuntime.Identity)"
296296
/>
297297
<Touch
298-
Files="@(_RuntimeSource);@(_ProfilerSource);@(_MonoPosixHelperSource);@(_BclProfileItems)"
298+
Files="@(_RuntimeSource);@(_ProfilerSource);@(_MonoPosixHelperSource);@(_BclProfileItems);@(_MonoBtlsSource)"
299299
/>
300300
</Target>
301301
<Target Name="_InstallRuntimes"
@@ -459,6 +459,9 @@
459459
SourceFiles="@(_FSharp)"
460460
DestinationFolder="$(_BclFrameworkDir)"
461461
/>
462+
<Touch
463+
Files="@(_FSharp->'$(_BclFrameworkDir)\%(Filename)%(Extension)')"
464+
/>
462465
<Touch
463466
Files="@(_BclInstalledItem)"
464467
/>

src/Mono.Android/Mono.Android.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@
315315
</PropertyGroup>
316316
<Import Project="Mono.Android.targets" />
317317
<PropertyGroup>
318-
<JavaCallableWrapperAbsAssembly>$(JavaCallableWrapperOutputPathAbs)$(AssemblyName).dll</JavaCallableWrapperAbsAssembly>
318+
<JavaCallableWrapperAbsAssembly>$([System.IO.Path]::GetFullPath ('$(OutputPath)$(AssemblyName).dll'))</JavaCallableWrapperAbsAssembly>
319319
<JavaCallableWrapperAfterTargets>CoreBuild</JavaCallableWrapperAfterTargets>
320320
</PropertyGroup>
321321
<Import Project="..\..\build-tools\scripts\JavaCallableWrappers.targets" />

src/Mono.Android/Mono.Android.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<Exec
4141
Command="$(ManagedRuntime) ..\..\bin\Build$(Configuration)\jnienv-gen.exe -o Android.Runtime\JNIEnv.g.cs --use-java-interop"
4242
/>
43+
<Touch Files="Android.Runtime\JNIEnv.g.cs" />
4344
</Target>
4445
<ItemGroup>
4546
<_AndroidProfile Include="Profiles\api-*.xml.in" />
@@ -128,6 +129,7 @@
128129
SourceFiles="$(IntermediateOutputPath)__dex\classes.dex"
129130
DestinationFiles="$(OutputPath)mono.android.dex"
130131
/>
132+
<Touch Files="$(OutputPath)mono.android.dex" />
131133
<RemoveDir
132134
Directories="$(IntermediateOutputPath)__dex"
133135
/>

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,11 @@
143143
<Copy
144144
SourceFiles="$(IntermediateOutputPath)multidex-aar\classes.jar"
145145
DestinationFiles="$(OutputPath)..\..\..\mandroid\android-support-multidex.jar" />
146+
<Touch Files="$(OutputPath)..\..\..\mandroid\android-support-multidex.jar" />
146147
<Copy
147148
SourceFiles="$(_SupportLicense)"
148149
DestinationFiles="$(OutputPath)..\..\..\mandroid\MULTIDEX_JAR_LICENSE" />
150+
<Touch Files="$(OutputPath)..\..\..\mandroid\MULTIDEX_JAR_LICENSE" />
149151
</Target>
150152

151153
<ItemGroup>

src/Xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks/GenerateProfile.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ public override bool Execute ()
3838
sb.AppendLine ("\t}");
3939
sb.AppendLine ("}");
4040

41-
File.WriteAllText (OutputFile.ItemSpec, sb.ToString ());
41+
var newContents = sb.ToString ();
42+
var curContents = "";
43+
if (File.Exists (OutputFile.ItemSpec)) {
44+
curContents = File.ReadAllText (OutputFile.ItemSpec);
45+
}
46+
if (newContents != curContents) {
47+
File.WriteAllText (OutputFile.ItemSpec, sb.ToString ());
48+
}
4249

4350
return !Log.HasLoggedErrors;
4451
}

0 commit comments

Comments
 (0)