variants: Allow multiple explicit optional variants

When a variant has optional, it is possible to explictly list it in the
XML file and add extra groups. However, the original DTD did not allow
multiple variants with `id="optional"` as `id` attribute has to be
globally unique. This patch changes its type to `CDATA`, which has less
restrictions. This also means we can no longer define `<ref>` as
`IDREF` and instead check the existence of referenced variant in parser.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2016-09-15 10:12:32 +02:00
parent 912f81ca16
commit 6fede3f395
2 changed files with 7 additions and 3 deletions

View File

@ -150,7 +150,11 @@ class VariantsXmlParser(object):
self.add_child(optional, variant) self.add_child(optional, variant)
for ref in variant_node.xpath("variants/ref/@id"): for ref in variant_node.xpath("variants/ref/@id"):
child_variant = self.parse_variant_node(self.addons[ref], variant) try:
child_variant = self.parse_variant_node(self.addons[ref], variant)
except KeyError:
raise RuntimeError("Variant %s references non-existing variant %s"
% (variant.uid, ref))
self.add_child(child_variant, variant) self.add_child(child_variant, variant)
# XXX: top-level optional # XXX: top-level optional

View File

@ -2,7 +2,7 @@
<!ELEMENT variant (release?,arches,groups?,environments*,variants*,buildinstallpackages?)?> <!ELEMENT variant (release?,arches,groups?,environments*,variants*,buildinstallpackages?)?>
<!ATTLIST variant <!ATTLIST variant
id ID #REQUIRED id CDATA #REQUIRED
name CDATA #REQUIRED name CDATA #REQUIRED
type (variant|addon|optional|layered-product) #REQUIRED type (variant|addon|optional|layered-product) #REQUIRED
has_optional (true|false) #IMPLIED has_optional (true|false) #IMPLIED
@ -39,7 +39,7 @@
<!ELEMENT ref EMPTY> <!ELEMENT ref EMPTY>
<!ATTLIST ref <!ATTLIST ref
id IDREF #REQUIRED id CDATA #REQUIRED
> >
<!ELEMENT buildinstallpackages (package)+> <!ELEMENT buildinstallpackages (package)+>