Skip to content

Commit

Permalink
Specify devices for Gauntlet via JSON file instead
Browse files Browse the repository at this point in the history
This works around weird command-line parsing bugs in Gauntlet for the device list when device IDs are IP addresses with port numbers.
  • Loading branch information
hach-que committed Jan 1, 2025
1 parent 5db345f commit 7c9f35d
Showing 1 changed file with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ await writer.WriteAgentNodeAsync(
};
if (!string.IsNullOrWhiteSpace(projectPackage.settings.BootTest.DeviceId))
{
arguments.Add($"-device={projectPackage.settings.TargetPlatform}:{projectPackage.settings.BootTest.DeviceId}");
arguments.Add($"-devices=$(TempPath)/{assembledProjectName}/DeviceList.json");
}
if (projectPackage.settings.BootTest.GauntletArguments != null)
{
Expand Down Expand Up @@ -424,6 +424,8 @@ public async Task<int> ExecuteBuildGraphNodeAsync(
var projectDirectory = runtimeSettings["ProjectDirectory"];
var stagingDirectory = runtimeSettings["StagingDirectory"];

var hasDeviceId = runtimeSettings.TryGetValue("DeviceId", out var deviceId) && !string.IsNullOrWhiteSpace(deviceId);

if (stage == "PrePackage" && targetPlatform == "IOS")
{
// We have to create Intermediate/ProjectFilesIOS so that Info.Template.plist gets generated
Expand Down Expand Up @@ -572,6 +574,27 @@ public async Task<int> ExecuteBuildGraphNodeAsync(
return 0;
}

if (stage == "PreGauntlet" && hasDeviceId)
{
// Write out the DeviceList.json file. Gauntlet doesn't handle platform + IP address properly on the command
// line (via -device), so we need to write this file and get it to load the device list from JSON instead.
var deviceListPath = Path.Combine(runtimeSettings["ProjectDirectory"], "DeviceList.json");
_logger.LogInformation($"Writing out device list file to: {deviceListPath}");

// We assume device IDs and platform names don't have quotes or other things that need JSON escaping in them.
File.WriteAllText(
deviceListPath,
$$"""
[
{
"Name": "{{deviceId}}",
"Address": "{{deviceId}}",
"Platform": "{{targetPlatform}}"
}
]
""");
}

if (stage == "PreGauntlet" && targetPlatform == "IOS")
{
var enginePath = runtimeSettings["EnginePath"];
Expand Down Expand Up @@ -608,16 +631,14 @@ public async Task<int> ExecuteBuildGraphNodeAsync(
}
}

if (stage == "PreGauntlet" && targetPlatform == "Android")
if (stage == "PreGauntlet" && targetPlatform == "Android" && hasDeviceId)
{
var deviceId = runtimeSettings["DeviceId"];

var adbFilePath = Path.Combine(
Environment.GetEnvironmentVariable("ANDROID_HOME")!,
"platform-tools",
"adb.exe");

if (deviceId.Contains("._tcp.", StringComparison.Ordinal))
if (deviceId!.Contains("._tcp.", StringComparison.Ordinal))
{
// Pre-connect via mDNS. This is necessary because if we're not already connected to the device when Gauntlet runs, it will append :5555 to the address, which we don't want for mDNS.
_logger.LogInformation($"Checking mDNS service is running...");
Expand Down

0 comments on commit 7c9f35d

Please sign in to comment.