from mkosi.distributions import Distribution
from mkosi.installer import clean_package_manager_metadata
from mkosi.kmod import gen_required_kernel_modules, process_kernel_modules
-from mkosi.log import complete_step, die, log_notice, log_step
+from mkosi.log import ARG_DEBUG, complete_step, die, log_notice, log_step
from mkosi.manifest import Manifest
from mkosi.mounts import finalize_source_mounts, mount_overlay
from mkosi.pager import page
return False
final, build, manifest = cache_tree_paths(config)
- if not final.exists() or (need_build_overlay(config) and not build.exists()):
+ if not final.exists():
+ logging.info(f"{final} does not exist, not reusing cached images")
+ return False
+
+ if need_build_overlay(config) and not build.exists():
+ logging.info(f"{build} does not exist, not reusing cached images")
return False
if manifest.exists():
prev = json.loads(manifest.read_text())
- if prev != json.loads(json.dumps(config.cache_manifest(), cls=JsonEncoder)):
+ new = json.dumps(config.cache_manifest(), cls=JsonEncoder, indent=4, sort_keys=True)
+ if prev != json.loads(new):
+ logging.info("Cache manifest mismatch, not reusing cached images")
+ if ARG_DEBUG.get():
+ run(["diff", manifest, "-"], input=new, check=False,
+ sandbox=config.sandbox(mounts=[Mount(manifest, manifest)]))
+
return False
else:
+ logging.info(f"{manifest} does not exist, not reusing cached images")
return False
# Either we're running as root and the cache is owned by root or we're running unprivileged inside a user
# generated by an unprivileged build, the cache will not be owned by root and we should not use it.
for p in (final, build):
if p.exists() and os.getuid() == 0 and p.stat().st_uid != 0:
+ logging.info("Running as root but cached images were not built as root, not reusing cached images")
return False
return True