Better error message when VCPKG_ROOT is independently defined #7229
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the VCPKG_ROOT environment variable is defined incorrectly - i.e., does not point to the 'vcpkg' root directory - the current error message provides no insight into the real cause of the problem.
I just lost 10 hours debugging this issue. It does make sense for end-users to define an environment variable called 'VCPKG_ROOT' independently of actually running vcpkg, as I did - to indicate to my downstream application the location of the 'include' path created for a 3rd-party library when vcpkg installed it (which happens to be located inside the vkpkg root directory by default - in the /installed/.../include directory).
Unfortunately, defining the 'VCPKG_ROOT' independently, as I did, caused complete failure of vcpkg to run, giving the current useless error "Changing the working dir failed". (...The path <vcpkg/installed/.../include> is not the root directory of vcpkg, and in fact does not even exist when the vcpkg repository is cloned.)
It would be immensely helpful to receive a proper error message alerting a programmer to the real likely cause of this error - i.e., alerting the programmer to the fact that the VCPKG_ROOT environment variable is reserved for use by 'vcpkg' itself, and should not be used by end-users for alternate purposes. (I have also included the other potential error condition - an improperly created '.vcpkg-root' file - for completeness, though it seems less likely this would be the issue.)
The current error message addresses this issue, and I hope will be accepted into the library to save some other poor soul such as myself an entire lost day should they mistakenly create an environment variable called 'VCPKG_ROOT' pointing to the install target location inside the actual vkpkg root directory.