Fix crash in target-specific commands called from initial cache script

Fixes: #26018
8 files changed