Skip to content

Commit 8a35d03

Browse files
authored
Merge pull request #6741 from naveenrajm7/qemu-args
scripting: add qemu additional arguments
2 parents 6093498 + f101cce commit 8a35d03

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Scripting/UTM.sdef

+10
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@
444444
description="List of serial configuration.">
445445
<type type="qemu serial configuration" list="yes"/>
446446
</property>
447+
448+
<property name="qemu additional arguments" code="QeAd"
449+
description="List of qemu arguments.">
450+
<type type="qemu argument" list="yes"/>
451+
</property>
447452
</record-type>
448453

449454
<enumeration name="qemu directory share mode" code="QeSm" description="Method for sharing directory in QEMU.">
@@ -553,6 +558,11 @@
553558
description="The port number to listen on when the interface is a TCP server."/>
554559
</record-type>
555560

561+
<record-type name="qemu argument" code="QeAr" description="QEMU argument configuration.">
562+
<property name="argument string" code="ArSt" type="text"
563+
description="The QEMU argument as a string."/>
564+
</record-type>
565+
556566
<record-type name="apple configuration" code="ApCf" description="Apple virtual machine configuration.">
557567
<property name="name" code="pnam" type="text"
558568
description="Virtual machine name."/>

Scripting/UTMScriptingConfigImpl.swift

+25
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ extension UTMScriptingConfigImpl {
107107
"drives": config.drives.map({ serializeQemuDriveExisting($0) }),
108108
"networkInterfaces": config.networks.enumerated().map({ serializeQemuNetwork($1, index: $0) }),
109109
"serialPorts": config.serials.enumerated().map({ serializeQemuSerial($1, index: $0) }),
110+
"qemuAdditionalArguments": config.qemu.additionalArguments.map({ serializeQemuAdditionalArgument($0)}),
110111
]
111112
}
112113

@@ -188,6 +189,14 @@ extension UTMScriptingConfigImpl {
188189
]
189190
}
190191

192+
private func serializeQemuAdditionalArgument(_ argument: QEMUArgument) -> [AnyHashable: Any] {
193+
var serializedArgument: [AnyHashable: Any] = [
194+
"argumentString": argument.string
195+
]
196+
197+
return serializedArgument
198+
}
199+
191200
private func serializeAppleConfiguration(_ config: UTMAppleConfiguration) -> [AnyHashable : Any] {
192201
[
193202
"name": config.information.name,
@@ -338,6 +347,9 @@ extension UTMScriptingConfigImpl {
338347
if let serialPorts = record["serialPorts"] as? [[AnyHashable : Any]] {
339348
try updateQemuSerials(from: serialPorts)
340349
}
350+
if let qemuAdditionalArguments = record["qemuAdditionalArguments"] as? [[AnyHashable: Any]] {
351+
try updateQemuAdditionalArguments(from: qemuAdditionalArguments)
352+
}
341353
}
342354

343355
private func parseQemuDriveInterface(_ value: AEKeyword?) -> QEMUDriveInterface? {
@@ -500,6 +512,19 @@ extension UTMScriptingConfigImpl {
500512
}
501513
}
502514

515+
private func updateQemuAdditionalArguments(from records: [[AnyHashable: Any]]) throws {
516+
let config = config as! UTMQemuConfiguration
517+
let additionalArguments = records.compactMap { record -> QEMUArgument? in
518+
guard let argumentString = record["argumentString"] as? String else { return nil }
519+
var argument = QEMUArgument(argumentString)
520+
521+
return argument
522+
}
523+
// Update entire additional arguments with new one.
524+
config.qemu.additionalArguments = additionalArguments
525+
}
526+
527+
503528
private func updateAppleConfiguration(from record: [AnyHashable : Any]) throws {
504529
let config = config as! UTMAppleConfiguration
505530
if let name = record["name"] as? String, !name.isEmpty {

0 commit comments

Comments
 (0)