Skip to content

Commit

Permalink
Use ios-sim from classpath to avoid needing a Home instance whenever …
Browse files Browse the repository at this point in the history
…we need

to invoke it. (fixes #962)
  • Loading branch information
ntherning committed May 4, 2015
1 parent 0fdb717 commit 984901a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
9 changes: 4 additions & 5 deletions compiler/src/main/java/org/robovm/compiler/AppCompiler.java
Expand Up @@ -52,7 +52,6 @@
import org.robovm.compiler.clazz.Path;
import org.robovm.compiler.config.Arch;
import org.robovm.compiler.config.Config;
import org.robovm.compiler.config.Config.Home;
import org.robovm.compiler.config.Config.TargetType;
import org.robovm.compiler.config.OS;
import org.robovm.compiler.config.Resource;
Expand Down Expand Up @@ -543,7 +542,7 @@ public static void main(String[] args) throws IOException {
} else if ("-sdk".equals(args[i])) {
builder.iosSdkVersion(args[++i]);
} else if ("-printdevicetypes".equals(args[i])) {
printDeviceTypesAndExit(Home.find());
printDeviceTypesAndExit();
} else if ("-devicetype".equals(args[i])) {
builder.iosDeviceType(args[++i]);
} else if ("-createipa".equals(args[i])) {
Expand Down Expand Up @@ -638,7 +637,7 @@ public static void main(String[] args) throws IOException {
deviceName = parts[0].trim();
sdkVersion = parts.length > 1 ? parts[1].trim() : null;
}
DeviceType type = DeviceType.getBestDeviceType(compiler.config.getHome(),
DeviceType type = DeviceType.getBestDeviceType(
compiler.config.getArch(), null, deviceName, sdkVersion);
simParams.setDeviceType(type);
}
Expand Down Expand Up @@ -731,8 +730,8 @@ public void launchAsyncCleanup() {
}
}

private static void printDeviceTypesAndExit(Home home) throws IOException {
List<DeviceType> types = DeviceType.listDeviceTypes(home);
private static void printDeviceTypesAndExit() throws IOException {
List<DeviceType> types = DeviceType.listDeviceTypes();
for (DeviceType type : types) {
System.out.println(type.getSimpleDeviceTypeId());
}
Expand Down
Expand Up @@ -16,7 +16,6 @@
*/
package org.robovm.compiler.target.ios;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -27,7 +26,6 @@
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 Down Expand Up @@ -95,9 +93,9 @@ public DeviceFamily getFamily() {
}
}

public static List<DeviceType> listDeviceTypes(Home home) {
public static List<DeviceType> listDeviceTypes() {
try {
String capture = new Executor(Logger.NULL_LOGGER, new File(home.getBinDir(), "ios-sim")).args(
String capture = new Executor(Logger.NULL_LOGGER, IOSTarget.getIosSimPath()).args(
"showdevicetypes").execCapture();
List<DeviceType> types = new ArrayList<DeviceType>();
String[] deviceTypeIds = capture.split("\n");
Expand Down Expand Up @@ -168,16 +166,16 @@ private static List<DeviceType> filter(List<DeviceType> deviceTypes, Arch arch,
return result;
}

public static List<String> getSimpleDeviceTypeIds(Home home) {
public static List<String> getSimpleDeviceTypeIds() {
List<String> result = new ArrayList<>();
for (DeviceType type : listDeviceTypes(home)) {
for (DeviceType type : listDeviceTypes()) {
result.add(type.getSimpleDeviceTypeId());
}
return result;
}

public static DeviceType getDeviceType(Home home, String deviceTypeId) {
List<DeviceType> types = listDeviceTypes(home);
public static DeviceType getDeviceType(String deviceTypeId) {
List<DeviceType> types = listDeviceTypes();
if (deviceTypeId == null) {
return null;
}
Expand All @@ -192,12 +190,12 @@ public static DeviceType getDeviceType(Home home, String deviceTypeId) {
return null;
}

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

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

/**
Expand All @@ -206,15 +204,15 @@ public static DeviceType getBestDeviceType(Home home, DeviceFamily family) {
* 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, Arch arch, DeviceFamily family,
public static DeviceType getBestDeviceType(Arch arch, DeviceFamily family,
String deviceName, String sdkVersion) {

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

DeviceType best = null;
for (DeviceType type : filter(listDeviceTypes(home), arch, family, deviceName, sdkVersion)) {
for (DeviceType type : filter(listDeviceTypes(), arch, family, deviceName, sdkVersion)) {
if (best == null) {
best = type;
} else if (type.getSdk().compareTo(best.getSdk()) > 0) {
Expand Down
Expand Up @@ -80,6 +80,7 @@
*
*/
public class IOSTarget extends AbstractTarget {
private static File iosSimPath;

private Arch arch;
private SDK sdk;
Expand Down Expand Up @@ -113,6 +114,21 @@ public static boolean isDeviceArch(Arch arch) {
return arch == Arch.thumbv7 || arch == Arch.arm64;
}

public static synchronized File getIosSimPath() {
if (iosSimPath == null) {
try {
File path = File.createTempFile("ios-sim", "");
FileUtils.copyURLToFile(IOSTarget.class.getResource("/ios-sim"), path);
path.setExecutable(true);
path.deleteOnExit();
iosSimPath = path;
} catch (IOException e) {
throw new Error(e);
}
}
return iosSimPath;
}

public List<SDK> getSDKs() {
if (isSimulatorArch(arch)) {
return SDK.listSimulatorSDKs();
Expand Down
Binary file added compiler/src/main/resources/ios-sim
Binary file not shown.

0 comments on commit 984901a

Please sign in to comment.