def _install_build_snaps(build_snaps: Set[str], content_snaps: Set[str]) -> List[str]: if common.is_offline(): logger.warning("Offline mode, not installing build packages.") return [] if common.is_process_container() and build_snaps: installed_snaps: List[str] = [] logger.warning( ( "The following snaps are required but not installed as snapcraft " "is running inside docker or podman container: {}.\n" "Please ensure the environment is properly setup before continuing.\n" "Ignore this message if the appropriate measures have already been taken".format( ", ".join(build_snaps) ) ) ) else: installed_snaps = repo.snaps.install_snaps(build_snaps) for content_snap in content_snaps: try: installed_snaps += repo.snaps.install_snaps([content_snap]) except repo.snaps.errors.SnapUnavailableError: logger.warning( f"Could not install snap defined in plug {content_snap!r}. " "The missing library report may have false positives listed if those " "libraries are provided by the content snap." ) return installed_snaps
def get_op(self) -> _SnapOp: if self.__required_operation is not None: return self.__required_operation if common.is_offline(): self.__required_operation = _SnapOp.INJECT return self.__required_operation # From the point of view of multiple architectures if the target host (this) # is different than that of where these snaps run from, then we always need to # install from the store if self._inject_from_host: # Get information from the host. host_snap_repo = self._get_snap_repo() try: host_snap_info = host_snap_repo.get_local_snap_info() is_installed = host_snap_repo.installed except repo.errors.SnapdConnectionError: # This maybe because we are in a docker instance or another OS. is_installed = False else: is_installed = False # The evaluations for the required operation is as follows: # - if the snap is not installed on the host (is_installed == False), # and the snap is not installed in the build environment # (_latest_revision is None), then a store install will take place. # - else if the snap is not installed on the host (is_installed == False), # but the is previously installed revision in the build environment # (_latest_revision is not None), then a store install will take place. # - else if the snap is installed on the host (is_installed == True), # and the snap installed in the build environment (_latest_revision) matches # the one on the host, no operation takes place. # - else if the snap is installed on the host (is_installed == True), # and the snap installed in the build environment (_latest_revision) does not # match the one on the host, then a snap injection from the host will take place. if not is_installed and self._latest_revision is None: op = _SnapOp.INSTALL elif not is_installed and self._latest_revision is not None: op = _SnapOp.REFRESH elif is_installed and self._latest_revision == host_snap_info[ "revision"]: op = _SnapOp.NOP elif is_installed and self._latest_revision != host_snap_info[ "revision"]: op = _SnapOp.INJECT else: # This is a programmatic error raise RuntimeError( "Unhandled scenario for {!r} (host installed: {}, latest_revision {})" .format(self.snap_name, is_installed, self._latest_revision)) self.__required_operation = op return op
def _wait_for_network(self) -> None: if common.is_offline(): logger.debug("Offline mode, don't wait for network.") return self.echoer.wrapped("Waiting for network to be ready...") for i in range(40): try: self._run(["getent", "hosts", "snapcraft.io"], hide_output=True) break except errors.ProviderExecError: sleep(0.5) else: self.echoer.warning("Failed to setup networking.")
def _install_build_packages(build_packages: Set[str]) -> List[str]: if common.is_offline(): logger.warning("Offline mode, not installing build packages.") return [] return repo.Repo.install_build_packages(build_packages)