Пример #1
0
    def get_stage_snaps(self) -> Set[str]:
        if not self.__stage_snaps:
            processor = GrammarProcessor(
                arch=self._arch,
                target_arch=self._target_arch,
                checker=repo.snaps.SnapPackage.is_valid_snap,
            )
            self.__stage_snaps = set(
                processor.process(grammar=self._get_property("stage-snaps")))

        return self.__stage_snaps
Пример #2
0
    def get_build_environment(self) -> List[Dict[str, str]]:
        if not self.__build_environment:
            processor = GrammarProcessor(
                arch=self._arch,
                target_arch=self._target_arch,
                checker=lambda s: True,
            )
            self.__build_environment = processor.process(
                grammar=self._get_property("build-environment"), )

        return self.__build_environment
Пример #3
0
    def get_build_packages(self) -> Set[str]:
        if not self.__build_packages:
            processor = GrammarProcessor(
                arch=self._arch,
                target_arch=self._target_arch,
                checker=self._repo.build_package_is_valid,
            )
            self.__build_packages = set(
                processor.process(
                    grammar=self._get_property("build-packages"), ))

        return self.__build_packages
Пример #4
0
 def get_source(self) -> str:
     if not self.__source:
         # The grammar is array-based, even though we only support a single
         # source.
         processor = GrammarProcessor(
             arch=self._arch,
             target_arch=self._target_arch,
             checker=lambda s: True,
         )
         source_array = processor.process(grammar=self._source_grammar)
         if len(source_array) > 0:
             self.__source = source_array.pop()
     return self.__source
Пример #5
0
def process_parts(
    *, parts_yaml_data: Dict[str, Any], arch: str, target_arch: str
) -> Dict[str, Any]:
    """Process grammar for parts.

    :param yaml_data: unprocessed snapcraft.yaml.
    :returns: process snapcraft.yaml.
    """
    # TODO: make checker optional in craft-grammar.
    processor = GrammarProcessor(
        arch=arch,
        target_arch=target_arch,
        checker=lambda x: x == x,  # pylint: disable=comparison-with-itself
    )

    for part_name in parts_yaml_data:
        parts_yaml_data[part_name] = process_part(
            part_yaml_data=parts_yaml_data[part_name], processor=processor
        )

    return parts_yaml_data
Пример #6
0
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Grammar processor tests."""

from collections import namedtuple

import pytest
from craft_grammar import GrammarProcessor

from snapcraft.parts.grammar import process_part, process_parts

_PROCESSOR = GrammarProcessor(
    arch="amd64",
    target_arch="amd64",
    checker=lambda x: x == x,  # pylint: disable=comparison-with-itself
)
GrammarEntry = namedtuple("GrammarEntry", ["value", "expected"])

GRAMMAR_SCALAR_ENTRIES = [
    # no grammar.
    GrammarEntry("entry", "entry"),
    # on arch match.
    GrammarEntry([{
        "on amd64": "entry"
    }], "entry"),
    # on else match.
    GrammarEntry([{
        "on arm64": "entry"
    }, {