Support `--config path_to_config.toml` cli syntax.
Updates the `--config` flag so that if the argument appears to be a file, it will load the file.
cc #7722, #7723
Set an environment variable for tests to find executables.
This adds the environment variable `CARGO_BIN_EXE_<name>` so that integration tests can find binaries to execute, instead of doing things like inspecting `env::current_exe()`.
The use of uppercase is primarily motivated by Windows whose Rust implementation behaves in a strange way. It always ascii-upper-cases keys to implement case-insensitive matching (which loses the original case). Seems less likely to result in confusion?
Closes#5758.
Rework internal errors.
This changes the behavior of "internal" errors, which were previously hidden and only displayed with `--verbose`. The changes here:
- `internal` now means "a cargo bug", and is always displayed and requests that the user file a bug report.
- Added `VerboseError` to signify an error that should only be displayed with `--verbose`. This is only used in one place, to display the `rustc` compiler command if the compiler exited with a normal error code (i.e. not a crash).
- Audited the uses of internal errors, and promoted some to normal errors, as they seemed to contain useful information, but weren't necessarily bugs in cargo.
- Added some details to some errors.
- Sometimes the "run with --verbose" message wasn't being printed when I think it should. This happened when rustc failed while other rustc processes were running. Another case was with `cargo install` installing multiple packages, and one of them fails.
Improvements to StringList config handling.
`StringList` was using an untagged enum to deserialize a string or list. Unfortunately, serde does not handle untagged enums very well. The error messages are not very good, and it doesn't interact with untyped deserializers (like our environment variables). This switches it to a newtype struct, and then has hard-coded support for it in the deserializer. This fixes some deserialization errors (like treating `true` as a boolean) and provides better error messages.
`StringList` is currently used for `build.rustflags`, `target.*.rustflags`, and `target.*.runner`.
Fixes#7780Fixes#7781
Add new/old rustflags to fingerprint log.
Follow up to #7888. Due to a conversation with someone I had with Discord who was having trouble determining why something was rebuilding.
Add some extra fingerprint debug information.
There have been some situations where the existing log info was not sufficient to understand the cause of a rebuild. I hope that this additional information can help with debugging problems.
Fix BuildScriptOutput when a build script is run multiple times.
When I implemented profile build overrides, I created a scenario where a build script could run more than once for different scenarios. See the test for an example.
However, the `BuildScriptOutputs` map did not take this into consideration. This caused multiple build script runs to stomp on the output of previous runs. This is further exacerbated by the new feature resolver in #7820 where build scripts can run with different features enabled.
The solution is to make the map key unique for the Unit it is running for. Since this map must be updated on different threads, `Unit` cannot be used as a key, so I chose just using the metadata hash which is hopefully unique. Most of this patch is involved with the fussiness of getting the correct metadata hash (we want the RunCustomBuild unit's hash). I also added some checks to avoid collisions and assert assumptions.
Update tar.
Updates to the latest tar. rust-lang/rust is currently on 0.4.20. The change I'm most interested in is fixing the TarError cause/source, so that Cargo reports a better error message. Compare:
```
Caused by:
failed to unpack `/…/registry/src/github.com-1ecc6299db9ec823/curl-sys-0.4.25/curl/docs/libcurl/libcurl-multi.3`
```
to the new version:
```
Caused by:
failed to unpack `curl-sys-0.4.25/curl/docs/libcurl/libcurl-multi.3` into `/…/registry/src/github.com-1ecc6299db9ec823/curl-sys-0.4.25/curl/docs/libcurl/libcurl-multi.3`
Caused by:
No space left on device (os error 28)
```
Emit report on error with Ztimings.
Previously the report was not saved on error.
I'm not actually sure this is all that useful. I was using it to gather a picture of what was being built (I wasn't actually interested in the timing data). There might be better ways to accomplish what I wanted, but it's a small change, so probably doesn't hurt.
Fixes#7413.
Format placeholder code when generating a crate
When generating source files in `cargo new` and `cargo init`, try to run `rustfmt` CLI on them.
If it fails, log the error and proceed.
Tests:
* Works for `cargo init --lib`
* No changes in behavior if `rustfmt` is missing
Closes#7656
Generalized `clippy_is_available` and renamed as `command_is_available`.
No checks in `ignores_failure_to_format_source`, it's not supposed to
use `rustfmt` even if it's available
Fix rebuild_sub_package_then_while_package on HFS.
This test was flaky on HFS ([azure failure](https://dev.azure.com/rust-lang/cargo/_build/results?buildId=20144&view=logs&j=a5e52b91-c83f-5429-4a68-c246fc63a4f7&t=d4864165-4be3-5e34-b483-a6b05303aa68&l=2018)), resulting in this error:
```
Compiling foo v0.0.1 (/Users/runner/runners/2.164.7/work/1/s/target/cit/t750/foo)
error[E0460]: found possibly newer version of crate `b` which `a` depends on
--> src/lib.rs:1:1
|
1 | extern crate a; extern crate b; pub fn toplevel() {}
| ^^^^^^^^^^^^^^^
|
= note: perhaps that crate needs to be recompiled?
= note: the following crate versions were found:
crate `b`: /Users/runner/runners/2.164.7/work/1/s/target/cit/t750/foo/target/debug/deps/libb-98160c67a5811c37.rlib
crate `b`: /Users/runner/runners/2.164.7/work/1/s/target/cit/t750/foo/target/debug/deps/libb-98160c67a5811c37.rmeta
crate `a`: /Users/runner/runners/2.164.7/work/1/s/target/cit/t750/foo/target/debug/deps/liba-7d2b9ccd932a36e9.rmeta
```
There are two race-condition bugs here.
Race 1: The second cargo build command (`cargo build -pb`) would sometimes not build, because it thought `b` is fresh. This can happen when the first build finishes and changing `b/src/lib.rs` happen within the same second. (#5918) The test silently ignored this failure, this is not the cause of the CI failure, though.
Race 2: The first and second build commands work as expected. The third build command fails because it thinks both `a` and `b` are "fresh". However, `b` was just rebuilt, and `a` depends on it, so `a` should have been rebuilt. It thinks `a` is fresh because `a`'s mtime is equal to `b` when `b` finishes compiling within the same second that the first build finished.
The solution here is to make sure the second step happens well after the first. The underlying problem is #5918.
Fix required-features using renamed dependencies.
The dep_name/feat_name syntax in required-features should use the "name in toml" for dep_name, not the actual package name. Otherwise, it is impossible to actually enable the feature (because the `--features` flag expects a "name in toml").
Fix build-std collisions.
`build-std` unit filenames can collide with user dependencies in some situations. In particular, `cc` as a build-dependency is likely to be exactly the same as a user's dep. This would result in the `cc` crate being built twice, but with the same filename, causing a collision.
Other dependencies typically never collide because they have the `rustc-dep-of-std` feature, but build-dependencies do not.
The solution here is to include `is_std` in the metadata hash.
Fixes#7859.
Fix using global options before an alias.
Options before an alias were being ignored (like `cargo -v b`). The solution is to extract those global options before expanding an alias, and then merging it later.
An alternative to this is to try to avoid discarding the options during expansion, but I couldn't figure out a way to get the position of the subcommand in the argument list. Clap only provides a way to get the arguments *following* the subcommand.
I also cleaned up some of the code in `Config::configure`, which was carrying some weird baggage from previous refactorings.
Fixes#7834
Stabilize config-profile.
This is a proposal to stabilize config-profiles. This feature was proposed in [RFC 2282](https://github.com/rust-lang/rfcs/pull/2282) and implemented in #5506. Tracking issue is rust-lang/rust#48683.
This is intended to land in 1.43 which will reach the stable channel on April 23rd.
This is a fairly straightforward extension of profiles where the exact same syntax from `Cargo.toml` can be specified in a config file. Environment variables are supported for everything except the `package` override table, where we do not support the ability to read arbitrary keys in the environment name.