Skip to content

Commit

Permalink
feature(cli): allow simulator_uuid for [ios], fix(cli): set group on …
Browse files Browse the repository at this point in the history
…child pid to parent group, fix(api): fix buffers too account for value already being a buffer in serialize method
  • Loading branch information
heapwolf committed Apr 15, 2024
1 parent d571c19 commit f57b6cf
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 106 deletions.
4 changes: 4 additions & 0 deletions api/internal/serialize.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import Buffer from '../buffer.js'

export default function serialize (value) {
if (!value || typeof value !== 'object') {
return value
}

return map(value, (value) => {
if (Buffer.isBuffer(value)) return value

if (typeof value[Symbol.serialize] === 'function') {
return value[Symbol.serialize]()
}
Expand Down
215 changes: 113 additions & 102 deletions src/cli/cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1094,125 +1094,129 @@ int runApp (const Path& path, const String& args) {

void runIOSSimulator (const Path& path, Map& settings) {
#ifndef _WIN32
checkIosSimulatorDeviceAvailability(settings["ios_simulator_device"]);

String deviceType;
StringStream listDeviceTypesCommand;
listDeviceTypesCommand
<< "xcrun"
<< " simctl"
<< " list devicetypes";

auto rListDeviceTypes = exec(listDeviceTypesCommand.str().c_str());
if (rListDeviceTypes.exitCode != 0) {
log("failed to list device types using \"" + listDeviceTypesCommand.str() + "\"");
if (rListDeviceTypes.output.size() > 0) {
log(rListDeviceTypes.output);
}
exit(rListDeviceTypes.exitCode);
}

std::regex reDeviceType(settings["ios_simulator_device"] + "\\s\\((com.apple.CoreSimulator.SimDeviceType.(?:.+))\\)");
std::smatch match;
String uuid;
bool booted = false;

if (std::regex_search(rListDeviceTypes.output, match, reDeviceType)) {
deviceType = match.str(1);
log("simulator device type: " + deviceType);
if (settings.count("ios_simulator_uuid") > 0) {
uuid = settings["ios_simulator_uuid"];
} else {
auto rListDevices = exec("xcrun simctl list devicetypes | grep iPhone");
log(
"failed to find device type: " + settings["ios_simulator_device"] + ". "
"Please provide correct device name for the \"ios_simulator_device\". "
"The list of available devices:\n" + rListDevices.output
);
if (rListDevices.output.size() > 0) {
log(rListDevices.output);
}
exit(rListDevices.exitCode);
}
checkIosSimulatorDeviceAvailability(settings["ios_simulator_device"]);

StringStream listDevicesCommand;
listDevicesCommand
<< "xcrun"
<< " simctl"
<< " list devices available";
auto rListDevices = exec(listDevicesCommand.str().c_str());
if (rListDevices.exitCode != 0) {
log("failed to list available devices using \"" + listDevicesCommand.str() + "\"");
if (rListDevices.output.size() > 0) {
log(rListDevices.output);
}
exit(rListDevices.exitCode);
}

auto iosSimulatorDeviceSuffix = settings["ios_simulator_device"];
std::replace(iosSimulatorDeviceSuffix.begin(), iosSimulatorDeviceSuffix.end(), ' ', '_');
std::regex reSocketSDKDevice("SocketSimulator_" + iosSimulatorDeviceSuffix + "\\s\\((.+)\\)\\s\\((.+)\\)");
String deviceType;
StringStream listDeviceTypesCommand;
listDeviceTypesCommand
<< "xcrun"
<< " simctl"
<< " list devicetypes";

String uuid;
bool booted = false;
auto rListDeviceTypes = exec(listDeviceTypesCommand.str().c_str());
if (rListDeviceTypes.exitCode != 0) {
log("failed to list device types using \"" + listDeviceTypesCommand.str() + "\"");
if (rListDeviceTypes.output.size() > 0) {
log(rListDeviceTypes.output);
}
exit(rListDeviceTypes.exitCode);
}

if (std::regex_search(rListDevices.output, match, reSocketSDKDevice)) {
uuid = match.str(1);
booted = match.str(2).find("Booted") != String::npos;
std::regex reDeviceType(settings["ios_simulator_device"] + "\\s\\((com.apple.CoreSimulator.SimDeviceType.(?:.+))\\)");
std::smatch match;

log("found Socket simulator VM for " + settings["ios_simulator_device"] + " with uuid: " + uuid);
if (booted) {
log("Socket simulator VM is booted");
if (std::regex_search(rListDeviceTypes.output, match, reDeviceType)) {
deviceType = match.str(1);
log("simulator device type: " + deviceType);
} else {
log("Socket simulator VM is not booted");
auto rListDevices = exec("xcrun simctl list devicetypes");
log(
"failed to find device type: " + settings["ios_simulator_device"] + ". "
"Please provide correct device name for the \"ios_simulator_device\". "
"The list of available devices:\n" + rListDevices.output
);
if (rListDevices.output.size() > 0) {
log(rListDevices.output);
}
exit(rListDevices.exitCode);
}
} else {
log("creating a new iOS simulator VM for " + settings["ios_simulator_device"]);

StringStream listRuntimesCommand;
listRuntimesCommand
StringStream listDevicesCommand;
listDevicesCommand
<< "xcrun"
<< " simctl"
<< " list runtimes available";
auto rListRuntimes = exec(listRuntimesCommand.str().c_str());
if (rListRuntimes.exitCode != 0) {
log("failed to list available runtimes using \"" + listRuntimesCommand.str() + "\"");
if (rListRuntimes.output.size() > 0) {
log(rListRuntimes.output);
}
exit(rListRuntimes.exitCode);
}
auto const runtimes = split(rListRuntimes.output, '\n');
String runtime;
// TODO: improve iOS version detection
for (auto it = runtimes.rbegin(); it != runtimes.rend(); ++it) {
if (it->find("iOS") != String::npos) {
runtime = trim(*it);
log("found runtime: " + runtime);
break;
<< " list devices available";
auto rListDevices = exec(listDevicesCommand.str().c_str());
if (rListDevices.exitCode != 0) {
log("failed to list available devices using \"" + listDevicesCommand.str() + "\"");
if (rListDevices.output.size() > 0) {
log(rListDevices.output);
}
exit(rListDevices.exitCode);
}

std::regex reRuntime(R"(com.apple.CoreSimulator.SimRuntime.iOS(?:.*))");
std::smatch matchRuntime;
String runtimeId;
auto iosSimulatorDeviceSuffix = settings["ios_simulator_device"];
std::replace(iosSimulatorDeviceSuffix.begin(), iosSimulatorDeviceSuffix.end(), ' ', '_');
std::regex reSocketSDKDevice("SocketSimulator_" + iosSimulatorDeviceSuffix + "\\s\\((.+)\\)\\s\\((.+)\\)");

if (std::regex_search(runtime, matchRuntime, reRuntime)) {
runtimeId = matchRuntime.str(0);
}
if (std::regex_search(rListDevices.output, match, reSocketSDKDevice)) {
uuid = match.str(1);
booted = match.str(2).find("Booted") != String::npos;

log("found Socket simulator VM for " + settings["ios_simulator_device"] + " with uuid: " + uuid);
if (booted) {
log("Socket simulator VM is booted");
} else {
log("Socket simulator VM is not booted");
}
} else {
log("creating a new iOS simulator VM for " + settings["ios_simulator_device"]);

StringStream listRuntimesCommand;
listRuntimesCommand
<< "xcrun"
<< " simctl"
<< " list runtimes available";
auto rListRuntimes = exec(listRuntimesCommand.str().c_str());
if (rListRuntimes.exitCode != 0) {
log("failed to list available runtimes using \"" + listRuntimesCommand.str() + "\"");
if (rListRuntimes.output.size() > 0) {
log(rListRuntimes.output);
}
exit(rListRuntimes.exitCode);
}
auto const runtimes = split(rListRuntimes.output, '\n');
String runtime;
// TODO: improve iOS version detection
for (auto it = runtimes.rbegin(); it != runtimes.rend(); ++it) {
if (it->find("iOS") != String::npos) {
runtime = trim(*it);
log("found runtime: " + runtime);
break;
}
}

std::regex reRuntime(R"(com.apple.CoreSimulator.SimRuntime.iOS(?:.*))");
std::smatch matchRuntime;
String runtimeId;

if (std::regex_search(runtime, matchRuntime, reRuntime)) {
runtimeId = matchRuntime.str(0);
}

StringStream createSimulatorCommand;
createSimulatorCommand
<< "xcrun simctl"
<< " create SocketSimulator_" + iosSimulatorDeviceSuffix
<< " " << deviceType
<< " " << runtimeId;
StringStream createSimulatorCommand;
createSimulatorCommand
<< "xcrun simctl"
<< " create SocketSimulator_" + iosSimulatorDeviceSuffix
<< " " << deviceType
<< " " << runtimeId;

auto rCreateSimulator = exec(createSimulatorCommand.str().c_str());
if (rCreateSimulator.exitCode != 0) {
log("unable to create simulator VM");
if (rCreateSimulator.output.size() > 0) {
log(rCreateSimulator.output);
auto rCreateSimulator = exec(createSimulatorCommand.str().c_str());
if (rCreateSimulator.exitCode != 0) {
log("unable to create simulator VM");
if (rCreateSimulator.output.size() > 0) {
log(rCreateSimulator.output);
}
exit(rCreateSimulator.exitCode);
}
exit(rCreateSimulator.exitCode);
uuid = rCreateSimulator.output;
}
uuid = rCreateSimulator.output;
}

if (!booted) {
Expand Down Expand Up @@ -5085,7 +5089,9 @@ int main (const int argc, const char* argv[]) {

if (flagBuildForIOS) {
if (flagBuildForSimulator) {
checkIosSimulatorDeviceAvailability(settings["ios_simulator_device"]);
if (settings.count("ios_simulator_uuid") < 0) {
checkIosSimulatorDeviceAvailability(settings["ios_simulator_device"]);
}
log("building for iOS Simulator");
} else {
log("building for iOS");
Expand Down Expand Up @@ -5166,9 +5172,14 @@ int main (const int argc, const char* argv[]) {
// building, signing, bundling, archiving, noterizing, and uploading.
//
StringStream archiveCommand;
String deviceIdentity = settings.count("ios_simulator_uuid") > 0
? "id=" + settings["ios_simulator_uuid"]
: "name=" + settings["ios_simulator_device"];

String destination = flagBuildForSimulator
? "platform=iOS Simulator,OS=latest,name=" + settings["ios_simulator_device"]
? "platform=iOS Simulator,OS=latest," + deviceIdentity
: "generic/platform=iOS";

String deviceType;

// TODO: should be "iPhone Distribution: <name/provisioning specifier>"?
Expand Down
4 changes: 2 additions & 2 deletions src/cli/templates.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@ constexpr auto gXCodeProject = R"ASCII(// !$*UTF8*$!
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "{{ios_provisioning_specifier}}";
SWIFT_EMIT_LOC_STRINGS = YES;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
WARNING_CFLAGS = (
"$(inherited)",
"-Wno-nullability-completeness",
Expand Down Expand Up @@ -1113,7 +1113,7 @@ constexpr auto gXCodeProject = R"ASCII(// !$*UTF8*$!
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "{{ios_provisioning_specifier}}";
SWIFT_EMIT_LOC_STRINGS = YES;
TARGETED_DEVICE_FAMILY = 1;
TARGETED_DEVICE_FAMILY = "1,2";
WARNING_CFLAGS = (
"$(inherited)",
"-Wno-nullability-completeness",
Expand Down
3 changes: 2 additions & 1 deletion src/process/unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ Process::id_type Process::open(const std::function<int()> &function) noexcept {
return pid;
}

setpgid(pid, 0);
closed = false;
id = pid;

if (pid > 0) {
setpgid(pid, getpgid(0));

auto thread = std::thread([this] {
int code = 0;
waitpid(this->id, &code, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/window/apple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1315,7 +1315,7 @@ - (void) webView: (WKWebView*) webView
}

//
// We don't support hiddenInset because the same thing can be accomplished by specifying windowControlOffsets
// results in a hidden titlebar with inset/offset window controls
//
else if (opts.titlebarStyle == "hiddenInset") {
style |= NSWindowStyleMaskFullSizeContentView;
Expand Down

0 comments on commit f57b6cf

Please sign in to comment.