Skip to content
17 changes: 12 additions & 5 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/GetAvailableDevices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ public override bool Execute ()
System.Threading.Tasks.Task.WhenAll (new [] { devicectlTask, simctlTask }).Wait (cancellationTokenSource.Token);

var devices = new List<DeviceInfo> ();
devices.AddRange (devicectlTask.Result);
devices.AddRange (simctlTask.Result);
var simulators = simctlTask.Result.ToList ();
var simulatorUdids = new HashSet<string> (simulators.Select (d => d.Udid), StringComparer.OrdinalIgnoreCase);
foreach (var device in devicectlTask.Result) {
if (!simulatorUdids.Contains (device.Udid))
devices.Add (device);
}
Comment thread
rolfbjarne marked this conversation as resolved.
Resolved
devices.AddRange (simulators);

// filter to the current platform
foreach (var d in devices.Where (d => !d.Discarded && d.Platform != Platform))
Expand Down Expand Up @@ -133,15 +138,17 @@ public override bool Execute ()

class DeviceInfo {
public ITaskItem Item { get; set; }
public string Udid { get; set; }
public IEnumerable<string> RuntimeIdentifiers { get; set; }
Comment thread
rolfbjarne marked this conversation as resolved.
Resolved
public ApplePlatform Platform { get; set; }
public IPhoneDeviceType DeviceType { get; set; }
public Version MinimumOSVersion { get; set; }
public string DiscardedReason { get; set; }
public bool Discarded { get => !string.IsNullOrEmpty (DiscardedReason); }
public DeviceInfo (ITaskItem item, IEnumerable<string> runtimeIdentifiers, ApplePlatform platform, IPhoneDeviceType deviceType, Version minimumOSVersion, string discardedReason)
public DeviceInfo (ITaskItem item, string udid, IEnumerable<string> runtimeIdentifiers, ApplePlatform platform, IPhoneDeviceType deviceType, Version minimumOSVersion, string discardedReason)
{
Item = item;
Udid = udid;
RuntimeIdentifiers = runtimeIdentifiers;
Platform = platform;
DeviceType = deviceType;
Expand Down Expand Up @@ -252,7 +259,7 @@ async System.Threading.Tasks.Task<IEnumerable<DeviceInfo>> RunDeviceCtlAsync ()

Version.TryParse (device.OSVersion, out var minimumOSVersion);

rv.Add (new DeviceInfo (item, [runtimeIdentifier], platform, deviceType, minimumOSVersion ?? new Version (0, 0), discardedReason));
rv.Add (new DeviceInfo (item, udid, [runtimeIdentifier], platform, deviceType, minimumOSVersion ?? new Version (0, 0), discardedReason));
}
return rv;
}
Expand Down Expand Up @@ -390,7 +397,7 @@ async System.Threading.Tasks.Task<IEnumerable<DeviceInfo>> RunSimCtlAsync ()
}
}

rv.Add (new DeviceInfo (item, runtimeIdentifiers, platform, deviceType, minimumOSVersion, discardedReason));
rv.Add (new DeviceInfo (item, device.Udid, runtimeIdentifiers, platform, deviceType, minimumOSVersion, discardedReason));
}
return rv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@ public void DeviceCtl1 ()
}

[Test]
public void DeviceCtlDuplicateSimulator ()
{
var platform = ApplePlatform.iOS;
var task = CreateTask (platform, SIMCTL_JSON_1, DEVICECTL_JSON_1.Replace ("00008003-012301230123ABCD", "3F1C114D-FC3D-481A-9CA1-499EE1339390"));
Comment thread
rolfbjarne marked this conversation as resolved.
Resolved
Assert.That (task.Execute (), Is.True, "Task should have succeeded.");

Assert.Multiple (() => {
Assert.That (task.Devices.Count, Is.EqualTo (4), "Devices count mismatch.");
Assert.That (task.Devices.Count (d => d.ItemSpec == "3F1C114D-FC3D-481A-9CA1-499EE1339390"), Is.EqualTo (1), "Duplicate simulator count mismatch.");
Assert.That (task.Devices.Single (d => d.ItemSpec == "3F1C114D-FC3D-481A-9CA1-499EE1339390").GetMetadata ("Type"), Is.EqualTo ("Simulator"), "Simulator metadata mismatch.");
});
}

public void DeviceCtlJsonVersion5 ()
{
var platform = ApplePlatform.iOS;
Expand Down
Loading