Don't directly assign Pathname objects to environment variables

Fixes #32234.
The build environment should only deal with strings