# This file is part of craft-platforms.## Copyright 2024 Canonical Ltd.## This program is free software: you can redistribute it and/or modify it# under the terms of the GNU Lesser General Public License version 3, as# published by the Free Software Foundation.## This program is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.# See the GNU Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public License along# with this program. If not, see <http://www.gnu.org/licenses/>."""Rockcraft-specific platforms information."""fromtypingimportOptional,Sequencefromcraft_platformsimport_buildinfo,_errors,_platforms_LEGACY_BASES_MAP={"ubuntu:20.04":"[email protected]","ubuntu:22.04":"[email protected]",}
[docs]defget_rock_build_plan(base:str,platforms:_platforms.Platforms,build_base:Optional[str]=None,)->Sequence[_buildinfo.BuildInfo]:"""Generate the build plan for a rock. This function uses the default build planner, but filters it to prevent the use of ``build-for: all`` :param base: the rock base (e.g. ``'[email protected]'``) :param platforms: the platforms structure in ``rockcraft.yaml`` :param build_base: the build base, if provided in ``rockcraft.yaml``. :raises NeedsBuildBaseError: If base is bare and no build base is specified """# Bare bases require a build_baseifbase=="bare"andbuild_baseisNone:raise_errors.NeedBuildBaseError(base=base)ifbasein_LEGACY_BASES_MAP:base=_LEGACY_BASES_MAP[base]ifbuild_basein_LEGACY_BASES_MAP:build_base=_LEGACY_BASES_MAP[build_base]forname,platforminplatforms.items():ifplatformand"all"inplatform.get("build-for",[]):raise_errors.InvalidPlatformError(name,details="Rockcraft cannot build platform-independent images.",resolution="Replace 'build-for: [all]' with a valid architecture",)return_platforms.get_platforms_build_plan(base,platforms,build_base)