Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #471 from sandyarmstrong/pr-sandy-iphonex
Browse files Browse the repository at this point in the history
iOS: Prefer iPhone X to iPhone 5s
  • Loading branch information
abock authored Jul 3, 2018
2 parents 9ac0fbb + eecfa7c commit 297febf
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -244,21 +245,20 @@ async Task InitializeSimulatorAsync (
simCheckerResult.Error);
}

foreach (var resultLine in simCheckerResult.Result.Split (Environment.NewLine.ToCharArray (), StringSplitOptions.RemoveEmptyEntries)) {
var line = resultLine.Trim ();
if (line.StartsWith ("UDID: ")) {
deviceUdid = line.Substring (6);
break;
}
}
var mtouchList = MTouchSdkTool.ReadFromXml (
new MemoryStream (Encoding.UTF8.GetBytes (simCheckerResult.Result)));

deviceUdid = MTouchSdkTool
.GetCompatibleDevices (mtouchList)
.FirstOrDefault ()
?.UDID;

if (deviceUdid == null)
throw new UserPresentableException (
Catalog.GetString (
"Unexpected error communicating with the Mac build host."),
Catalog.GetString (
"Confirm you have the same version of Xamarin Workbooks " +
"installed on both Mac and Windows."));
"Check your Xcode, Xamarin, and Visual Studio configurations."));
}

static Message CreateInstallAlert (
Expand Down
15 changes: 5 additions & 10 deletions Clients/Xamarin.Interactive.Client.Mac.SimChecker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Serialization;

using Xamarin.Interactive.Logging;
using Xamarin.Interactive.MTouch;
Expand Down Expand Up @@ -56,22 +58,15 @@ public static async Task Main (string[] args)
return;
}

IEnumerable<MTouchListSimXml.SimDeviceElement> compatibleDevices;
try {
compatibleDevices = MTouchSdkTool.GetCompatibleDevices (mtouchList);
// compatibleDevices = MTouchSdkTool.GetCompatibleDevices (mtouchList);
var x = new XmlSerializer (typeof (MTouchListSimXml));
x.Serialize (Console.Out, mtouchList);
} catch (Exception e) {
Console.Error.WriteLine (e.Message);
Environment.Exit (103); // Invalid mlaunch output
return;
}

var firstCompatibleDevice = compatibleDevices?.FirstOrDefault ();
if (firstCompatibleDevice == null) {
Console.Error.WriteLine ("No compatible simulator devices installed");
Environment.Exit (104); // No compatible sim listed by mlaunch
}

Console.WriteLine ($"UDID: {firstCompatibleDevice.UDID}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ sealed class iOSAgentProcess : IAgentProcess
{
const string TAG = nameof (iOSAgentProcess);

const string simulatorDevice = "iphone,64";

FilePath sdkRoot;
string defaultSdkVersion;
MTouchListSimXml.SimDeviceElement simulatorDevice;

NSTask mlaunchProcess;
NSObject terminatedObserver;
Expand Down Expand Up @@ -72,7 +71,7 @@ void StartSimulatorOnMainThread (IdentifyAgentRequest identifyAgentRequest)
"-sdkroot", sdkRoot,
"-launchsim", WorkbookApp.AppPath,
"-sdk", defaultSdkVersion,
"-device", simulatorDevice
"-device", $":v2:udid={simulatorDevice.UDID}"
};

mlaunchArguments.AddRange (identifyAgentRequest
Expand Down Expand Up @@ -147,7 +146,11 @@ async Task InitializeXcodeSdkAsync (IMessageService messageService)
.Select (r => r.Name.Replace ("iOS ", ""))
.LastOrDefault ();

if (defaultSdkVersion != null)
simulatorDevice = MTouchSdkTool
.GetCompatibleDevices (mtouchList)
.FirstOrDefault ();

if (simulatorDevice != null && defaultSdkVersion != null)
return;

throw new UserPresentableException (Catalog.GetString ("No iOS simulators found."));
Expand Down
16 changes: 15 additions & 1 deletion Clients/Xamarin.Interactive.MTouch/MTouchListSimXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Xml.Serialization;

namespace Xamarin.Interactive.MTouch
Expand Down Expand Up @@ -43,7 +44,7 @@ public class SimDeviceTypeElement
public bool Supports64Bits { get; set; }
}

public class SimDeviceElement
public class SimDeviceElement : IComparable<SimDeviceElement>
{
[XmlAttribute]
public string UDID { get; set; }
Expand All @@ -54,6 +55,19 @@ public class SimDeviceElement
public string SimRuntime { get; set; }

public string SimDeviceType { get; set; }

public int CompareTo (SimDeviceElement other)
{
if (other == null)
return -1;

// NOTE: This is copied from IPhoneSimulatorExecutionTargetGroup in VSmac.
//
// Treating iPhone X (ten) as iPhone 10 makes it so 'iPhone 7 < iPhone 8 < iPhone X'
var name = Name.Replace ("X", "10");
var otherName = other.Name.Replace ("X", "10");
return string.Compare (name, otherName, StringComparison.OrdinalIgnoreCase);
}
}

public string SdkRoot { get; set; }
Expand Down
16 changes: 12 additions & 4 deletions Clients/Xamarin.Interactive.MTouch/MTouchSdkTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,20 @@ await RunToolWithRetriesAsync (
mlaunchPath,
$"{sdkRootArgs} --listsim=\"{tmpFile}\"");

var x = new XmlSerializer (typeof (MTouchListSimXml));
var mtouchInfo = x.Deserialize (File.OpenRead (tmpFile)) as MTouchListSimXml;
var mtouchInfo = ReadFromXml (File.OpenRead (tmpFile));
File.Delete (tmpFile);

return mtouchInfo;
}

public static IEnumerable<MTouchListSimXml.SimDeviceElement> GetCompatibleDevices (MTouchListSimXml mtouchInfo)
public static MTouchListSimXml ReadFromXml (Stream xmlStream)
{
if (xmlStream == null)
throw new ArgumentNullException (nameof (xmlStream));
return new XmlSerializer (typeof (MTouchListSimXml)).Deserialize (xmlStream) as MTouchListSimXml;
}

public static List<MTouchListSimXml.SimDeviceElement> GetCompatibleDevices (MTouchListSimXml mtouchInfo)
{
if (mtouchInfo == null)
throw new ArgumentNullException (nameof (mtouchInfo));
Expand All @@ -150,13 +156,15 @@ await RunToolWithRetriesAsync (
var iOSRuntime = simInfo.SupportedRuntimes
.LastOrDefault (r => r.Name.StartsWith ("iOS", StringComparison.OrdinalIgnoreCase));

return
var devices =
from d in simInfo.AvailableDevices
where d.SimRuntime == iOSRuntime.Identifier
join t in simInfo.SupportedDeviceTypes on d.SimDeviceType equals t.Identifier
where t.ProductFamilyId == "IPhone"
where t.Supports64Bits
orderby d
select d;
return devices.ToList ();
}

/// <summary>
Expand Down

0 comments on commit 297febf

Please sign in to comment.