From f57b6cf59ac0e9fd43886426dc0006a06f6e2590 Mon Sep 17 00:00:00 2001 From: heapwolf Date: Mon, 15 Apr 2024 21:33:01 +0200 Subject: [PATCH] feature(cli): allow simulator_uuid for [ios], fix(cli): set group on child pid to parent group, fix(api): fix buffers too account for value already being a buffer in serialize method --- api/internal/serialize.js | 4 + src/cli/cli.cc | 215 ++++++++++++++++++++------------------ src/cli/templates.hh | 4 +- src/process/unix.cc | 3 +- src/window/apple.mm | 2 +- 5 files changed, 122 insertions(+), 106 deletions(-) diff --git a/api/internal/serialize.js b/api/internal/serialize.js index 0d0a0f18cd..a99b1fcb9e 100644 --- a/api/internal/serialize.js +++ b/api/internal/serialize.js @@ -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]() } diff --git a/src/cli/cli.cc b/src/cli/cli.cc index b8d2b1da78..5a25847460 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -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) { @@ -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"); @@ -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: "? diff --git a/src/cli/templates.hh b/src/cli/templates.hh index e2d8d2a659..20f983386d 100644 --- a/src/cli/templates.hh +++ b/src/cli/templates.hh @@ -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", @@ -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", diff --git a/src/process/unix.cc b/src/process/unix.cc index 7550043f60..e3a86b93e7 100644 --- a/src/process/unix.cc +++ b/src/process/unix.cc @@ -121,11 +121,12 @@ Process::id_type Process::open(const std::function &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); diff --git a/src/window/apple.mm b/src/window/apple.mm index 9eb0bef33b..a946cd9819 100644 --- a/src/window/apple.mm +++ b/src/window/apple.mm @@ -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;