Package original PHP alongside the Swift server
This commit is contained in:
1 parent
5852266ed9
commit
66a35a9f7c
5 files changed
+66
-5
No files matched your search
@@ -3,7 +3,11 @@ import Foundation
|
||||
func runCommandLine(_ arguments: [String]) {
|
||||
do {
|
||||
if arguments.contains("--help") {
|
||||
print("EzServerMac [--headless | --import-library /absolute/path | --show-token]")
|
||||
print("EzServerMac [--headless | --php | --import-library /absolute/path | --show-token]")
|
||||
return
|
||||
}
|
||||
if arguments == ["--php"] {
|
||||
try launchBundledPHP()
|
||||
return
|
||||
}
|
||||
guard arguments.isEmpty || arguments == ["--headless"] || arguments == ["--show-token"]
|
||||
@@ -48,7 +52,24 @@ func runCommandLine(_ arguments: [String]) {
|
||||
}
|
||||
}
|
||||
|
||||
private func launchBundledPHP() throws {
|
||||
guard let script = Bundle.main.resourceURL?.appendingPathComponent("php/run.sh"),
|
||||
FileManager.default.isReadableFile(atPath: script.path) else {
|
||||
throw CommandError.phpNotBundled
|
||||
}
|
||||
var arguments = [strdup("/bin/bash"), strdup(script.path), nil]
|
||||
defer { arguments.forEach { free($0) } }
|
||||
// Replace the launcher so the shell receives the caller's stop signals directly.
|
||||
_ = execv("/bin/bash", &arguments)
|
||||
throw POSIXError(POSIXErrorCode(rawValue: errno) ?? .EIO)
|
||||
}
|
||||
|
||||
private enum CommandError: LocalizedError {
|
||||
case invalidArguments
|
||||
var errorDescription: String? { "Invalid arguments. Run EzServerMac --help." }
|
||||
case invalidArguments, phpNotBundled
|
||||
var errorDescription: String? {
|
||||
switch self {
|
||||
case .invalidArguments: return "Invalid arguments. Run EzServerMac --help."
|
||||
case .phpNotBundled: return "Original PHP is missing from this build. Prepare the runtime before building."
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user