From dd1d5472bf28beba971d2b507fab53dec43939f7 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 10 May 2017 18:46:42 +0300 Subject: Allow multi-line machine manifest options value --- bbot/machine-manifest.cxx | 35 +++++++++++++++++++++----- unit-tests/machine-manifest/testscript | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/bbot/machine-manifest.cxx b/bbot/machine-manifest.cxx index 7f9a030..b7baf7e 100644 --- a/bbot/machine-manifest.cxx +++ b/bbot/machine-manifest.cxx @@ -4,10 +4,14 @@ #include +#include + +#include #include #include #include +using namespace std; using namespace butl; namespace bbot @@ -64,9 +68,16 @@ namespace bbot throw parsing (p.name (), nv.name_line, nv.name_column, d); }; - auto bad_value = [&p, &nv] (const string& d, size_t offset = 0) + // Offsets are used to tie an error to the specific position inside a + // manifest value (possibly a multiline one). + // + auto bad_value = [&p, &nv] ( + const string& d, uint64_t column_offset = 0, uint64_t line_offset = 0) { - throw parsing (p.name (), nv.value_line, nv.value_column + offset, d); + throw parsing (p.name (), + nv.value_line + line_offset, + (line_offset == 0 ? nv.value_column : 1) + column_offset, + d); }; optional type; @@ -106,14 +117,26 @@ namespace bbot strings op; + // Note that when reporting errors we combine the manifest value + // position with the respective error position. + // try { - op = string_parser::parse_quoted (v, false); + istringstream is (v); + tab_parser parser (is, ""); + + tab_fields tl; + while (!(tl = parser.next ()).empty ()) + { + for (auto& tf: tl) + op.emplace_back (move (tf.value)); + } } - catch (const invalid_string& e) + catch (const tab_parsing& e) { - bad_value (string ("invalid machine options: ") + e.what (), - e.position); + bad_value ("invalid machine options: " + e.description, + e.column - 1, + e.line - 1); } if (op.empty ()) diff --git a/unit-tests/machine-manifest/testscript b/unit-tests/machine-manifest/testscript index 66dedc6..e264b41 100644 --- a/unit-tests/machine-manifest/testscript +++ b/unit-tests/machine-manifest/testscript @@ -22,6 +22,38 @@ options: -device "virtio-scsi-pci,id=scsi" -device "scsi-hd,drive=disk0" EOF + : multi-line-options + : + $* <>EOO + : 1 + id: a2b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + name: windows_10-msvc_14 + summary: Windows 10 build 1607 with VC 14 update 3 + type: kvm + options: \ + -device "virtio-scsi-pci,id=scsi" + -device "scsi-hd,drive=disk0" + \ + EOI + : 1 + id: a2b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + name: windows_10-msvc_14 + summary: Windows 10 build 1607 with VC 14 update 3 + type: kvm + options: -device "virtio-scsi-pci,id=scsi" -device "scsi-hd,drive=disk0" + EOO + + : no-mac + : + $* <>EOF + : 1 + id: a2b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + name: windows_10-msvc_14 + summary: Windows 10 build 1607 with VC 14 update 3 + type: nspawn + options: -device "virtio-scsi-pci,id=scsi" -device "scsi-hd,drive=disk0" + EOF + : no-options : $* <>EOF @@ -106,6 +138,19 @@ summary: Windows 10 build 1607 with VC 14 update 3 options: -device "virtio-scsi-pci,id=scsi EOI + + : unquoted-multi-line + : + $* <'stdin:7:29: error: invalid machine options: unterminated quoted string' == 1 + : 1 + id: a2b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + name: windows_10-msvc_14 + summary: Windows 10 build 1607 with VC 14 update 3 + options: \ + -device "virtio-scsi-pci,id=scsi" + -device "scsi-hd,drive=disk0 + \ + EOI } } -- cgit v1.1