Пример #1
0
def _update_yaml_with_extracted_metadata(
        config_data: Dict[str, Any],
        parts_config: project_loader.PartsConfig) -> None:
    if 'adopt-info' in config_data:
        part_name = config_data['adopt-info']
        part = parts_config.get_part(part_name)
        if not part:
            raise meta_errors.AdoptedPartMissingError(part_name)

        # This would be caught since metadata would be missing, but we want
        # to be clear about the issue here. This really should be caught by the
        # schema, but it doesn't seem to support such dynamic behavior.
        if 'parse-info' not in config_data['parts'][part_name]:
            raise meta_errors.AdoptedPartNotParsingInfo(part_name)

        # Get the metadata from the pull step first, then update it using the
        # metadata from the build step (i.e. the data from the build step takes
        # precedence over the pull step)
        metadata = part.get_pull_state().extracted_metadata['metadata']
        metadata.update(part.get_build_state().extracted_metadata['metadata'])
        _adopt_info(config_data, metadata)

    # Verify that all mandatory keys have been satisfied
    missing_keys = []  # type: List[str]
    for key in _MANDATORY_PACKAGE_KEYS:
        if key not in config_data:
            missing_keys.append(key)

    if missing_keys:
        raise meta_errors.MissingSnapcraftYamlKeysError(keys=missing_keys)
Пример #2
0
def _update_yaml_with_extracted_metadata(
    config_data: Dict[str, Any],
    parts_config: project_loader.PartsConfig,
    prime_dir: str,
) -> Optional[extractors.ExtractedMetadata]:
    if "adopt-info" not in config_data:
        return None

    part_name = config_data["adopt-info"]
    part = parts_config.get_part(part_name)
    if not part:
        raise meta_errors.AdoptedPartMissingError(part_name)

    pull_state = part.get_pull_state()
    build_state = part.get_build_state()
    stage_state = part.get_stage_state()
    prime_state = part.get_prime_state()

    # Get the metadata from the pull step first.
    metadata = pull_state.extracted_metadata["metadata"]

    # Now update it using the metadata from the build step (i.e. the data
    # from the build step takes precedence over the pull step).
    metadata.update(build_state.extracted_metadata["metadata"])

    # Now make sure any scriptlet data are taken into account. Later steps
    # take precedence, and scriptlet data (even in earlier steps) take
    # precedence over extracted data.
    metadata.update(pull_state.scriptlet_metadata)
    metadata.update(build_state.scriptlet_metadata)
    metadata.update(stage_state.scriptlet_metadata)
    metadata.update(prime_state.scriptlet_metadata)

    if not metadata:
        # If we didn't end up with any metadata, let's ensure this part was
        # actually supposed to parse info. If not, let's try to be very
        # clear about what's happening, here. We do this after checking for
        # metadata because metadata could be supplied by scriptlets, too.
        if "parse-info" not in config_data["parts"][part_name]:
            raise meta_errors.AdoptedPartNotParsingInfo(part_name)

    _adopt_info(config_data, metadata, prime_dir)

    return metadata
Пример #3
0
def _update_yaml_with_extracted_metadata(
    config_data: Dict[str, Any], parts_config: project_loader.PartsConfig
) -> None:
    if "adopt-info" in config_data:
        part_name = config_data["adopt-info"]
        part = parts_config.get_part(part_name)
        if not part:
            raise meta_errors.AdoptedPartMissingError(part_name)

        pull_state = part.get_pull_state()
        build_state = part.get_build_state()
        stage_state = part.get_stage_state()
        prime_state = part.get_prime_state()

        # Get the metadata from the pull step first.
        metadata = pull_state.extracted_metadata["metadata"]

        # Now update it using the metadata from the build step (i.e. the data
        # from the build step takes precedence over the pull step).
        metadata.update(build_state.extracted_metadata["metadata"])

        # Now make sure any scriptlet data are taken into account. Later steps
        # take precedence, and scriptlet data (even in earlier steps) take
        # precedence over extracted data.
        metadata.update(pull_state.scriptlet_metadata)
        metadata.update(build_state.scriptlet_metadata)
        metadata.update(stage_state.scriptlet_metadata)
        metadata.update(prime_state.scriptlet_metadata)

        if not metadata:
            # If we didn't end up with any metadata, let's ensure this part was
            # actually supposed to parse info. If not, let's try to be very
            # clear about what's happening, here. We do this after checking for
            # metadata because metadata could be supplied by scriptlets, too.
            if "parse-info" not in config_data["parts"][part_name]:
                raise meta_errors.AdoptedPartNotParsingInfo(part_name)

        _adopt_info(config_data, metadata)