summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2023-02-02 03:00:30 -0700
committerAndrew Kaster <andrewdkaster@gmail.com>2023-02-02 05:35:44 -0700
commit3e6d790cf07024f6ed0e5246e0c2b091fed65638 (patch)
treeb51363cc4c97eb6f3f80c0adda12ace007235c6f
parent792258afe8b7ab0343f8b53c826ccd1b6fb60998 (diff)
downloadserenity-3e6d790cf07024f6ed0e5246e0c2b091fed65638.zip
Ladybird: Abstract spawning helper processes into separate methods
This will let us use the same path discovery methods for WebContent, SQLServer, and any other helper processes we need to launch.
-rw-r--r--Ladybird/CMakeLists.txt1
-rw-r--r--Ladybird/HelperProcess.cpp35
-rw-r--r--Ladybird/HelperProcess.h18
-rw-r--r--Ladybird/WebContentView.cpp8
4 files changed, 56 insertions, 6 deletions
diff --git a/Ladybird/CMakeLists.txt b/Ladybird/CMakeLists.txt
index 43daac54f1..bdff1b7a9d 100644
--- a/Ladybird/CMakeLists.txt
+++ b/Ladybird/CMakeLists.txt
@@ -82,6 +82,7 @@ set(SOURCES
${BROWSER_SOURCE_DIR}/History.cpp
BrowserWindow.cpp
ConsoleWidget.cpp
+ HelperProcess.cpp
InspectorWidget.cpp
LocationEdit.cpp
ModelTranslator.cpp
diff --git a/Ladybird/HelperProcess.cpp b/Ladybird/HelperProcess.cpp
new file mode 100644
index 0000000000..52a0d0ca68
--- /dev/null
+++ b/Ladybird/HelperProcess.cpp
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "HelperProcess.h"
+#include "Utilities.h"
+#include <AK/String.h>
+#include <QCoreApplication>
+
+ErrorOr<void> spawn_helper_process(StringView process_name, Span<StringView> arguments, Core::System::SearchInPath search_in_path, Optional<Span<StringView>> environment)
+{
+ auto paths = TRY(get_paths_for_helper_process(process_name));
+ VERIFY(!paths.is_empty());
+ ErrorOr<void> result;
+ for (auto const& path : paths) {
+ arguments[0] = path.bytes_as_string_view();
+ result = Core::System::exec(path, arguments, search_in_path, environment);
+ if (!result.is_error())
+ break;
+ }
+
+ return result;
+}
+
+ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name)
+{
+ Vector<String> paths;
+ TRY(paths.try_append(TRY(String::formatted("./{}/{}", process_name, process_name))));
+ TRY(paths.try_append(TRY(String::formatted("{}/{}", TRY(ak_string_from_qstring(QCoreApplication::applicationDirPath())), process_name))));
+ TRY(paths.try_append(TRY(String::formatted("./{}", process_name))));
+ // NOTE: Add platform-specific paths here
+ return paths;
+}
diff --git a/Ladybird/HelperProcess.h b/Ladybird/HelperProcess.h
new file mode 100644
index 0000000000..18d530a321
--- /dev/null
+++ b/Ladybird/HelperProcess.h
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2023, Andrew Kaster <akaster@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#define AK_DONT_REPLACE_STD
+
+#include <AK/Error.h>
+#include <AK/Optional.h>
+#include <AK/Span.h>
+#include <AK/StringView.h>
+#include <LibCore/System.h>
+
+ErrorOr<void> spawn_helper_process(StringView process_name, Span<StringView> arguments, Core::System::SearchInPath, Optional<Span<StringView>> environment = {});
+ErrorOr<Vector<String>> get_paths_for_helper_process(StringView process_name);
diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp
index 1c2af12c2b..71666bf510 100644
--- a/Ladybird/WebContentView.cpp
+++ b/Ladybird/WebContentView.cpp
@@ -9,6 +9,7 @@
#include "WebContentView.h"
#include "ConsoleWidget.h"
+#include "HelperProcess.h"
#include "InspectorWidget.h"
#include "Utilities.h"
#include <AK/Assertions.h>
@@ -586,12 +587,7 @@ void WebContentView::create_client()
arguments.append(m_webdriver_content_ipc_path);
}
- auto result = Core::System::exec("./WebContent/WebContent"sv, arguments, Core::System::SearchInPath::Yes);
- if (result.is_error()) {
- auto web_content_path = ak_deprecated_string_from_qstring(QCoreApplication::applicationDirPath() + "/WebContent");
- result = Core::System::exec(web_content_path, arguments, Core::System::SearchInPath::Yes);
- }
-
+ auto result = spawn_helper_process("WebContent"sv, arguments, Core::System::SearchInPath::Yes);
if (result.is_error())
warnln("Could not launch WebContent: {}", result.error());
VERIFY_NOT_REACHED();