ERROR: failed (prepare phase) The source directory '${S}' doesn't exist

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

Sample error:

* ERROR: foo-bar/baz-5.6::some-overlay failed (prepare phase):
*   The source directory '/var/tmp/portage/foo-bar/baz-5.6/work/baz-5.6' doesn't exist
*
* Call stack:
*            ebuild.sh, line  773:  Called __ebuild_main 'prepare'
*   phase-functions.sh, line 1072:  Called __dyn_prepare
*   phase-functions.sh, line  384:  Called die
* The specific snippet of code:
*              die "The source directory '${S}' doesn't exist"
// ...
* Working directory: '/var/tmp/portage/foo-bar/baz-5.6/homedir'
* S: '/var/tmp/portage/foo-bar/baz-5.6/work/baz-5.6'

First, check the value of S printed at the end (the value of the source directory), and carefully compare to any existing directory under /var/tmp/portage/.
Any slight discrepancy in the full path name might give you a clue at the source of the problem.

In EAPI versions before 5, the variable S would default to ${WORKDIR}/${P}. But if ${P} did not exist, the ebuild would silently fall back to the work directory (${WORKDIR}).
Try to set S to ${WORKDIR}.After the DEPEND/RDEPEND variables and before any of the src_* or pkg_* functions, add:

S=${WORKDIR}

If you are testing a custom ebuild, remember to clean before trying again:

ebuild baz-5.6.ebuild clean
ebuild baz-5.6.ebuild install

If it still does not work, you need to investigate and check the exact value of the source directory.