Skip to content

Commit

Permalink
Arch will now be taken into account when finding a DeviceType to prev…
Browse files Browse the repository at this point in the history
…ent that

a 32-bit only simulator is used when launching in 64-bit mode. Refactored
DeviceType lookup and moved the code used by the Gradle and Maven plugins to
the core project. (fixes #691)
  • Loading branch information
ntherning committed Jan 13, 2015
1 parent 6714b5a commit 8032cc3
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 42 deletions.
Binary file modified bin/ios-sim
Binary file not shown.
15 changes: 9 additions & 6 deletions compiler/src/main/java/org/robovm/compiler/AppCompiler.java
Expand Up @@ -582,13 +582,16 @@ public static void main(String[] args) throws IOException {
LaunchParameters launchParameters = compiler.config.getTarget().createLaunchParameters();
if (launchParameters instanceof IOSSimulatorLaunchParameters) {
IOSSimulatorLaunchParameters simParams = (IOSSimulatorLaunchParameters) launchParameters;
DeviceType type = DeviceType.getDeviceType(compiler.config.getHome(),
compiler.config.getIosDeviceType());
if (type == null) {
simParams.setDeviceType(DeviceType.getBestDeviceType(compiler.config.getHome()));
} else {
simParams.setDeviceType(type);
String deviceName = null;
String sdkVersion = null;
if (compiler.config.getIosDeviceType() != null) {
String[] parts = compiler.config.getIosDeviceType().split("[:;, ]+");
deviceName = parts[0].trim();
sdkVersion = parts.length > 1 ? parts[1].trim() : null;
}
DeviceType type = DeviceType.getBestDeviceType(compiler.config.getHome(),
compiler.config.getArch(), null, deviceName, sdkVersion);
simParams.setDeviceType(type);
}
launchParameters.setArguments(runArgs);
compiler.launch(launchParameters);
Expand Down
106 changes: 70 additions & 36 deletions compiler/src/main/java/org/robovm/compiler/target/ios/DeviceType.java
Expand Up @@ -21,9 +21,12 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.robovm.compiler.config.Arch;
import org.robovm.compiler.config.Config.Home;
import org.robovm.compiler.log.Logger;
import org.robovm.compiler.util.Executor;
Expand All @@ -45,10 +48,12 @@ public static enum DeviceFamily {

private final String deviceName;
private final SDK sdk;
private final Set<Arch> archs;

public DeviceType(String deviceName, SDK sdk) {
DeviceType(String deviceName, SDK sdk, Set<Arch> archs) {
this.deviceName = deviceName;
this.sdk = sdk;
this.archs = archs;
}

public String getDeviceName() {
Expand All @@ -59,6 +64,10 @@ public SDK getSdk() {
return sdk;
}

public Set<Arch> getArchs() {
return Collections.unmodifiableSet(archs);
}

/**
* @return id as understood by ios-sim, concatentation of type and sdk
* version
Expand All @@ -75,7 +84,7 @@ public String getSimpleDeviceTypeId() {
}

public String getSimpleDeviceName() {
return deviceName.substring("com.apple.CoreSimulator.SimDeviceType.".length());
return deviceName.substring(PREFIX.length());
}

public DeviceFamily getFamily() {
Expand All @@ -101,17 +110,49 @@ public static List<DeviceType> listDeviceTypes(Home home) {
String[] tokens = deviceTypeId.split(",");
tokens[0] = tokens[0].trim();
tokens[1] = tokens[1].trim();
tokens[2] = tokens[2].trim();
SDK sdk = sdkMap.get(tokens[1]);
if (sdk != null) {
types.add(new DeviceType(tokens[0], sdk));
Set<Arch> archs = new HashSet<>();
for (String s : tokens[2].replaceAll("[\\(\\)]", "").split(" ")) {
switch (s) {
case "i386":
archs.add(Arch.x86);
break;
case "x86_64":
archs.add(Arch.x86_64);
break;
}
}
types.add(new DeviceType(tokens[0], sdk, archs));
}
}
return types;
} catch (IOException e) {
return Collections.<DeviceType> emptyList();
throw new RuntimeException(e);
}
}


private static List<DeviceType> filter(List<DeviceType> deviceTypes, Arch arch,
DeviceFamily family, String deviceName, String sdkVersion) {

deviceName = deviceName == null ? null : deviceName.toLowerCase();

List<DeviceType> result = new ArrayList<>();
for (DeviceType type : deviceTypes) {
if (arch == null || type.getArchs().contains(arch)) {
if (family == null || family == type.getFamily()) {
if (deviceName == null || type.getSimpleDeviceName().toLowerCase().contains(deviceName)) {
if (sdkVersion == null || type.getSdk().getVersion().equals(sdkVersion)) {
result.add(type);
}
}
}
}
}
return result;
}

public static List<String> getSimpleDeviceTypeIds(Home home) {
List<String> result = new ArrayList<>();
for (DeviceType type : listDeviceTypes(home)) {
Expand All @@ -136,47 +177,40 @@ public static DeviceType getDeviceType(Home home, String deviceTypeId) {
return null;
}

/**
* @return the iPhone {@link DeviceType} with the highest version number
*/
public static DeviceType getBestDeviceType(Home home) {
DeviceType best = null;
for (DeviceType type : listDeviceTypes(home)) {
if (type.getFamily() != DeviceFamily.iPhone) {
continue;
}
if (best == null) {
best = type;
} else {
int bestVersion = (best.getSdk().getMajor() << 8) | (best.getSdk().getMinor());
int typeVersion = (type.getSdk().getMajor() << 8) | (type.getSdk().getMinor());
if (bestVersion < typeVersion) {
best = type;
}
}
}
return best;
return getBestDeviceType(home, null, null, null, null);
}

public static DeviceType getBestDeviceType(Home home, DeviceFamily family) {
return getBestDeviceType(home, null, family, null, null);
}

/**
* @return the iPhone {@link DeviceType} with the highest version number
* Returns the best {@link DeviceType} matching the parameters. If multiple
* device types match the parameters the first one with the highest SDK
* number will be returned. If no device name and no {@link DeviceFamily} is
* specified this method will default to {@link DeviceFamily#iPhone}.
*/
public static DeviceType getBestDeviceType(Home home, DeviceFamily family) {
public static DeviceType getBestDeviceType(Home home, Arch arch, DeviceFamily family,
String deviceName, String sdkVersion) {

if (deviceName == null && family == null) {
family = DeviceFamily.iPhone;
}

DeviceType best = null;
for (DeviceType type : listDeviceTypes(home)) {
if (type.getFamily() != family) {
continue;
}
for (DeviceType type : filter(listDeviceTypes(home), arch, family, deviceName, sdkVersion)) {
if (best == null) {
best = type;
} else {
int bestVersion = (best.getSdk().getMajor() << 8) | (best.getSdk().getMinor());
int typeVersion = (type.getSdk().getMajor() << 8) | (type.getSdk().getMinor());
if (bestVersion < typeVersion) {
best = type;
}
} else if (type.getSdk().compareTo(best.getSdk()) > 0) {
best = type;
}
}
if (best == null) {
throw new IllegalArgumentException("Unable to find a matching device "
+ "[arch=" + arch + ", family=" + family
+ ", name=" + deviceName + ", sdk=" + sdkVersion + "]");
}
return best;
}
}

0 comments on commit 8032cc3

Please sign in to comment.