<?xml version="1.0" encoding="UTF-8"?>
<!--
  A source link file with optional modificators like patches
-->
<grammar ns="http://buildservice.org/api"
         xmlns="http://relaxng.org/ns/structure/1.0"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
         xmlns:a="http://www.example.com/annotation">

  <start>
    <ref name="link-element"/>
  </start>

  <define name="cicount">
    <choice>
      <value>add</value>
        <a:documentation>
          The resulting check in counter is calculated by adding the linked
          package's cicount to the link's cicount.
        </a:documentation>
      <value>copy</value>
        <a:documentation>
          The check in counter is copied over from the original package.
        </a:documentation>
      <value>local</value>
        <a:documentation>
          The check in counter is the number of commits to the local package
          (and not taking the package that is being linked to into account).
        </a:documentation>
    </choice>
  </define>

  <define name="patches-element">
    <element ns="" name="patches">
      <interleave>
        <zeroOrMore>
          <element ns="" name="add">
            <a:documentation>
              Add a file to the package on top of the original package.
            </a:documentation>
            <attribute name="name">
              <a:documentation>
                Name of the file which should be added to the package. It must
                be checked-in in the unexpanded package.
              </a:documentation>
            </attribute>
            <optional>
                <attribute name="type"/>
            </optional>
            <optional>
                <attribute name="after"/>
            </optional>
            <optional>
                <attribute name="popt"/>
            </optional>
            <optional>
                <attribute name="dir"/>
            </optional>
            <empty/>
          </element>
        </zeroOrMore>

        <zeroOrMore>
          <element ns="" name="apply">
            <a:documentation>
              Apply the patch with the supplied name when expanding the sources.
            </a:documentation>
            <attribute name="name"/>
            <empty/>
          </element>
        </zeroOrMore>

        <zeroOrMore>
          <element ns="" name="delete">
            <a:documentation>
              Remove the file with the supplied name when expanding the sources.
            </a:documentation>
            <attribute name="name"/>
            <empty/>
          </element>
        </zeroOrMore>

        <optional>
          <element ns="" name="branch">
            <a:documentation>
              If present, then perform a full copy of all sources from the link
              source into the current package.
            </a:documentation>
            <empty/>
          </element>
        </optional>

        <zeroOrMore>
          <element ns="" name="topadd">
            <a:documentation>
              Add the given string to the top of the spec file in the package sources.
            </a:documentation>
            <text/>
          </element>
        </zeroOrMore>

      </interleave>
    </element>
  </define>

  <define name="link-element">
    <element ns="" name="link">
      <a:documentation>
        A source link element instructs OBS to link a certain package into a
        different project and optionally to apply modifications, like patches,
        on top of the original package.

        The actual build of the package is run in the so-called "expanded
        sources". The expansion is performed either as a 3-way merge or as a
        plain copy of the linked package into the linking package, depending
        whether the 'branch' element is present in the 'patches' child element.

        If the 'branch' element not present, then a simple copy is performed. If
        the 'branch' is present, then OBS applies the diff of the linking
        package at 'rev' (or HEAD if omitted) to the linked package at 'baserev'
        (or HEAD if omitted) to the latest revision of the linked package.
      </a:documentation>

      <optional>
        <attribute name="project">
          <a:documentation>
            The name of the project to which this link points.
          </a:documentation>
        </attribute>
      </optional>
      <optional>
        <attribute name="package">
          <a:documentation>
            The name of the package to which this link points.
          </a:documentation>
        </attribute>
      </optional>
      <optional>
        <attribute name="missingok">
          <choice>
            <value>true</value>
          </choice>
          <a:documentation>
            Allow linking against packages that have been deleted.
          </a:documentation>
        </attribute>
      </optional>
      <optional>
        <attribute name="rev">
          <a:documentation>
            Revision of the package containing the _link file that is used for
            the 3-way merge to construct the expanded sources.
            If omitted, defaults to the latest revision.
          </a:documentation>
        </attribute>
      </optional>
      <optional>
        <attribute name="vrev"/>
      </optional>
      <optional>
        <attribute name="cicount">
          <ref name="cicount"/>
          <a:documentation>
            Determines how the cicount (=check in count, the number of commits
            since the last version bump of the package) of the linked package is
            calculated.
            If omitted, then the default is "add".
          </a:documentation>
        </attribute>
      </optional>
      <optional>
        <attribute name="baserev">
          <a:documentation>
            Revision of the base package to which the link points that is used
            for the 3-way merge to calculate the expanded sources.
            If omitted, then the latest revision is used.
          </a:documentation>
        </attribute>
      </optional>

      <zeroOrMore>
        <ref name="patches-element"/>
      </zeroOrMore>

    </element>
  </define>
</grammar>
