From 463e3454bd8553c8ee26c813a83386beeecb9837 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Wed, 10 May 2017 15:33:05 +0300 Subject: Make machine_manifest class to partially delegate parsing/serialization to base one --- bbot/machine-manifest.cxx | 59 ++++---------------------------- unit-tests/bootstrap-manifest/testscript | 10 ++++-- 2 files changed, 14 insertions(+), 55 deletions(-) diff --git a/bbot/machine-manifest.cxx b/bbot/machine-manifest.cxx index dd3b7de..3417dd7 100644 --- a/bbot/machine-manifest.cxx +++ b/bbot/machine-manifest.cxx @@ -57,6 +57,7 @@ namespace bbot machine_manifest:: machine_manifest (parser& p, name_value nv, bool iu) + : machine_header_manifest (p, move (nv), unknown_name_mode::stop, &nv) { auto bad_name = [&p, &nv] (const string& d) { @@ -68,52 +69,14 @@ namespace bbot throw parsing (p.name (), nv.value_line, nv.value_column + offset, d); }; - // Make sure this is the start and we support the version. - // - if (!nv.name.empty ()) - bad_name ("start of machine manifest expected"); - - if (nv.value != "1") - bad_value ("unsupported format version"); - optional type; - for (nv = p.next (); !nv.empty (); nv = p.next ()) + for (; !nv.empty (); nv = p.next ()) { string& n (nv.name); string& v (nv.value); - if (n == "id") - { - if (!id.empty ()) - bad_name ("machine id redefinition"); - - if (v.empty ()) - bad_value ("empty machine id"); - - id = move (v); - } - else if (n == "name") - { - if (!name.empty ()) - bad_name ("machine name redefinition"); - - if (v.empty ()) - bad_value ("empty machine name"); - - name = move (v); - } - else if (n == "summary") - { - if (!summary.empty ()) - bad_name ("machine summary redefinition"); - - if (v.empty ()) - bad_value ("empty machine summary"); - - summary = move (v); - } - else if (n == "type") + if (n == "type") { if (type) bad_name ("machine type redefinition"); @@ -162,15 +125,6 @@ namespace bbot // Verify all non-optional values were specified. // - if (id.empty ()) - bad_value ("no machine id specified"); - - if (name.empty ()) - bad_value ("no machine name specified"); - - if (summary.empty ()) - bad_value ("no machine summary specified"); - if (!type) bad_value ("no machine type specified"); @@ -183,10 +137,9 @@ namespace bbot // @@ Should we check that all non-optional values are specified and all // values are valid? // - s.next ("", "1"); // Start of manifest. - s.next ("id", id); - s.next ("name", name); - s.next ("summary", summary); + + machine_header_manifest::serialize (s, false); + s.next ("type", to_string (type)); if (mac) diff --git a/unit-tests/bootstrap-manifest/testscript b/unit-tests/bootstrap-manifest/testscript index 52c6721..e2af360 100644 --- a/unit-tests/bootstrap-manifest/testscript +++ b/unit-tests/bootstrap-manifest/testscript @@ -143,17 +143,23 @@ { : unquoted : - $* <'stdin:3:42: error: invalid machine options: unterminated quoted string' == 1 + $* <'stdin:6:42: 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 EOI : empty : - $* <'stdin:3:9: error: empty machine options' == 1 + $* <'stdin:6:9: error: empty machine options' == 1 : 1 : + id: a2b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + name: windows_10-msvc_14 + summary: Windows 10 build 1607 with VC 14 update 3 options: EOI } -- cgit v1.1