Skip to content

Commit

Permalink
merge: master to jdk12 branch (#428)
Browse files Browse the repository at this point in the history
* * simlauncher stopped working with ios13. switching to apple's simctl instead. (#402)

* * xcode11 fix. swift libraries not in /swift/ directory anymore but in swift-5.0. it is not a perfect fix but dirty workaround but it allows to use swift based frameworks with xcode11 (#405)

* Ios13 switch to simctl -- starting simulator (#410)

* * simlauncher stopped working with ios13. switching to apple's simctl instead.

* * added 'open Simulator' as simctl boot doesn't show the simulator and it has to be opened either using spotlight or open cmd

* #414 fix (libimobiledevice affected) (#416)

* updated to recent master of libimobiledevice which should fix the issue:
- removed libxml as it not required anymore by libplist v2.0.0
- libusbmuxd is picked from master, as version 1.1.0 is not available in releases
- added openssl as dependency as it is not part of MacOSX anymore (probably LibreSSL might be used)

* * fixed libmobiledevice to allow bypass ssl termination when required

* * libimobiledevice: bindings re-generated to recent version with ssl  passthrough and debug server

* * libimobiledevice: added handling of introduced time-out

* * libimobiledevice: added patch to provide timeout error through debugserver client

* * libimobiledevice: added patch to provide timeout error through debugserver client

* * libimobiledevice: removed unused debugserver api, fixed unix permissions for all other files

* * libimobiledevice: switched to use DebugServerClient to interact with GDB server, cleaned up some if lint warnings in AppLauncher and fixed to dev image lookup to allow using older one available (for example to use 13.0 with 13.1 device)

* * libimobiledevice: reverted back companion to byte[] parameter `count` argument. As usually byte array buffer contains less useful bytes than its length (this broke upload of app)

* update libimobiledevice lib

* * fixed broken reg-exp for version matching (development image lookup), added testcases for new code (#427)

* * fixed #408 by adding @MarshalsValue to toNative methods. Otherwise compiler was not able to resolve to native marshaller for enum and went to parent class where it picked up default marshaller from ValuedEnum. This results in type difference in case type of enum data is not int and caused following exception: (#409)

> java.lang.IllegalArgumentException: Duplicate @StructMember(1) in @PACKED structs (union in packed structs is not supported

* Add bool declarations for non Darwin systems (#425)
  • Loading branch information
dkimitsa authored and Tom-Ski committed Nov 8, 2019
1 parent 1d4987e commit f38636b
Show file tree
Hide file tree
Showing 84 changed files with 2,738 additions and 833 deletions.
Binary file removed compiler/bin/simlauncher
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,27 @@ public void processFile(Resource resource, File file, File destDir) throws IOExc
}
}

private boolean isValidSwiftDir(File swiftDir) {
// FIXME: simplest criteria is to check for one of core libs
return new File(swiftDir, "libswiftCore.dylib").exists();
}

private File getSwiftDir(String system) throws IOException {
// FIXME: dkimitsa: its a temporal for finding location of swift libraries
// FIXME: as in XCode 11 these are not under swift subdir anymore (but in swift-5.0).
// FIXME: while its a workaround and hardcode for specific swift version and proper way of
// FIXME: finding swift library location to be used
String[] versions = new String[]{"swift", "swift-5.0"};
String xcodePath = ToolchainUtil.findXcodePath();
for (String v: versions) {
File candidate = new File(xcodePath, "Toolchains/XcodeDefault.xctoolchain/usr/lib/" + v + "/" + system);
if (isValidSwiftDir(candidate))
return candidate;
}

throw new IOException("Failed to locate Swift Library directory!");
}

protected void copySwiftLibs(Collection<String> swiftLibraries, File targetDir, boolean strip) throws IOException {
String system = null;
if (config.getOs() == OS.ios) {
Expand All @@ -457,8 +478,7 @@ protected void copySwiftLibs(Collection<String> swiftLibraries, File targetDir,
} else {
system = "mac";
}
File swiftDir = new File(ToolchainUtil.findXcodePath(),
"Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/" + system);
File swiftDir = getSwiftDir(system);

// dkimitsa: there is hidden dependencies possible between swift libraries.
// e.g. one swiftLib has dependency that is not listed in included framework
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,20 @@ public DeviceFamily getFamily() {
public String getUdid() {
return udid;
}

public String getState() {
return getState(false);
}

public String getState(boolean fresh) {
if (fresh) {
// get fresh state by requesting a list
for (DeviceType t : listDeviceTypes()) {
if (udid.equals(t.udid))
return t.state;
}

}
return state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,12 @@
*/
package org.robovm.compiler.target.ios;

import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;

import com.dd.plist.NSArray;
import com.dd.plist.NSDictionary;
import com.dd.plist.NSNumber;
import com.dd.plist.NSObject;
import com.dd.plist.NSString;
import com.dd.plist.PropertyListParser;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -64,12 +51,23 @@
import org.robovm.libimobiledevice.util.AppLauncher;
import org.robovm.libimobiledevice.util.AppLauncherCallback;

import com.dd.plist.NSArray;
import com.dd.plist.NSDictionary;
import com.dd.plist.NSNumber;
import com.dd.plist.NSObject;
import com.dd.plist.NSString;
import com.dd.plist.PropertyListParser;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;

/**
* @author niklas
Expand Down Expand Up @@ -173,46 +171,7 @@ protected Launcher createLauncher(LaunchParameters launchParameters) throws IOEx
}

private Launcher createIOSSimLauncher(LaunchParameters launchParameters) throws IOException {
File dir = getAppDir();

String iosSimPath = new File(config.getHome().getBinDir(), "simlauncher").getAbsolutePath();;

IOSSimulatorLaunchParameters simulatorLaunchParameters = (IOSSimulatorLaunchParameters) launchParameters;

List<Object> args = new ArrayList<Object>();
args.add("-a=" + dir);
args.add("-u=" + simulatorLaunchParameters.getDeviceType().getUdid());

if (launchParameters.getEnvironment() != null) {
for (Entry<String, String> entry : launchParameters.getEnvironment().entrySet()) {
args.add("-e="+ entry.getKey() + "=" + entry.getValue() + "");
}
}

if (!launchParameters.getArguments().isEmpty()) {
for (String entry : launchParameters.getArguments()) {
args.add("-x=" + entry);
}
}

File xcodePath = new File(ToolchainUtil.findXcodePath());
Map<String, String> env = Collections.singletonMap("DEVELOPER_DIR", xcodePath.getAbsolutePath());

OutputStream out = System.out;
OutputStream err = System.err;
if (launchParameters.getStdoutFifo() != null) {
out = new OpenOnWriteFileOutputStream(launchParameters.getStdoutFifo());
}
if (launchParameters.getStderrFifo() != null) {
err = new OpenOnWriteFileOutputStream(launchParameters.getStderrFifo());
}

return new Executor(config.getLogger(), iosSimPath)
.args(args)
.wd(launchParameters.getWorkingDirectory())
.out(out).err(err).closeOutputStreams(true)
.inheritEnv(false)
.env(env);
return new SimLauncherProcess(config.getLogger(), getAppDir(), getBundleId(), (IOSSimulatorLaunchParameters) launchParameters);
}

private Launcher createIOSDevLauncher(LaunchParameters launchParameters)
Expand Down Expand Up @@ -557,7 +516,7 @@ private void codesignAppExtension(SigningIdentity identity, File entitlementsPLi
}

private void codesign(SigningIdentity identity, File entitlementsPList, boolean preserveMetadata, boolean verbose, boolean allocate, File target) throws IOException {
List<Object> args = new ArrayList<Object>();
List<Object> args = new ArrayList<>();
args.add("-f");
args.add("-s");
args.add(identity.getFingerprint());
Expand All @@ -583,7 +542,7 @@ private void codesign(SigningIdentity identity, File entitlementsPList, boolean
private void ldid(File entitlementsPList, File appDir) throws IOException {
File executableFile = new File(appDir, getExecutable());
config.getLogger().info("Pseudo-signing %s", executableFile.getAbsolutePath());
List<Object> args = new ArrayList<Object>();
List<Object> args = new ArrayList<>();
if (entitlementsPList != null) {
args.add("-S" + entitlementsPList.getAbsolutePath());
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
* Copyright (C) 2013 RoboVM AB
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
*/
package org.robovm.compiler.target.ios;

import org.apache.commons.exec.ExecuteException;
import org.apache.commons.io.output.NullOutputStream;
import org.robovm.compiler.log.ErrorOutputStream;
import org.robovm.compiler.log.Logger;
import org.robovm.compiler.target.Launcher;
import org.robovm.compiler.util.Executor;
import org.robovm.compiler.util.io.OpenOnWriteFileOutputStream;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;

/**
* {@link Process} implementation which runs an app on a simulator using an
* simctl
*/
public class SimLauncherProcess extends Process implements Launcher {
private final CountDownLatch countDownLatch = new CountDownLatch(1);
private final AtomicInteger threadCounter = new AtomicInteger();
private final Logger log;
private final DeviceType deviceType;
private final File wd;
private final String bundleId;
private final File appDir;
private final List<String> arguments;
private HashMap<String, String> env;
private Thread launcherThread;
private volatile boolean finished = false;
private volatile int exitCode = -1;
private OutputStream errStream;
private OutputStream outStream;

public SimLauncherProcess(Logger log, File appDir, String bundleId, IOSSimulatorLaunchParameters launchParameters) {
this.log = log;
deviceType = launchParameters.getDeviceType();
wd = launchParameters.getWorkingDirectory();
this.appDir = appDir;
this.bundleId = bundleId;
this.arguments = new ArrayList<>(launchParameters.getArguments());
if (launchParameters.getEnvironment() != null) {
this.env = new HashMap<>();
for (Map.Entry<String, String> entry : launchParameters.getEnvironment().entrySet()) {
env.put("SIMCTL_CHILD_" + entry.getKey(), entry.getValue());
}
}

outStream = System.out;
errStream = System.err;
if (launchParameters.getStdoutFifo() != null) {
outStream = new OpenOnWriteFileOutputStream(launchParameters.getStdoutFifo());
}
if (launchParameters.getStderrFifo() != null) {
errStream = new OpenOnWriteFileOutputStream(launchParameters.getStderrFifo());
}
}

@Override
public Process execAsync() throws IOException {
this.launcherThread = new Thread("SimLauncherThread-" + threadCounter.getAndIncrement()) {
@Override
public void run() {
try {
Executor executor;

if ("shutdown".equals(deviceType.getState(true).toLowerCase())) {
log.info("Booting simulator %s", deviceType.getUdid());
executor = new Executor(log, "xcrun");
executor.args("simctl", "boot", deviceType.getUdid());
executor.exec();
}

// bringing simulator to front (and showing it if it was just booted)
log.info("Showing simulator %s", deviceType.getUdid());
executor = new Executor(log, "open");
executor.args("-a", "Simulator", "--args", "-CurrentDeviceUDID", deviceType.getUdid());
executor.exec();

log.info("Deploying app %s to simulator %s", appDir.getAbsolutePath(),
deviceType.getUdid());
executor = new Executor(log, "xcrun");
executor.args("simctl", "install", deviceType.getUdid(), appDir.getAbsolutePath());
executor.exec();

log.info("Launching app %s on simulator %s", appDir.getAbsolutePath(),
deviceType.getUdid());
executor = new Executor(log, "xcrun");
List<Object> args = new ArrayList<>();
args.add("simctl");
args.add("launch");
args.add("--console");
args.add(deviceType.getUdid());
args.add(bundleId);
args.addAll(arguments);
executor.args(args);

if (env != null) {
executor.env(env);
}

executor.wd(wd).out(outStream).err(errStream).closeOutputStreams(true).inheritEnv(false);
executor.exec();
exitCode = 0;
} catch (ExecuteException e) {
exitCode = e.getExitValue();
} catch (Throwable t) {
log.error("AppLauncher failed with an exception:", t.getMessage());
t.printStackTrace(new PrintStream(new ErrorOutputStream(log), true));
} finally {
finished = true;
countDownLatch.countDown();
}
}
};
this.launcherThread.start();
return this;
}

@Override
public OutputStream getOutputStream() {
return new NullOutputStream();
}

@Override
public InputStream getInputStream() {
return waitInputStream;
}

@Override
public InputStream getErrorStream() {
return waitInputStream;
}

@Override
public int waitFor() throws InterruptedException {
countDownLatch.await();
return exitCode;
}

@Override
public int exitValue() {
if (!finished) {
throw new IllegalThreadStateException("Not terminated");
}
return exitCode;
}

@Override
public void destroy() {
try {
this.launcherThread.interrupt();
this.launcherThread.join();
} catch (InterruptedException ignored) {
}
}

final InputStream waitInputStream = new InputStream() {
@Override
public int read() throws IOException {
try {
countDownLatch.await();
} catch (InterruptedException e) {
throw new InterruptedIOException();
}
return -1;
}
};
}
Loading

0 comments on commit f38636b

Please sign in to comment.