Skip to content

Commit dcbdca5

Browse files
emafGitHub Actions Autoformatterrolfbjarne
authored
[test] Add incremental build test (#23666)
Co-authored-by: GitHub Actions Autoformatter <github-actions-autoformatter@xamarin.com> Co-authored-by: Rolf Bjarne Kvinge <rolf@xamarin.com>
1 parent 1adc3a3 commit dcbdca5

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

tests/common/AppDelegate.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public override bool FinishedLaunching (UIApplication application, NSDictionary
4343

4444
PostFinishedLaunching ();
4545

46+
#if INCLUDED_ADDITIONAL_CODE
47+
Console.WriteLine ("Additional code is included.");
48+
#endif
49+
4650
return true;
4751
}
4852
}

tests/dotnet/IncrementalTestApp/AppDelegate.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ static int Main (string [] args)
99
{
1010
GC.KeepAlive (typeof (NSObject)); // prevent linking away the platform assembly
1111

12+
#if INCLUDED_ADDITIONAL_CODE
13+
Console.WriteLine ("Additional code is included.");
14+
#endif
15+
1216
Console.WriteLine (Environment.GetEnvironmentVariable ("MAGIC_WORD"));
1317

1418
return args.Length;

tests/dotnet/IncrementalTestApp/shared.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
<ExcludeNUnitLiteReference>true</ExcludeNUnitLiteReference>
1010
<ExcludeTouchUnitReference>true</ExcludeTouchUnitReference>
11+
12+
<DefineConstants>$(DefineConstants);$(AdditionalDefineConstants)</DefineConstants>
1113
</PropertyGroup>
1214

1315
<Import Project="../../common/shared-dotnet.csproj" />

tests/dotnet/UnitTests/IncrementalBuildTest.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,5 +187,60 @@ public void Interpreter (ApplePlatform platform, string runtimeIdentifiers)
187187
Assert.That (File.GetLastWriteTimeUtc (appExecutable), Is.EqualTo (appExecutableTimestamp), "Modified B");
188188
}
189189

190+
[Test]
191+
[TestCase (ApplePlatform.iOS, "iossimulator-arm64", true)]
192+
[TestCase (ApplePlatform.iOS, "iossimulator-arm64", false)]
193+
public void CodeChangeSkipsTargets (ApplePlatform platform, string runtimeIdentifiers, bool interpreterEnabled)
194+
{
195+
CodeChangeSkipsTargetsImpl (platform, runtimeIdentifiers, interpreterEnabled);
196+
}
197+
198+
[Test]
199+
[Category ("RemoteWindows")]
200+
[TestCase (ApplePlatform.iOS, "iossimulator-arm64", true)]
201+
[TestCase (ApplePlatform.iOS, "iossimulator-arm64", false)]
202+
public void CodeChangeSkipsTargetsOnRemoteWindows (ApplePlatform platform, string runtimeIdentifiers, bool interpreterEnabled)
203+
{
204+
Configuration.IgnoreIfNotOnWindows ();
205+
CodeChangeSkipsTargetsImpl (platform, runtimeIdentifiers, interpreterEnabled);
206+
}
207+
208+
void CodeChangeSkipsTargetsImpl (ApplePlatform platform, string runtimeIdentifiers, bool interpreterEnabled)
209+
{
210+
var project = "IncrementalTestApp";
211+
Configuration.IgnoreIfIgnoredPlatform (platform);
212+
Configuration.AssertRuntimeIdentifiersAvailable (platform, runtimeIdentifiers);
213+
214+
var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
215+
Clean (project_path);
216+
var properties = GetDefaultProperties (runtimeIdentifiers);
217+
218+
properties ["UseInterpreter"] = interpreterEnabled.ToString ();
219+
220+
// Build the first time
221+
var rv = DotNet.AssertBuild (project_path, properties);
222+
var allTargets = BinLog.GetAllTargets (rv.BinLogPath);
223+
224+
// Verify these targets executed on first build
225+
AssertTargetExecuted (allTargets, "_CreatePkgInfo", "A");
226+
AssertTargetExecuted (allTargets, "_CompileNativeExecutable", "A");
227+
AssertTargetExecuted (allTargets, "_LinkNativeExecutable", "A");
228+
229+
// Make a code change
230+
properties ["AdditionalDefineConstants"] = "INCLUDED_ADDITIONAL_CODE";
231+
232+
// Build again after modifying the helper C# file
233+
rv = DotNet.AssertBuild (project_path, properties);
234+
allTargets = BinLog.GetAllTargets (rv.BinLogPath);
235+
236+
// Verify these targets did NOT execute on incremental build after C# change
237+
AssertTargetNotExecuted (allTargets, "_CreatePkgInfo", "B");
238+
AssertTargetNotExecuted (allTargets, "_CompileNativeExecutable", "B");
239+
if (interpreterEnabled) {
240+
AssertTargetNotExecuted (allTargets, "_LinkNativeExecutable", "B");
241+
} else {
242+
AssertTargetExecuted (allTargets, "_LinkNativeExecutable", "B");
243+
}
244+
}
190245
}
191246
}

0 commit comments

Comments
 (0)