),
)
+ if config.is_incremental() and config.cacheonly == Cacheonly.never:
+ die("Incremental=yes cannot be used with CacheOnly=never")
+
def check_tool(config: Config, *tools: PathString, reason: str, hint: Optional[str] = None) -> Path:
tool = config.find_binary(*tools)
rmtree(*(p for p in cache_tree_paths(config) if p.exists()), sandbox=sandbox)
-def run_clean(args: Args, config: Config) -> None:
+def run_clean(args: Args, config: Config, repository_metadata_needs_sync: bool = False) -> None:
# We remove any cached images if either the user used --force twice, or he/she called "clean"
# with it passed once. Let's also remove the downloaded package cache if the user specified one
# additional "--force".
config.is_incremental() and not have_cache(config)
)
remove_build_cache = args.force > 1 or args.wipe_build_dir
- remove_image_cache = args.force > 1 or not have_cache(config)
+ remove_image_cache = args.force > 1 or not have_cache(config) or repository_metadata_needs_sync
remove_package_cache = args.force > 2
if remove_outputs:
config.build_subdir.chmod(stat.S_IMODE(st.st_mode) & ~(stat.S_ISGID | stat.S_ISUID))
+def repository_metadata_needs_sync(images: Sequence[Config]) -> bool:
+ for config in images:
+ if config.cacheonly == Cacheonly.never:
+ return True
+
+ if config.cacheonly == Cacheonly.auto and not have_cache(config):
+ return True
+
+ return False
+
+
def sync_repository_metadata(
args: Args,
images: Sequence[Config],
(last.package_cache_dir_or_default() / "cache" / subdir).mkdir(parents=True, exist_ok=True)
- def needs_sync(config: Config) -> bool:
- if config.cacheonly != Cacheonly.auto:
- return config.cacheonly == Cacheonly.never
-
- return not have_cache(config)
-
# Sync repository metadata unless explicitly disabled.
- if any(needs_sync(config) for config in images):
+ if repository_metadata_needs_sync(images):
with setup_workspace(args, last) as workspace:
context = Context(
args,
# a later image build could end up deleting the output generated by an earlier image build.
if needs_build(args, last) or args.wipe_build_dir:
for config in images:
- run_clean(args, config)
+ run_clean(args, config, repository_metadata_needs_sync(images))
for i, config in enumerate(images):
if args.verb != Verb.build:
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 the image is cached (see `Incremental=`) and packages can
+ synced unless all images are cached (see `Incremental=`) and packages can
be downloaded during the build. If set to `never`, repository metadata
is always synced and packages can be downloaded during the build.