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.
Update pretty_env_logger requirement from 0.3 to 0.4
Updates the requirements on [pretty_env_logger](https://github.com/seanmonstar/pretty-env-logger) to permit the latest version.
<details>
<summary>Commits</summary>
<ul>
<li><a href="fa4e28537f"><code>fa4e285</code></a> v0.4.0</li>
<li><a href="693b5e7088"><code>693b5e7</code></a> Remove chrono dependency</li>
<li><a href="28c5ad0cbb"><code>28c5ad0</code></a> env_logger: 0.6.2 -> 0.7.0</li>
<li><a href="0288e4ed4b"><code>0288e4e</code></a> fixes env goof in README.md</li>
<li><a href="76d9fc7606"><code>76d9fc7</code></a> Make env_logger dependency public</li>
<li><a href="8ddffae2c5"><code>8ddffae</code></a> v0.3.1</li>
<li><a href="04c1aa50e1"><code>04c1aa5</code></a> require latest env_logger</li>
<li><a href="ce8c2f12fb"><code>ce8c2f1</code></a> fix deprecated calls</li>
<li><a href="67d2e7d68b"><code>67d2e7d</code></a> timestamps with milliseconds</li>
<li><a href="27eaa2bc1b"><code>27eaa2b</code></a> fix with_builder_1 example (<a href="https://github-redirect.dependabot.com/seanmonstar/pretty-env-logger/issues/25">#25</a>)</li>
<li>See full diff in <a href="https://github.com/seanmonstar/pretty-env-logger/compare/v0.3.0...v0.4.0">compare view</a></li>
</ul>
</details>
<br />
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
<details>
<summary>Dependabot commands and options</summary>
<br />
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
- `@dependabot badge me` will comment on this PR with code to add a "Dependabot enabled" badge to your readme
Additionally, you can set the following in your Dependabot [dashboard](https://app.dependabot.com):
- Update frequency (including time of day and day of week)
- Pull request limits (per update run and/or open at any time)
- Automerge options (never/patch/minor, and dev/runtime dependencies)
- Out-of-range updates (receive only lockfile updates, if desired)
- Security updates (receive only security updates, if desired)
</details>
Search for root manifest with ephemeral workspaces
Fixes#5495.
This seems like it's too simple to just work like this, but after trying a few different things, this was the only solution which worked reliably for me.
I've verified that no `/target` is present in the actual checkout location, the target directory used is actually the one created in `/tmp`.
I've also verified that both workspaces and "normal" packages still install through git and that a normal `cargo install --path` works too (though that doesn't use ephemeral workspaces anyways).
Test 1: init a library crate with a `rustfmt.toml` config file in it.
Expect the generated source files to be formatted according to the
config file.
Test 2: same as test 1, but with missing `rustfmt`. Expect `cargo init`
to ignore the absence of `rustfmt` and generate source files
with default formatting.
Store maximum queue length
Previously, the queue length was constantly decreasing as we built crates, which
meant that we were incorrectly displaying the progress bar. In debug builds,
this even led to panics (due to underflow on subtraction).
Not sure if we can add a test case for this. I have made the panic unconditional on release/debug though by explicitly checking that current is less than the maximum for the progress bar.
Fixes https://github.com/rust-lang/cargo/pull/7731#issuecomment-578358824.
Previously, the queue length was constantly decreasing as we built crates, which
meant that we were incorrectly displaying the progress bar. In debug builds,
this even led to panics (due to underflow on subtraction).
I think I found the correct place in the algorithm where rustfmt should
be called.
I'm not sure if using `std::process::Command` and converting errors into
warnings is the correct way here.
Also the warning should only be printed once. Unless
`config.shell().warn()` deduplicates warnings, right now there will be
one warning per source file.
So I should probably check that `rustfmt` exists only once and disable
formatting if it doesn't.