mcompile: fix broken codepaths and restore orphaned code
mcompile: fix broken codepaths and restore orphaned code

In commit 928078982c8643bffd95a8da06a1b4494fe87e2b a good error message
about the directory not being a valid build directory, was replaced by a
worse message.

In commit abaa980436f53100041bd5535589bb1c42019bd6 the error message was
replaced by a traceback when trying to load the coredata before checking
if it was a build directory.

Revert back to using the helper function with the good error message.
Reorganize code so that we check basic things first, and do less work
before detecting errors.

Fixes #9584

pexip/meson,pexip/meson,mesonbuild/meson,mesonbuild/meson,pexip/meson,mesonbuild/meson,pexip/meson,pexip/meson,mesonbuild/meson,pexip/meson,mesonbuild/meson,pexip/meson,pexip/meson,mesonbuild/meson,pexip/meson,mesonbuild/meson,mesonbuild/meson,pexip/meson,mesonbuild/meson,mesonbuild/meson