Commit graph

3010 commits

Author SHA1 Message Date
Roman Volosatovs 4677a7cce5
test: reproduce transitive bindep dependency bug
This is a unit test reproducing the bindep transitive dependency bug based upon examples from
- https://github.com/rust-lang/cargo/issues/10837
- https://github.com/rust-lang/cargo/issues/11463

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
2022-12-22 14:45:21 +01:00
bors 74c7aab19a Auto merge of #11499 - willcrichton:example-analyzer, r=weihanglo
Don't scrape examples from library targets by default

### What does this PR try to resolve?

Based on some [early feedback](https://www.reddit.com/r/rust/comments/zosle6/feedback_requested_rustdocs_scraped_examples/) about the scrape-examples feature, both documentation authors and consumers did not consider examples useful if they are scraped from a library's internals, at least in the common case. Therefore this PR changes the default behavior of `-Zrustdoc-scrape-examples` to *only* scrape from example targets, although library targets can still be configured for scraping.

### How should we test and review this PR?

I have updated the `docscrape` tests to reflect this new policy, as well as the Unstable Options page in the Cargo book.

r? `@weihanglo`
2022-12-20 21:10:16 +00:00
Will Crichton eb829cfb35 Improve failed scrape diagnostic 2022-12-20 12:13:41 -08:00
bors 1d8cdaa01e Auto merge of #11494 - ehuss:stabilize-diagnostic-width, r=weihanglo
Stabilize terminal-width

This stabilized the passing of the `--diagnostic-width` flag to rustc and rustdoc so that they will format diagnostics to fit within the terminal size. Previously they always assume the width is 140. The diagnostics are trimmed with `...` to elide parts of extra-long lines.

In cases where the width isn't known (such as not when used on a tty, or with mintty), then cargo does not pass the flag and the default of 140 is still used.

At this time there is no way for the user to override the width (unlike with the progress bar width). That can be added in the future if there is demand. https://github.com/rust-lang/rust/issues/84673#issuecomment-1179096971 contains some thoughts on some different ideas.

Closes https://github.com/rust-lang/rust/issues/84673
2022-12-19 22:00:52 +00:00
Eric Huss 1709f0aee2 Stabilize terminal-width 2022-12-19 12:17:52 -08:00
bors 3f6c685285 Auto merge of #11477 - kylematsuda:workspace_lockfile, r=weihanglo
Use workspace lockfile when running `cargo package` and `cargo publish`

### What does this PR try to resolve?

Fix #11148.

### How should we test and review this PR?

Please run the integration test in `tests/testsuite/publish_lockfile.rs` or try the steps from the issue.
2022-12-19 18:16:27 +00:00
Kyle Matsuda 8c4f27fd5b make test clearer 2022-12-19 10:50:55 -07:00
Will Crichton 818debbf90 Don't scrape examples from library targets by default 2022-12-18 22:15:08 -08:00
Will Crichton d588298c3f Fix examples of proc-macro crates being scraped for examples 2022-12-18 10:41:21 -08:00
Weihang Lo 0523f42cc2
Revert "temporarily disable test lto::test_profile"
This reverts commit d5cac16d07.
2022-12-17 22:51:57 +00:00
Eric Huss b1bcc9c834 Fix collision_doc_profile test error 2022-12-15 20:04:50 -08:00
Scott Schafer 33c32088fa fix: Make auto-fix note work with clippy 2022-12-15 10:54:35 -06:00
Philpax 249683b456
fix(tests): update to match add change 2022-12-15 09:34:23 +01:00
bors cc0a320879 Auto merge of #11434 - weihanglo:issue/10526, r=ehuss
artifact deps should works when target field specified coexists with `optional = true`
2022-12-14 14:46:57 +00:00
Kyle Matsuda 4d86b26a68 fix test 2022-12-12 15:47:31 -07:00
Kyle Matsuda 4cda74a1a3 add test with current behavior 2022-12-12 11:07:43 -07:00
bors 4a8d17e236 Auto merge of #11450 - willcrichton:example-analyzer, r=weihanglo
Allow Check targets needed for optional doc-scraping to fail without killing the build

### What does this PR try to resolve?

In doing a Crater run of -Zrustdoc-scrape-examples, I found that the only remaining regressions are cases where:
* A library does not type-check
* The library has examples
* Cargo tries to scrape the examples, which requires checking the library
* The Check unit for the library fails, crashing the build

The core issue is that the Check unit should be able to fail without killing the build. This PR fixes this issue by checking for this condition, and then allowing the unit to fail.

Specifically, I added a new method `BuildContext::unit_can_fail_for_docscraping` that determines the conditions for whether a unit is allowed to fail. This method is used both in `JobQueue` to interpret process failure, and in the `rustc`/`rustdoc` functions to emit a warning upon failure. I modified `rustc` to handle the case of failure similar to `rustdoc`, but with a slightly different diagnostic.

### How should we test and review this PR?

The unit test `no_fail_bad_lib` has been extended with example files to test this case.

r? `@weihanglo`
2022-12-11 22:27:21 +00:00
bors 9c8e8a9abb Auto merge of #11323 - weihanglo:issue/11310, r=ehuss
fix: gleaning rustdocflags from `target.cfg(…)` is not supported

### What does this PR try to resolve?

Fixes #11310

The bug was `rustflags_from_target` trying to learn rustdocflags from
`target.cfg(…).rustflags`, which is definitely wrong.

As of this writing, either `target.cfg(…).rustdocflags` or
`target.<triple>.rustdocflags` is not supported.

### How should we test and review this PR?

See f8d1b30ad3 as an example.
<!-- homu-ignore:end -->
2022-12-11 16:52:06 +00:00
Weihang Lo 5b8985a470
fix(bindeps): assumed host target and optional = true coexist
`{ …, artifact = "bin", target = "target" }` should also be considered
to being built for `FeaturesFor::ArtifactDep` instead of `NormalOrDev`.

[This line][1] requests for `ArtifactDep` but [here][2] Cargo ignore
assumed host target of artifact dep.

Change it to explicit set host target triple when

- `{ …, target = "target" }`, and
- `--target` is not presented, meaning it would be build on host platform.

[1]: 1382b44e43/src/cargo/core/compiler/unit_dependencies.rs (L887)
[2]: 1382b44e43/src/cargo/core/resolver/features.rs (L857)
2022-12-04 11:43:50 +00:00
Weihang Lo bf56587e26
fix(bindeps): target field specified and optional = true coexist
> Adapted from #11183

Previously, `is_dep_activated` depends on `activated_dependencies`,
which is a map of `PackageFeaturesKey` to its own activated `DepFeature`s.
`PackageFeaturesKey` in feature resolver is always comprised of

* A `PackageId` of a given dependency, and
* A enum value that helps decoupling activated features for that dependency.
  Currently depending on the type of given dependency.

Looking into issue 10526, it has an `activated_dependencies` of

```
{
    (mycrate, NormalOrDev) -> [dep:mybindep]
}
```

However, this [line][1] accidentally use a parent's `pkgid`
and a dependency's `FeaturesFor` to compose a key:

```
(mycrate, ArtifactDep("x86_64-unknown-linux-gnu"))
```

That is never a valid key to query features for artifacts dependency.
A valid key should be comprised of components both from the parent:

```
(mycrate, NormalOrDev)
```

Or both from the dependency itself:

```
(mybindep, ArtifactDep("x86_64-unknown-linux-gnu"))
```

This `unit_for` is from parent and should already contain its own
artifact dep information inside `artifact_target_for_features`,
so we don't need to map any dependency artifact from `dep.artifact()`.

[1]: a2ea66bea6/src/cargo/core/compiler/unit_dependencies.rs (L1106-L1107)
2022-12-04 11:41:49 +00:00
Weihang Lo 7dcb6daa7d
test(bindeps): assumed host target and optional = true coexist 2022-12-04 11:41:49 +00:00
Weihang Lo 437bed069a
test(bindeps): target field specified and optional = true coexist 2022-12-04 11:41:49 +00:00
Will Crichton de34d60076 Allow Check targets needed for optional doc-scraping to fail without killing the build 2022-12-03 10:13:33 -08:00
bors 324a935e04 Auto merge of #11299 - hi-rustin:rustin-patch-target-warn, r=weihanglo
Improve file found in multiple build targets warning

### What does this PR try to resolve?

close https://github.com/rust-lang/cargo/issues/11248.
Improve file found in multiple build targets warning. This PR tries to print the target name and kind in the warning message.

### How should we test and review this PR?

- [x] Unit Test
2022-12-02 10:25:49 +00:00
hi-rustin 7eadd58eef Update duplicate build targets test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-12-01 08:58:52 +08:00
bors 7b9069e8f9 Auto merge of #11349 - hi-rustin:rustin-patch-error-cli, r=weihanglo
Error when precise without -p flag

### What does this PR try to resolve?

close https://github.com/rust-lang/cargo/issues/10919

Follow up https://github.com/rust-lang/cargo/pull/10988, see https://github.com/rust-lang/cargo/issues/10919#issuecomment-1214464756

### How should we test and review this PR?

You can manually build and test it. You can try `cargo update --precise xxx` without -p flag.

### Additional information
It has already been released on stable. `rustc 1.65.0 (897e37553 2022-11-02)`
2022-11-30 09:46:05 +00:00
hi-rustin c51f8ad083 Remove warning for aggressive flag without -p flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-30 09:08:03 +08:00
bors d28c9b8bc1 Auto merge of #11430 - willcrichton:example-analyzer, r=weihanglo
Improve strategy for selecting targets to be scraped for examples

### What does this PR try to resolve?

After #10343, we have identified a clear set of conditions for whether a particular target should be considered by `-Zrustdoc-scrape-examples`. These conditions are described more clearly in #11425.

However, after some testing with complex Cargo workspaces (e.g. [wasmtime](https://github.com/bytecodealliance/wasmtime/)), I realized that the current approach of modifying the `CompileFilter` did not correctly implement this new specification. For example, a target with `doc = false` should not be scraped by default since it is not a documented unit, but the current approach would potentially include such a target for scraping.

This PR provides a new approach which I believe correctly implements the specification:
1. `generate_targets` is called with the same parameters except the `mode` which becomes `CompileMode::Docscrape` instead of `CompileMode::Doc`. `filter_default_targets` generates the same targets for `Docscrape` as for `Doc`.
2. Inside `generate_targets`, an initial set of `Proposal`s are created. This set of proposals is extended with further proposals based on targets identified as `doc-scrape-examples = true`, or Example targets where possible.

This PR subsumes #11423, and also fixes #10571.

### How should we test and review this PR?

I have added another test `docscrape::only_scrape_documented_targets` to verify that only documented or explicitly-enabled targets are included for scraping.

r? `@weihanglo`
2022-11-29 19:59:48 +00:00
bors 0460192d1a Auto merge of #11337 - weihanglo:compression-ratio, r=ehuss
Aware of compression ratio for unpack size limit
2022-11-29 19:10:00 +00:00
Caleb Fletcher f54cd332e2 Add test for rustdoc map usage with sparse alternative registries 2022-11-29 19:28:03 +11:00
bors a2ea66bea6 Auto merge of #11400 - hi-rustin:rustin-patch-fix-error, r=epage
Add error message when `cargo fix` on an empty repo

### What does this PR try to resolve?

close https://github.com/rust-lang/cargo/issues/11380

Add error message when `cargo fix` on an empty repo.

### How should we test and review this PR?

- [x] unit test

```sh
set -eux

cargo +nightly new repro
cd repro
echo "fn main() { let _ = 0.clone(); }" > src/main.rs
cargo fix
```
2022-11-28 13:01:15 +00:00
Will Crichton 968caae025 Remove outdated check on scrape units, add test for doc = false 2022-11-27 11:57:56 -06:00
bors a004f94c48 Auto merge of #11387 - arlosi:sparse-url, r=weihanglo
Store the sparse+ prefix in the SourceId for sparse registries

#11209 added a new `SourceKind::SparseRegistry` and removed the `sparse+` prefix from the URLs stored in the `SourceId`.

The removal of the `sparse+` prefix from the URLs in the `SourceId` has led to several bugs, since registry URLs no longer round-trip through a `SourceId`. The most recent one I found was that the example configuration generated by `cargo vendor` did not include the `sparse+` prefix. Any place that calls the `.url()` method on a `SourceId` potentially has this bug.

This change puts the `sparse+` prefix back in the URL stored in the `SourceId`, but keeps the new `SourceKind::SparseRegistry`.

A test is added for doing `cargo vendor` on an alternative registry using the sparse protocol.
2022-11-27 16:00:17 +00:00
hi-rustin 21b2fe98a4 Fix fix_in_existing_repo_weird_ignore broken test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-26 20:15:36 +08:00
hi-rustin 3189dc3b06 Include untracked files
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-26 20:15:36 +08:00
hi-rustin 25f7d4b09a Remove new_repo_without_add_and_commit
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-26 20:15:36 +08:00
hi-rustin 89b8a8bb10 Suppress error with --allow-dirty and add a test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-26 20:15:36 +08:00
bors 79fe7573b0 Auto merge of #11401 - adam248:patch-1, r=ehuss
add newline char to `cargo install .` error message for easier reading.

I just noticed the `cargo install .` error message was not formatted very nicely.

Just added a newline char to make it cleaner.

Thanks
2022-11-25 13:34:10 +00:00
bors de56c1251b Auto merge of #10343 - willcrichton:example-analyzer, r=weihanglo
Change rustdoc-scrape-examples to be a target-level configuration

This PR addresses issues raised in rust-lang/cargo#9525. Specifically:
1. It enables examples to be scraped from `#[test]` functions, by passing additional flags to Rustdoc to ensure that these functions aren't ignored by rustc.
2. It moves the `arg` from `-Z rustdoc-scrape-examples={arg}` into a target-level configuration that can be added to Cargo.toml.

The added test `scrape_examples_configure_target` shows a concrete example. In short, examples will be default scraped from Example and Lib targets. Then the user can enable or disable scraping like so:

```toml
[lib]
doc-scrape-examples = false

[[test]]
name = "my_test"
doc-scrape-examples = true
```
2022-11-25 06:58:20 +00:00
Weihang Lo d5cac16d07
temporarily disable test lto::test_profile
- CI failing
  - <https://github.com/rust-lang/cargo/actions/runs/3542820690/jobs/5948722067>
  - <https://github.com/rust-lang/cargo/actions/runs/3535399031/jobs/5933377592>
- Tracking in <https://github.com/rust-lang/rust/issues/104852>
- Discussing in <https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/windows.20gnu.20LTO.20CI.20error>
2022-11-25 01:04:49 +00:00
Will Crichton 183425f0bc Add test to confirm #10876 is fixed. 2022-11-23 09:35:59 -06:00
Will Crichton c26ed6357f Add doc comments to explain scrape-examples feature 2022-11-22 15:19:18 -06:00
bors 995f5efcc2 Auto merge of #11186 - hi-rustin:rustin-patch-add-suggestion, r=epage
Add suggestions when `cargo add` multiple packages

### What does this PR try to resolve?

close https://github.com/rust-lang/cargo/issues/11173
Add suggestions when `cargo add` multiple packages. See https://github.com/rust-lang/cargo/issues/11173#issuecomment-1265692022

### How should we test and review this PR?

- [x] unit test
2022-11-22 14:10:58 +00:00
Adam Butler 1b7e256413 fixed typo causing broken cargo install . test case 2022-11-22 14:14:29 +09:30
Adam Butler db0d3f9de1
fixed cargo fmt error regarding unknown escape char. 2022-11-22 13:24:59 +09:30
Adam Butler c5836e97ba
fixed broken error made by newline char in cargo install . error message 2022-11-22 13:19:05 +09:30
hi-rustin a3eb31fab4 Fix typo try use -> try to use
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-20 18:14:17 +08:00
bors 63fdd75bde Auto merge of #11377 - hi-rustin:rustin-patch-warning-tree, r=weihanglo
Add warning when `cargo tree -i <spec>` can not find packages

### What does this PR try to resolve?

close https://github.com/rust-lang/cargo/issues/11315

Add warning when `cargo tree -i <spec>` can not find packages.

### How should we test and review this PR?

Please run the unit test.
2022-11-20 08:52:04 +00:00
hi-rustin c5eb61823c Remove the --all-features tip
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-11-20 16:39:00 +08:00
bors 43689d353a Auto merge of #11194 - cassaundra:cargo-remove-gc, r=epage
Clean profile, patch, and replace in cargo remove

### What does this PR try to resolve?

This PR is part of the continued work on cargo remove (#11099, see deferred work).

After a successful removal of a dependency, clean up the profile, patch, and replace sections to remove all references to it.

**Note** the GC process was expanded to clean up not just references to the dependencies just removed, but also references of all dependencies. This was because there's not an easy way to determine which dependencies correspond to the given TOML keys, without either 1) figuring that out before the removal (therefore having to predict the behavior), or 2) returning that information from the remove function (somewhat unorthodox for an op).

### How should we review and test this PR?

Verify that the implementation makes sense and that the tests are sufficient.
2022-11-19 02:46:46 +00:00