When set to "never", we'll always sync repository metadata.
@contextlib.contextmanager
-def mount_cache_overlay(context: Context) -> Iterator[None]:
- if not context.config.incremental or not context.config.base_trees or context.config.overlay:
+def mount_cache_overlay(context: Context, cached: bool) -> Iterator[None]:
+ if not context.config.incremental or not context.config.base_trees or context.config.overlay or cached:
yield
return
def copy_repository_metadata(context: Context) -> None:
- if have_cache(context.config):
- return
-
subdir = context.config.distribution.package_manager(context.config).subdir(context.config)
- # Don't copy anything if the repository metadata directories are already populated.
+ # Don't copy anything if the repository metadata directories are already populated and we're not explicitly asked
+ # to sync repository metadata.
if (
- any((context.package_cache_dir / "cache" / subdir).glob("*")) or
- any((context.package_cache_dir / "lib" / subdir).glob("*"))
+ context.config.cacheonly != Cacheonly.never and
+ (
+ any((context.package_cache_dir / "cache" / subdir).glob("*")) or
+ any((context.package_cache_dir / "lib" / subdir).glob("*"))
+ )
):
logging.debug(f"Found repository metadata in {context.package_cache_dir}, not copying repository metadata")
return
install_base_trees(context)
cached = reuse_cache(context)
- if not cached:
- with mount_cache_overlay(context):
- copy_repository_metadata(context)
+ with mount_cache_overlay(context, cached):
+ copy_repository_metadata(context)
context.config.distribution.setup(context)
install_package_directories(context)
if not cached:
- with mount_cache_overlay(context):
+ with mount_cache_overlay(context, cached):
install_skeleton_trees(context)
install_distribution(context)
run_prepare_scripts(context, build=False)
def sync_repository_metadata(context: Context) -> None:
- if have_cache(context.config) or context.config.cacheonly != Cacheonly.none:
+ if (
+ context.config.cacheonly != Cacheonly.never and
+ (have_cache(context.config) or context.config.cacheonly != Cacheonly.auto)
+ ):
return
with (
class Cacheonly(StrEnum):
- always = enum.auto()
- none = enum.auto()
+ always = enum.auto()
+ auto = enum.auto()
+ none = auto
metadata = enum.auto()
+ never = enum.auto()
class QemuFirmware(StrEnum):
dest="cacheonly",
long="--cache-only",
name="CacheOnly",
- metavar="CACHEONLY",
section="Distribution",
- parse=config_make_enum_parser_with_boolean(Cacheonly, yes=Cacheonly.always, no=Cacheonly.none),
- default=Cacheonly.none,
+ parse=config_make_enum_parser_with_boolean(Cacheonly, yes=Cacheonly.always, no=Cacheonly.auto),
+ default=Cacheonly.auto,
help="Only use the package cache when installing packages",
+ choices=Cacheonly.values(),
),
ConfigSetting(
dest="package_manager_trees",
`CacheOnly=`, `--cache-only=`
-: Takes one of `none`, `metadata` or `always`. If `always`, the package
- manager is instructed not to contact the network. This provides a
- minimal level of reproducibility, as long as the package cache is
- already fully populated. If set to `metadata`, the package manager can
- still download packages, but we won't sync the repository metadata. If
- set to `none`, the repository metadata is synced and packages can be
- downloaded during the build.
+: Takes one of `auto`, `metadata`, `always` or `never`. Defaults to
+ `auto`. If `always`, the package manager is instructed not to contact
+ the network. This provides a minimal level of reproducibility, as long
+ as the package cache is already fully populated. If set to `metadata`,
+ the package manager can still download packages, but we won't sync the
+ repository metadata. If set to `auto`, the repository metadata is
+ synced unless we have a cached image (see `Incremental=`) and packages
+ can be downloaded during the build. If set to `never`, repository
+ metadata is always synced and and packages can be downloaded during
+ the build.
`PackageManagerTrees=`, `--package-manager-tree=`