Auto merge of #4634 - kivikakk:cargo-env-prevails, r=matklad
authorbors <bors@rust-lang.org>
Thu, 26 Oct 2017 07:35:44 +0000 (07:35 +0000)
committerbors <bors@rust-lang.org>
Thu, 26 Oct 2017 07:35:44 +0000 (07:35 +0000)
commitf6ef6349b18f70243428aefd122edda80da7dab1
tree5ca5ee24e25c5801c3905d566b6fe4b17a620270
parentb3ba626305c94777e357527069fb0457d97ad15c
parent1bb43b081afbc76a5589a338ce10c5267c5ff256
Auto merge of #4634 - kivikakk:cargo-env-prevails, r=matklad

Use argv[0] for cargo_exe so we don't rely on /proc on Linux

This is a proposed solution to #4450. I'm not at all wedded to the idea or the code, though, so feel free to shoot it down with abandon if this isn't something that'd work out or that you like.

In short, we use the existing `CARGO_ENV` (`"CARGO"`) if present, and only if not do we attempt to perform a lookup with `env::current_exe()` ourselves. This means users without access to `current_exe` (such as Linux without `procfs` mounted) can supply the `CARGO` env var themselves for external commands to use.

My concern here is: what if maybe we intentionally switch cargo binaries and didn't intend for this to happen? Could this ever happen outside a test environment? This kind-of-sorta-happened by accident in the test suite, necessitating the explicit removal of `CARGO_ENV` from the subprocess environment, because the actual cargo executing the test suite propagated its own path into the test subprocess!

/cc @alexcrichton as the originator of the idea of `CARGO_ENV`