Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
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; }
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 @@ -121,6 +121,20 @@ public void DeviceCtlJsonVersion5 ()
});
}

[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.");
});
}

[Test]
public void SimCtl1 ()
{
Expand Down
Loading