def _copy_assets(self): """Copy assets directly to repository, if exists.""" assets_dir = self._project._get_snapcraft_assets_dir() logger.debug("assets expected at: {}".format(assets_dir)) # Assets directory exists, but may not actually contain assets. # The snapd project is an example of this. The sanity checker # will warn to the user when the project is built. if os.path.exists(assets_dir): logger.debug("copying assets: {} -> {}".format( assets_dir, self._repo_snap_dir)) # Remove existing assets, and update copy. if os.path.exists(self._repo_snap_dir): rmtree(self._repo_snap_dir) shutil.copytree(assets_dir, self._repo_snap_dir) else: os.makedirs(self._repo_snap_dir, exist_ok=True) # Copy plugins if not already inside assets directory (and exists). plugins_dir = self._project._get_local_plugins_dir() if plugins_dir.startswith( assets_dir) or not os.path.exists(plugins_dir): return self._repo_plugins_dir = os.path.join(self._repo_snap_dir, "plugins") logger.debug("copying local plugins: {} -> {}".format( plugins_dir, self._repo_plugins_dir)) shutil.copytree(plugins_dir, self._repo_plugins_dir)
def _pull_source(self, part_name: str, source: str, selector=None) -> str: """Pull source_url for part to source_dir. Returns source. :param str part_name: Name of part. :param str source: Source URL to pull. :param str selector: Source selector, if any (e.g. "on amd64"). :return: Relative path to archive within repository. """ download_dir = self._get_part_cache_dir(part_name, selector) source_handler = self._get_part_source_handler(part_name, source, download_dir) if selector: print_name = "{} [selector='{}']".format(part_name, selector) else: print_name = part_name # Skip non-local sources (the remote builder can fetch those directly), # unless configured to package all sources. is_local_source = isinstance( source_handler, snapcraft.internal.sources.Local) or ( isinstance(source_handler, snapcraft.internal.sources.Git) and source_handler.is_local()) if not self._package_all_sources and not is_local_source: logger.debug("passing through source for {}: {}".format( print_name, source)) return source logger.info("Packaging sources for {}...".format(print_name)) # Remove existing cache directory (if exists) if os.path.exists(download_dir): rmtree(download_dir) # Pull sources, but create directory first if part # is configured to use the `dump` plugin. if self._snapcraft_config["parts"][part_name].get("plugin") == "dump": os.makedirs(download_dir, exist_ok=True) source_handler.pull() # Create source archive. return self._archive_part_sources(part_name, selector)
def __init__(self, worktree_dir: str, project: Project, package_all_sources=False) -> None: """Create remote-build WorkTree. :param str worktree_dir: Directory to use for working tree. :param Project project: Snapcraft project. :param bool package_all_sources: Package all sources instead of the default of local-only sources. """ self._project = project self._package_all_sources = package_all_sources # Get snapcraft yaml (as OrderedDict). self._snapcraft_config = (self._project.info.get_raw_snapcraft() ) # type: OrderedDict # Working copy. self._prepared_snapcraft_config = ( self._project.info.get_raw_snapcraft()) # type: OrderedDict # Working tree base directory. self._base_dir = worktree_dir # Initialize cache for sources. self._cache_dir = os.path.join(self._base_dir, "cache") os.makedirs(self._cache_dir, exist_ok=True) # Initialize clean repo to ship to remote builder. self._repo_dir = os.path.join(self._base_dir, "repo") if os.path.exists(self._repo_dir): rmtree(self._repo_dir) self._repo_sources_dir = os.path.join(self._repo_dir, "sources") self._repo_snap_dir = os.path.join(self._repo_dir, "snap")