Commit graph

2936 commits

Author SHA1 Message Date
Ed Page be257b8b25 fix(add): Remove redundant version in build metadata cases 2022-09-12 09:51:38 -05:00
Ed Page 7ce2b7d42a fix(add): Limit 'Features as of vX.Y.Z' to when relevant
This will only show the messaeg if we didn't already show a version req
with full precision specified ... mostly.  We'll also skip it if its a
local or git dependency but we never show the version in those cases
because it doesn't matter.

The `precise_version` logic came from cargo-upgrade.
2022-09-12 09:46:22 -05:00
Ed Page 73906aeaf8 fix(add): Clarify which version the features are added for
This gives a hint to users that we might not be showing the feature list
for the latest version but the earliest version.

Also when using a workspace dependency or re-using an existing
dependency, this is a good reminder of what the version requirement is
that was selected.

However, when the user or add (the common case) selected a full
precision requirement, this is redundant.

I'm also mixed on whether the meta version should show up.

Fixes #11073
2022-09-12 09:39:47 -05:00
Dawid Ciężarkiewicz c712f08862 Do not add home bin path to PATH if it's already there
This is to allow users to control the order via PATH if they so desire.

Fix #11020
2022-09-08 09:37:41 -07:00
bors 646e9a0b9e Auto merge of #10511 - weihanglo:issue-10477, r=ehuss
Support inheriting jobserver fd for external subcommands
2022-09-02 14:29:28 +00:00
Eric Huss 23735d4c09 Rework test error handling 2022-08-27 19:23:30 -07:00
BlackHoleFox b676088572 Update non-ASCII crate name warning message 2022-08-23 14:23:59 -05:00
hi-rustin 64e3991907 Remove useless log deps and add more test for precise update
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-21 17:16:01 +08:00
hi-rustin f0b5bdad65 Add test for aggressive update
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-21 17:14:07 +08:00
Weihang Lo 52a418c516
test: ignore broken but excluded file during traversing 2022-08-20 00:56:43 +01:00
hi-rustin 99b3564d0d Update old tests
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-19 10:56:29 +08:00
hi-rustin a58489dfbb Add test for aggressive update
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-17 21:53:12 +08:00
hi-rustin f95deaafeb Warning when precise or aggressive without -p flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-17 21:53:07 +08:00
bors 9809f8ff33 Auto merge of #10944 - kcrimson-ar:master, r=epage
Improve error message for an array value in the manifest

Fixes https://github.com/rust-lang/cargo/issues/10942

The error message will be:

```
error: failed to parse manifest at `/Users/..`

Caused by:
  invalid type: string "Ky", expected an array for key `package.authors`
```
2022-08-16 22:10:06 +00:00
bors 34cba461f2 Auto merge of #10930 - ehuss:enable-windows-tests, r=weihanglo
Enable two windows tests

These two tests were disabled on Windows a long time ago. AFAICT, the reasons are no longer relevant, and it should be safe to enable these tests. See each commit for a more detailed exposition.
2022-08-11 22:30:26 +00:00
bors 1ac43cf649 Auto merge of #10968 - hi-rustin:rustin-patch-msg, r=ehuss
Improve error msg for get target runner

Actually, we'll get this config from three places. So this msg may be confusing when you set it up in `.cargo/config.toml` or pass it by `--config`.
We already printed the location of the config, so I think it's OK to change it to `configurations`.
2022-08-11 03:23:09 +00:00
hi-rustin 6bb4050552 Fix test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-10 23:19:35 +08:00
bors 1fcbca84ee Auto merge of #10961 - Nemo157:skip-implicit-override, r=epage
Only override published resolver when the workspace is different

### What does this PR try to resolve?

Ensures when publishing a package that uses an implicit `resolver = "1"` to maintain an MSRV before the `resolver` key was stabilized the implicitness is retained rather than being turned into an explicit setting.

fixes #10954 (assuming that the workspace and its packages are configured with a consistent resolver)
2022-08-10 14:30:11 +00:00
Wim Looman 492358a19f
Only override published resolver when the workspace is different 2022-08-10 09:26:50 +02:00
Josh Triplett 934e79072a Only show advice to use cargo update --precise for non-local packages
Packages in the local workspace can't get updated this way; the user
just needs to point to a different source, or otherwise update the
package themselves.
2022-08-08 10:37:15 -07:00
Josh Triplett dcbb433340 Make the rust-version error recommend cargo update -p crate@ver --precise ...
People encountering a dependency with a newer `rust-version` requirement
may not know about `cargo update --precise`, or may consider alternate
approaches that may be harmful (such as pinning with a `=` dependency).

Provide specific guidance in the error message.

If the user is using `cargo install`, suggest `cargo install --locked` instead.
2022-08-08 10:37:15 -07:00
Ky Phan 8f1a75d584 Add unit test for invalid authors, refactor name 2022-08-08 22:05:43 +07:00
bors 7259757dc6 Auto merge of #10322 - eholk:reserved-windows-name, r=ehuss
Test if reserved filenames are allowed in Windows

Recent versions of Windows have removed the limitation on filenames like `aux` or `con`. This change allows the `package::reserved_windows_name` to still pass by first trying to create a file with a reserved name to see if Windows supports it. If so, it skips the rest of the test. Otherwise, we keep the same behavior as before.
2022-08-04 00:32:49 +00:00
Eric Holk e9c7544c19 Move Windows path test function to test code 2022-08-03 15:59:59 -07:00
Eric Holk f122dbbd41 Use GetFullPathNameW to test restricted names
The previous commit tests whether the current machine supports Windows
restricted names by creating a file and checking whether that succeeds.
This commit reworks this testto use GetFullPathNameW, which can be done
without having to create and remove new files.
2022-08-03 15:59:58 -07:00
Eric Holk 0adcc183bc Test if reserved filenames are allowed in Windows
Recent versions of Windows have removed the limitation on filenames like
`aux` or `con`. This change allows the `package::reserved_windows_name`
to still pass by first trying to create a file with a reserved name to
see if Windows supports it. If so, it skips the rest of the test.
Otherwise, we keep the same behavior as before.
2022-08-03 15:59:58 -07:00
akabinds 222d90b78e test checking full stderr output, with new message, resulting from a "did you mean" 2022-08-03 11:38:41 -05:00
akabinds 8f5f2ed2a2 implement test checking if stderr, after using +toolchain, contains message stating that the directive is not handled by Cargo 2022-08-03 11:07:17 -05:00
akabinds 13776d2c59 Merge branch 'master' of https://github.com/rust-lang/cargo into better-no-such-subcommand 2022-08-03 10:53:47 -05:00
akabinds b1829b8dbd Merge branch 'master' of https://github.com/rust-lang/cargo into better-no-such-subcommand 2022-08-03 10:17:56 -05:00
Eric Huss 8bf7b8b89b Revert "Drop check for mingw32-make."
This reverts commit 8e35e2f044.
2022-08-03 06:59:35 -07:00
bors 333478d0aa Auto merge of #10929 - ehuss:ignore-reason, r=weihanglo
Add reasons to all ignored tests.

This adds a reason string to all `#[ignore]` attributes. This will be displayed when running the test (since 1.61), which can help quickly see and identify why tests are being ignored. It looks roughly like:

```
test basic ... ignored, requires nightly, CARGO_RUN_BUILD_STD_TESTS must be set
test build::simple_terminal_width ... ignored, --diagnostic-width is stabilized in 1.64
test check_cfg::features_with_cargo_check ... ignored, --check-cfg is unstable
test plugins::panic_abort_plugins ... ignored, requires rustc_private
```
2022-08-03 03:54:05 +00:00
binds adf5441b7a
Merge branch 'master' into better-no-such-subcommand 2022-08-02 20:47:20 -07:00
lucas 02e606d799 Grammar fixup unused patch message 2022-08-03 02:22:50 +01:00
akabinds 5f3ded124f stop mixing of newlines and \n in tests 2022-08-02 19:43:16 -05:00
akabinds 42df87409b fix formatting 2022-08-02 18:27:36 -05:00
akabinds b2f44de83d implemented requested changes; tests pass 2022-08-02 18:23:55 -05:00
Eric Huss c0be32b5de Re-enable version_works_without_rustc on windows.
This test was ignored in https://github.com/rust-lang/cargo/pull/3189
without much discussion of explaining why.

AFAICT, this test works fine on Windows on both MSVC and GNU.
Empty paths do the expected behavior (preventing cargo from running
rustc). There are some special rules on Windows about discovering the
process to run (such as searching the app's launch directory), but
I do not think that is relevant here. Confirmed by trying to run
`cargo check` in this test fails to find `rustc`.
2022-08-02 12:54:16 -07:00
Eric Huss 01747aa145 Re-enable killing_cargo_releases_the_lock on windows.
AFAICT, we do not test on these older platforms anymore.
Regardless, the test seems to work fine on 32-bit windows-gnu
on Windows 10.

See https://github.com/rust-lang/cargo/pull/3102#issuecomment-260815269
where it was originally disabled.
2022-08-02 12:30:42 -07:00
Eric Huss 7eb007ddbf Add reasons to all ignored tests. 2022-08-02 12:24:00 -07:00
akabinds ba3de81017 Merge branch 'better-no-such-subcommand' of https://github.com/akabinds/cargo into better-no-such-subcommand 2022-08-02 13:01:36 -05:00
akabinds b55e8d47a9 implemented requested changes; fixed one failing test (need to fix other) 2022-08-02 13:01:32 -05:00
bors 0fb9e85e45 Auto merge of #10918 - ehuss:fix-formats_source, r=Eh2406
Fix formats_source test requiring rustfmt.

The requirements added in #9892 that `rustfmt` must be present doesn't work in the `rust-lang/rust` environment. There are two issues:

* Cargo is run without using rustup. If you also have rustup installed, the test will fail because the `rustfmt` binary found in `PATH` will fail to choose a toolchain because HOME points to the sandbox home which does not have a rustup configuration.
* rust-lang/rust CI uninstalls rustup, and does not have rustfmt in PATH at all.  It is not practical to make rustfmt available there.

The solution here is to just revert the behavior back to where it was where it checks if it can run `rustfmt` in the sandbox. This should work for anyone who has a normal rustup installation (including Cargo's CI). If running the testsuite without rustup, then the test will be skipped.

This also includes a small enhancement to provide better error information when rustfmt fails.
2022-08-02 14:41:51 +00:00
Eric Huss e8d92919cf Disable scrape_examples_complex_reverse_dependencies 2022-08-02 06:57:34 -07:00
Eric Huss 15f9c2dc06 Fix formats_source test requiring rustfmt. 2022-08-01 21:07:19 -07:00
bors 223e84a981 Auto merge of #10844 - yerke:yerke/negative_jobs, r=ehuss
Support for negative --jobs parameter, counting backwards from max CPUs

Fixes #9217.

Continuation of https://github.com/rust-lang/cargo/pull/9221.
2022-08-01 03:41:10 +00:00
Yerkebulan Tulibergenov 767368fd02 Merge branch 'master' into yerke/negative_jobs 2022-07-31 18:21:33 -07:00
Eric Huss 8e35e2f044 Drop check for mingw32-make.
From what I can tell, it is no longer necessary on GitHub Actions.
This removes it to help simplify things.
2022-07-31 16:06:25 -07:00
Eric Huss bcf982cf24 Add missing requires_git requirements. 2022-07-31 15:19:17 -07:00
Eric Huss 9d43ffc02a Remove CARGO_TEST_DISABLE_GIT_CLI
This appears to no longer be necessary since we have migrated to
GitHub Actions.
2022-07-30 19:36:58 -07:00
Eric Huss 1c3640e05c Add requirements to cargo_test. 2022-07-30 19:36:58 -07:00
Wim Looman d953c3b2d7
Override to resolver=1 in published package 2022-07-29 16:03:05 +02:00
Ed Page 5789c12e45 fix(add): Update the lock file
This is done in the command, rather than in the op,
- To consistently construct the `Workspace`
- It is more composable as an API

A downside is we update the git dependencies a second time.

We are not rolling back on error.
- For some errors, the user might want to debug what went wrong
- Rollback adds its own complications and risks, including since its
  non-atomic

Fixes #10901
2022-07-26 14:59:07 -05:00
Ed Page 323c7bc306 test(add): Make test data valid
Resolving the manifests will fail due to inconsistencies.  This
addresses those.
2022-07-25 11:06:12 -05:00
Ed Page b5c4a765ef fix(add): Respect --locked
This is prep for #10901 to avoid the most common failure case for the
lock file.  We are assuming if the users action caused a change in the
manifes, then it will cause a change in the lock file.  This isn't
entirely true but close enough and I think these semantics can make
sense.
2022-07-25 09:52:00 -05:00
Eric Huss 8a487abedd Make the empty rustc-wrapper test more explicit. 2022-07-24 13:10:35 -07:00
Scott Schafer 2c810afda9 Stabilize workspace inheritance 2022-07-23 09:36:49 -05:00
Eric Huss cde8f6f692
Merge branch 'master' into stabilize-crate-type 2022-07-17 13:14:44 -07:00
Weihang Lo db3b5801d7
Update tests to reflect -Zmultitarget stabilization 2022-07-17 11:02:01 +01:00
bors 576356f414 Auto merge of #10668 - weihanglo:issue-10652, r=ehuss
Normalize path for `cargo vendor` output
2022-07-16 22:41:57 +00:00
Weihang Lo f128cbd5da
Stabilize --crate-type flag for cargo rust 2022-07-16 23:25:55 +01:00
bors bd5db301b0 Auto merge of #10868 - Muscraft:add-reason-for-nightly-tests, r=ehuss
add a reason to `masquerade_as_nightly_cargo` so it is searchable

When I was working on the stabilization for workspace inheritance, it was very tedious to find all of the places to remove `.masquerade_as_nightly_cargo()`. I [suggested](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/problems.20finding.20.60.2Emasquerade_as_nightly_cargo.28.29.60) to add a reason to `.masquerade_as_nightly_cargo()` so that it would be easier to find all of the places to remove it. By adding the reason it makes it easy to search for all places with the features name. This PR adds the reason(s) to all of the places `.masquerade_as_nightly_cargo()` is called, as well as updates the documentation so it talks about adding a reason when making the call.
2022-07-16 18:36:58 +00:00
Scott Schafer c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05:00
bors 6fc517b1c3 Auto merge of #10784 - tedinski:fix-10783, r=epage
Allow '.' in workspace.default-members in non-virtual workspaces.
2022-07-16 02:32:05 +00:00
Scott Schafer 4bc8fe85bd remove unneeded nightly flags from various tests 2022-07-14 19:55:44 -05:00
Scott Schafer 22721597f7 remove .masquerade_as_nightly_cargo() from build_script_extra_link_arg.rs 2022-07-14 15:05:33 -05:00
bors 8827baaa78 Auto merge of #10862 - Muscraft:workspace-selection-test, r=epage
Add a test for regressions in selecting the correct workspace root

This adds a test to check for regressions in selecting the correct workspace when there are nested workspaces.

#10846 solved a problem with nested workspace resolution that was caused by #10776. `@ehuss` [suggested](https://github.com/rust-lang/cargo/pull/10846#issuecomment-1183754728) that a test should be added to ensure that this issue does not pop up again.

I ensured that this worked by testing against commit before #10846. Sporadically I would get an error that was the same as described in #10846.
```
error: package `{path}/cargo/target/tmp/cit/t0/foo/sub/foo/Cargo.toml` is a member of the wrong workspace
expected: {path}/cargo/target/tmp/cit/t0/foo/sub/Cargo.toml
actual:   {path}/cargo/target/tmp/cit/t0/foo/Cargo.toml
```
I then tested it on the commit with the fix and the test passed every time.

---

While this does add a test to catch any regression I am worried that it will not catch it every time.  It was noted in #10846 that this error would sometimes happen but not every time, in my testing I found this to be true as well. Since this is caused by the `HashMap` order changing each run, switching to something ordered like `BTreeMap` **_should_** catch any regressions every run (if the implementation were to ever change). I'm not sure if this is necessary so I figured I would note the concern here.
2022-07-14 02:56:51 +00:00
Scott Schafer 6070b0aab4 Add a test to check for regressions in selecting the correct workspace when there are nested workspaces 2022-07-13 21:10:22 -05:00
Ted Kaminski 380be40922 Allow '.' in workspace.default-members in non-virtual workspaces. 2022-07-13 21:19:31 +00:00
Ed Page b78f91831e test(add): Ensure comments are preserved
A comment on killercup/cargo-edit#15 had me worried that `cargo add` was
deleting comments now.  It appears that isn't the case for inline
tables.

Standard tables however do delete comments.  The work to make sure they
don't conflicts with another need.  When changing the source, we delete
the old source fields and append the new which can cause some formatting
to be carried over unnecessarily.

For example, what would normally look like
```toml
cargo-list-test-fixture-dependency = { optional = true, path = "../dependency", version = "0.0.0" }
```
When fixed to preserve comments with my naive solution looks like
```toml
cargo-list-test-fixture-dependency = { optional = true , path = "../dependency", version = "0.0.0" }
```
Note that `optional = true` used to be last, so space separating it and
`}` was kept, now separating it and `,`.

More work will be needed to get this into an ideal state but we can at
least have confidence with inline tables for now.
2022-07-13 13:38:10 -05:00
Yerkebulan Tulibergenov 2a75b44bc5 fix the test 2022-07-10 16:31:24 -07:00
Yerkebulan Tulibergenov dc23d97d5b Merge branch 'master' into yerke/negative_jobs 2022-07-10 14:20:26 -07:00
Eric Huss 79d7dc0e49 Update terminal-width flag. 2022-07-08 07:57:40 -07:00
Eric Huss c46e57b0cf Fix corrupted git checkout recovery. 2022-07-05 21:02:08 -07:00
Ed Page 18f7dfe0f5 fix(add): Don't panic with --offline
For some reason, I defined my own `--offline` flag and it didn't get
updated with the global `--offline` flag, so it started failing.

Fixes #10814
2022-07-02 23:04:00 -05:00
Urgau 23f59d4eeb Add regression tests for check-cfg unstable config 2022-06-29 14:52:20 +02:00
bors 47620e2060 Auto merge of #10778 - epage:test, r=ehuss
refactor(test): Clarify asserts are for UI

In writing the contrib documentation for functional vs ui tests, I
realized that as we work to make snapbox work for the functional tests,
we'll need distinct `Assert` objects since we'll want to elide a lot
more content in functional tests.  I'm making room for this by
qualifying the existing asserts as being for "ui".
2022-06-24 18:27:15 +00:00
Eric Huss 502a9c5407 Fix tests due to change in dead_code diagnostic. 2022-06-23 13:08:08 -07:00
bors ed549d8717 Auto merge of #10755 - jonhoo:stabilize-config-cli, r=ehuss
Stabilize config-cli

This stabilizes the `--config` CLI argument as per [this FCP](https://github.com/rust-lang/cargo/issues/7722#issuecomment-1114369809).

It also makes the adjustment [suggested by `@ehuss](https://github.com/rust-lang/cargo/issues/7722#issuecomment-1098612205)` to allow stabilizing `--config path` without _also_ stabilizing [`config-include`](https://doc.rust-lang.org/cargo/reference/unstable.html#config-include).

I took a guess that this would land in 1.63 and put that in the tombstone entry in the unstable docs, but let me know if that's likely to be wrong.

Closes https://github.com/rust-lang/cargo/issues/7722.

Also, I think this should probably be tagged `relnotes`.
2022-06-22 20:02:24 +00:00
Ed Page cbd4edb266 refactor(test): Clarify asserts are for UI
In writing the contrib documentation for functional vs ui tests, I
realized that as we work to make snapbox work for the functional tests,
we'll need distinct `Assert` objects since we'll want to elide a lot
more content in functional tests.  I'm making room for this by
qualifying the existing asserts as being for "ui".
2022-06-21 14:59:54 -05:00
bors c9d8c28cba Auto merge of #10767 - danilhendrasr:master, r=epage
Restrict duplicate deps warning only to published packages

Fixes #10752
2022-06-21 01:37:37 +00:00
Danil Hendra Suryawan 08d10184aa Restrict duplicate deps warning only to published packages 2022-06-21 00:28:25 +00:00
bors 5db8295f92 Auto merge of #10746 - shkoo:nils/custom_target_path_cache, r=weihanglo
Use fingerprint_hash when computing fingerprints for custom targets

This makes it easier to get reproducible builds for custom targets.
2022-06-20 22:56:09 +00:00
Josh Triplett da5f35d950
Merge pull request #10761 from Muscraft/reduce-parsing
Add preloading for workspace packages in `resolve_with_previous`
2022-06-20 10:46:11 -07:00
Nils McCarthy b424f90edb Don't use the full pathname of a custom target json in fingerprint hashes.
This makes it easier to get reproducible builds for custom targets.
2022-06-20 09:09:52 -07:00
Jon Gjengset 39c3173619 Stabilize --config
FCP
https://github.com/rust-lang/cargo/issues/7722#issuecomment-1114369809

Closes #7722.
2022-06-17 22:46:04 +00:00
Jacob Finkelman 288856b778 HTTP-based -> sparse
Co-authored-by: Arlo Siemsen <arkixml@gmail.com>
2022-06-17 16:45:33 +00:00
Kornel a9faf49040 Use specific terminology for sparse HTTP-based registry
Git-based registry uses HTTP too
2022-06-17 15:09:56 +01:00
Scott Schafer cda5f82498 add preloading for workspace packages in resolve_with_previous so manifests aren't parsed twice 2022-06-16 15:34:22 -05:00
Ed Page 6f475f090e chore: Upgrade to clap 3.2 2022-06-13 10:02:23 -05:00
Arlo Siemsen 24dac452c5 Improve testing framework for http registries
Improve integration of the http server introduced by the http-registry feature.
Now the same HTTP server is used for serving downloads, the index, and
the API.

This makes it easier to write tests that deal with authentication and
http registries.
2022-06-10 16:51:35 -05:00
Jakub Sitnicki 26031b9069 Respect submodule update=none strategy in .gitmodules
Git lets users define the default update/checkout strategy for a submodule
by setting the `submodule.<name>.update` key in `.gitmodules` file.

If the update strategy is `none`, the submodule will be skipped during
update. It will not be fetched and checked out:

1. *foo* is a big git repo

```
/tmp $ git init foo
Initialized empty Git repository in /tmp/foo/.git/
/tmp $ dd if=/dev/zero of=foo/big bs=1000M count=1
1+0 records in
1+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 0.482087 s, 2.2 GB/s
/tmp $ git -C foo add big
/tmp $ git -C foo commit -m 'I am big'
[main (root-commit) 84fb533] I am big
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 big
```

2. *bar* is a repo with a big submodule with `update=none`

```
/tmp $ git init bar
Initialized empty Git repository in /tmp/bar/.git/
/tmp $ git -C bar submodule add file:///tmp/foo foo
Cloning into '/tmp/bar/foo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 1 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), 995.50 KiB | 338.00 KiB/s, done.
/tmp $ git -C bar config --file .gitmodules submodule.foo.update none
/tmp $ cat bar/.gitmodules
[submodule "foo"]
        path = foo
        url = file:///tmp/foo
        update = none
/tmp $ git -C bar commit --all -m 'I have a big submodule with update=none'
[main (root-commit) 6c355ea] I have a big submodule not updated by default
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 foo
```

3. *baz* is a clone of *bar*, notice *foo* submodule gets skipped

```
/tmp $ git clone --recurse-submodules file:///tmp/bar baz
Cloning into 'baz'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Submodule 'foo' (file:///tmp/foo) registered for path 'foo'
Skipping submodule 'foo'
/tmp $ git -C baz submodule update --init
Skipping submodule 'foo'
/tmp $
```

Cargo, on the other hand, ignores the submodule update strategy set in
`.gitmodules` properties when updating dependencies. Such behavior can
be considered against the wish of the crate publisher.

4. *bar* is now a lib with a big submodule with update disabled

```
/tmp $ cargo init --lib bar
     Created library package
/tmp $ git -C bar add .
/tmp $ git -C bar commit -m 'I am a lib with a big submodule but update=none'
[main eb07cf7] I am a lib with a big submodule but update=none
 3 files changed, 18 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 Cargo.toml
 create mode 100644 src/lib.rs
/tmp $
```

5. *qux* depends on *bar*, notice *bar*'s submodules are fetched

```
/tmp $ cargo init qux && cd qux
     Created binary (application) package
/tmp/qux $ echo -e '[dependencies.bar]\ngit = "file:///tmp/bar"' >> Cargo.toml
/tmp/qux $ time cargo update
    Updating git repository `file:///tmp/bar`
    Updating git submodule `file:///tmp/foo`

real    0m22.182s
user    0m20.402s
sys     0m1.714s
/tmp/qux $
```

Fix it by checking if a Git repository submodule should be updated when
cargo processes dependencies.

6. With the change applied, submodules with `update=none` are skipped

```
/tmp/qux $ cargo cache -a > /dev/null
/tmp/qux $ time ~/src/cargo/target/debug/cargo update
    Updating git repository `file:///tmp/bar`
    Skipping git submodule `file:///tmp/foo`

real    0m0.029s
user    0m0.021s
sys     0m0.008s
/tmp/qux $
```

Fixes #4247.

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
2022-06-07 14:52:02 +02:00
bors 7d289b1711 Auto merge of #10713 - flip1995:rust-version-env, r=epage
Expose rust-version through env var

This adds another env var that is exposed by cargo. In Clippy we would like to use that in order to efficiently check if a rust-version is set for the current package: https://github.com/rust-lang/rust-clippy/pull/8774

Currently we either have to parse the `Cargo.toml` file ourselves or use the `cargo_metadata` crate which has a notable performance impact when running `clippy-driver` on single files.
2022-06-06 13:19:38 +00:00
flip1995 0852f5413e
Expose rust-version through env var 2022-06-06 12:04:20 +02:00
bors a9efb069c4 Auto merge of #10676 - djmcgill:origin/master, r=weihanglo
add validation for string "true"/"false" in lto profile

### What does this PR try to resolve?
Adds a special-cased error message for when `lto` is set to the _string_ `"true"`/`"false"` which is surprisingly (I was surprised anyway) not allowed and the error message is ambiguous. The new error message makes it clear what values are accepted.
Fixes https://github.com/rust-lang/cargo/issues/10572

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

 <!-- Demonstrate how you test this change and guide reviewers through your PR.
With a smooth review process, a pull request usually gets reviewed quicker.

If you don't know how to write and run your tests, please read the guide:
https://doc.crates.io/contrib/tests -->

Uh I've not actually tested yet that's the WIP part. But put
```
[profile.dev]
lto="false"
```
in your TOML and run `cargo build`, check that you get the new error message and that it makes sense and is helpful.

### Additional information

It's worth noting that as per https://github.com/rust-lang/rust/pull/97051 this doesn't fix the _real_ problem here IMO which is that [rust's `opt_parse_bool` cli parsing](491f619f56/compiler/rustc_session/src/options.rs (L456)) doesn't accept true/false which certainly seems an ad-hoc historical choice to me on first glance but also it's a much bigger change to change those semantics than this error message.
2022-06-05 23:03:21 +00:00
David McGillicuddy 0daf70d816 Special case the string true/false error message for LTO profile arg 2022-06-05 23:30:29 +01:00
bors 38472bc19f Auto merge of #10701 - danilhendrasr:master, r=weihanglo
Emit warning upon encountering multiple packages with the same name

Fixes: #10669
2022-05-31 02:03:24 +00:00
bors ca4edabb28 Auto merge of #10706 - merelymyself:master, r=epage
Guide new users to add use `super::*;` to `mod test`

### What does this PR try to resolve?

Currently, `cargo init --lib` produces examples for unit tests. However, new users will find that they are unable to use functions they defined above. This should resolve the confusion.

Fixes #10559

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

This PR does not create new features. Test this PR using the already-existing tests.

### Additional information

I didn't think this was a major change, so I did not open a RFC for it. Please let me know if I should have!
2022-05-29 02:13:39 +00:00
Danil Hendra Suryawan e903f7dfc0 Emit warning upon encountering ambiguous deps 2022-05-28 03:32:04 +00:00
merelymyself 754a5bfbaa whitespace 2 2022-05-28 00:17:57 +08:00
merelymyself 684a338693 whitespace 2022-05-28 00:14:30 +08:00
merelymyself 3d21b14323 Guide new users to add use super::*; to mod test 2022-05-27 23:41:37 +08:00
bors e23cf4393f Auto merge of #10677 - likzn:fix_publish_p, r=ehuss
fix(publish): add more check when use `publish -p <SPEC>`

### Main issue
As issue say #10536 , we need add more check when user use `cargo publish -p <SPEC>`

>`@ehuss` point outs:
>From a behavior standpoint, here are some things to check:
> - In the root of a virtual workspace, it should be an error to run without -p.
>- It should be an error to pass -p for a non-workspace member.
>- It should be an error for -p to match multiple packages.
>- When using -p, it should publish that package, not the one in the current directory (which can be different).
2022-05-27 00:43:33 +00:00
likzn b486ada19f clean err msg 2022-05-26 08:49:06 +08:00
likzn 52165e8c2d update 2022-05-25 18:17:08 +08:00
bors 39ad1039d9 Auto merge of #10600 - tmfink:doc-build-script-link-order, r=ehuss
doc: discuss build script instruction order

### What does this PR try to resolve?

It is currently not documented that the order of build script `cargo:` instructions may be relevant to linking.

This has caused issues such as: https://github.com/rust-lang/rust/issues/96328

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

Build/view documentation.

### Additional information

- Cargo maintainers should fact check my wording.
- We may need to discuss if this should also be documented for `rustc`
- Maintainers should ensure that this change does not prevent a change in what is currently unspecified behavior. Perhaps `cargo` will want to rearrange link arguments itself to resolve issues in the future?
2022-05-25 00:50:02 +00:00
Travis Finkenauer 43ce1e7a98 Test that link argument order is maintained
Patch provided by @ehuss
2022-05-24 12:45:20 -07:00
bors e7c8ba7753 Auto merge of #10698 - arlosi:http-slash, r=Eh2406
Require http-registry URLs to end with a '/'

The `url` crate normalizes URLs with no path component to end in a trailing slash. This causes the current implementation to use urls containing two slashes for registries without a path component (such as `https://index.crates.io//config.json`).

This PR resolves the issue by requiring http registry URLs to end in a slash and generating paths by concatenating. A new error message is emitted for http registry URLs that do not end in a slash.

r? `@Eh2406`
2022-05-24 15:23:47 +00:00
bors bf824127cc Auto merge of #10691 - danilhendrasr:master, r=weihanglo
No printing executable names when running tests and benchmarks with json message format

Fixes: #10684
I added a new test for this, though I'm not sure if it's necessary. Let me know if I should delete it.
2022-05-24 14:42:56 +00:00
Danil Hendra Suryawan e04d7772e4 No printing executable names when running benches with json message format 2022-05-24 20:44:54 +07:00
merelymyself 8401ef16f6 fixed issue with formats_source 2022-05-24 20:42:26 +08:00
merelymyself 73aa070687 Guide new users to add use super::*; 2022-05-24 20:27:58 +08:00
Arlo Siemsen 2622074d43 Require http-registry URLs to end with a '/' 2022-05-23 21:39:23 -05:00
likzn 72d6c5411a cargo fmt 2022-05-24 09:15:44 +08:00
likzn 72457ef462 fix test stderr 2022-05-24 09:09:57 +08:00
likzn 1179e7ef6b cargo fmt 2022-05-23 21:06:34 +08:00
likzn 89c24bf811 refactor logic 2022-05-23 21:01:55 +08:00
Danil Hendra Suryawan 7952680d8d No printing executable names when running tests with json message format 2022-05-21 23:18:46 +07:00
Jon Gjengset c262f100ec Restore proper error for crate not in local reg
Fixes #10682.
2022-05-20 18:24:26 +00:00
bors c8c6e33996 Auto merge of #10539 - Urgau:check-cfg-build-script, r=ehuss
Add unstable `rustc-check-cfg` build script output

This PR adds a new build script output as unstable behind `-Zcheck-cfg=output`: `rustc-check-cfg`.

### What does this PR try to resolve?

This PR add a way to add to use the unstable `--check-cfg` command line option of `rustc` and `rustdoc`.

It was discover in [Bump bootstrap compiler to 1.61.0 beta](https://github.com/rust-lang/rust/pull/95678#discussion_r842803445) that `rustc_llvm` sets some custom `cfg` from a build script and because `--check-cfg=values()` is globally enable in the Rust codebase that cause the compilation to fail. For now no values are checked in stage 0 for the entire codebase which is a shame and should be fixed with the addition of this feature.

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

Commits are separated in: implementation, tests and doc.

Testing should simply be done by adding a valid `cargo:rustc-check-cfg` in a build script.
Watch the added tests or doc to have an example.

### Additional information

This PR is also the logical next step after `-Zcheck-cfg-features`.
2022-05-20 00:55:25 +00:00
Loïc BRANSTETT 805f5c2f0a Add tests for cargo:rustc-check-cfg 2022-05-18 21:26:56 +02:00
likzn a5a0f6809d fix typo 2022-05-18 23:42:42 +08:00
likzn 95cb21d6a1 fix cargo -p 2022-05-18 22:40:55 +08:00
Weihang Lo 378e292cfa
test: cargo-vendor with path specified 2022-05-13 20:46:33 +08:00
Weihang Lo 6651781593
Remove unnecessary dbg! 2022-05-13 20:46:32 +08:00
Eric Huss e952070946 Fix no_cross_doctests race condition. 2022-05-11 14:10:49 -07:00
bors 23ae8a0a0f Auto merge of #10650 - epage:install, r=ehuss
feat(install): Support `foo@version` like cargo-add

### What does this PR try to resolve?

This aims to make `cargo install` consistent with
- `cargo add foo@version` from #10472
- pkgid changes in #10582
- `cargo yank foo@version` from #10597

It also offers a shorthand for people installing a specific version.

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

#10582 acted as the FCP for this, see #10597

Documentation updates are split into their own commit to not clog up browsing the code.

Examine the tests to see if they make sense

### Additional information

While the `foo@vewrsion` syntax is the same, each's semantics are different.  We had decided it was better to have the same syntax with different semantics than having the user worry about what syntax they use where.  In `cargo install`s case, it has an
implicit-but-required `=` operand while `cargo-add` allows any operand.

This doesn't use the full `pkgid` syntax because that allows syntax that
is unsupported here.

This doesn't use `cargo-add`s parser because that is for version reqs.

I held off on reusing the parser from `cargo-yank` because they had
different type system needs and the level of duplication didn't seem
worth it (see Rule of Three).
2022-05-11 03:25:36 +00:00
bors 08bef9dfb7 Auto merge of #10649 - Muscraft:fix-typos, r=epage
fix typos found by the `typos-cli` crate

This fixes various typos inside `cargo`. They were found by [`typos-cli`](https://crates.io/crates/typos-cli). A few different typos were left out as they seemed either intentional or were needed. Typos found in `LICENSE-THIRD-PARTY` were left alone as well.

r? `@epage`
2022-05-10 23:58:15 +00:00
Scott Schafer cab6d30c1d fix typos found by the typos-cli crate 2022-05-10 16:47:28 -05:00
bors b3f6772a66 Auto merge of #10646 - koic:use_rust_2021_prelude, r=epage
Use the traits added to the Rust 2021 Edition prelude

Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
2022-05-10 16:48:05 +00:00
bors cc9e3014a3 Auto merge of #10594 - weihanglo:issue-10560, r=ehuss
Pass `--target` to `rustdoc` for `cargo test` if specified with host target.
2022-05-10 15:56:03 +00:00
Koichi ITO 1626762fe4 Use the traits added to the Rust 2021 Edition prelude
Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html
2022-05-10 21:46:45 +09:00
Weihang Lo ba2b250c2e
test: pass --target to rustdoc even if specified with host target 2022-05-10 16:56:19 +08:00
bors 9fa2bba679 Auto merge of #10281 - Gnurfos:depinfo_relative, r=ehuss
Fix use of .. in dep-info-basedir

### Summary

This allows setting, in .cargo/config's dep-info-basedir, some relative path that goes above the crate's directory.

### Motivation

In a setup like this:

```
repo_root
├── Makefile
├── some_c_things
│   └── foo.c
└── rust_things
    ├── Cargo.toml
    └─── src
        └── lib.rs
```

If you want the generated .d files to be includable directly in the Makefile (without post-processing), you need them to mention paths relative to the root, like:

rust_things/target/....: rust_things/src/lib.rs

### Implementation

For this you need to have relative paths with parent directories (in this case ..) in dep-info-basedir, which does not work without the change in this PR (due to render_filename doing only strip_prefix, while the basedir still contains literal ..s).

Let me know if this change is acceptable. Another implementation could be to canonicalize in ConfigRelativePath::resolve_path instead, especially since that struct outputs absolute paths. But that would have it access the filesystem, while it currently doesn't.
2022-05-07 19:49:54 +00:00
cuishuang 6f13c466d2 fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-05-08 01:07:28 +08:00
bors 9c61a3d10b Auto merge of #10638 - Muscraft:move-snapshot-tests, r=epage
Move snapshot tests into testsuite

This moves all tests from the `snapshot` folder into the `testsuite` folder as described by [this comment](https://github.com/rust-lang/cargo/pull/10631#discussion_r866306441). A macro was also added so there is no need to specify the path in a `snapshot` test just the file. This was done for ease of refactoring and ease of porting new tests to `snapshot`

close #10627

r? `@epage`
2022-05-07 02:14:00 +00:00
Scott Schafer 639f3bdea5 move all snapshot/init/ tests to testsuite/init/ 2022-05-06 20:51:49 -05:00
Scott Schafer 92fbc4e344 move all snapshot/cargo_add/ tests to testsuite/cargo_add/ 2022-05-06 20:51:29 -05:00
Loïc BRANSTETT cf496db45e Re-enable check-cfg tests under windows with a custom macro for escaping 2022-05-06 22:42:30 +02:00
Loïc BRANSTETT 2d0ca84b0e Move check cfg tests to their own module 2022-05-06 22:42:28 +02:00
Loïc BRANSTETT 6a9f094c8c Convert the testsuite to use the new -Zcheck-cfg flag and syntax 2022-05-06 22:40:08 +02:00
bors 08b8fe5c2d Auto merge of #10142 - jyn514:bin-private-link, r=ehuss
When documenting private items in a binary, ignore warnings about links to private items

Previously, rustdoc would warn about linking to private items in a binary, even
though cargo unconditionally documents private items in a binary.
This changes cargo to silence the warning, since it's only relevant in
cases where the private items might not be documented.

Fixes https://github.com/rust-lang/rust/issues/89600.
2022-05-06 19:48:59 +00:00
bors 0f75da631b Auto merge of #10582 - epage:pkgid, r=ehuss
Extend pkgid syntax with `@` support

In addition to `foo:1.2.3`, we now support `foo@1.2.3` for pkgids.  We
are also making it the default way of rendering pkgid's for the user.

### What does this PR try to resolve?

With cargo-add in #10472, we've decided to only use ``@`` in it and to add
it as an alternative to `:` in the rest of cargo.  `cargo-add`
originally used ``@`.`  When preparing it for merge, I switched to `:` to
be consistent with pkgids. When discussing this, it was felt ``@`` has
precedence in too many tools to switch to `:` but that we should instead
switch pkgid's to use ``@`,` in a backwards compatible way.  #10472 served
as the change proposal for this

See also
- https://internals.rust-lang.org/t/feedback-on-cargo-add-before-its-merged/16024/26?u=epage
- https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Multiple.20ways.20of.20specifying.20versions

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

The focus of the testing is on the parsers unit tests and on the end-to-end output.  We are not explicitly testing end-to-end input in this PR, assuming the unit tests are sufficient.

### Additional information

This only focuses on places we already accept pkgids.  Looking into supporting `foo@1.2.3` in `cargo install` and `cargo yank` is being left for a future PR.
2022-05-06 19:07:07 +00:00
Scott Schafer ea312988fb move a snapshot/add/ test into testsuite/cargo_add directory 2022-05-06 10:31:58 -05:00
bors 05a53e7293 Auto merge of #10629 - Muscraft:reorganize-snapshot-tests, r=epage
reorganize `snapshot` tests to better work in contexts that sort by extension

Changed snapshot file stricture from
```
<name>.in/
<name>.out/
<name>.stdout
<name>.stderr
```

To
```
<name>/in/
<name>/out/
<name>/stdout.log
<name>/stderr.log
```

This makes it easier to review and make changes when in contexts that sort by extension

close #10626

r? `@epage`
2022-05-04 14:42:24 +00:00
Scott Schafer 0602320c6a reorganize snapshot tests for init to better work in contexts that sort by extension 2022-05-04 08:58:30 -05:00
Scott Schafer 87833663f4 reorganize snapshot tests for cargo-add to better work in contexts that sort by extension 2022-05-04 08:55:55 -05:00
bors a44758ac80 Auto merge of #10129 - jyn514:fetch-build-std, r=weihanglo
Add support for `-Zbuild-std` to `cargo fetch`

This allows downloading the dependencies for libstd in advance, which
can be useful in e.g. sandboxed build environments.

Fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/22.

r? `@ehuss`
2022-05-04 02:29:34 +00:00
Joshua Nelson 55b680c194 Add support for -Zbuild-std to cargo fetch
This allows downloading the dependencies for libstd in advance, which
can be useful in e.g. sandboxed build environments.

- Abstract check for `--target` out into a function
- Try to abstract `test` special-casing into a function

  This avoids hard-coding crate names in multiple places.

- Unify handling of checks for `--target` in `BuildConfig::new`

  This makes sure it's checked consistently, without requiring each new command to check it explicitly.

- Share more code between `fetch` and `build` by adding `std_crates()`
- Warn about `--build-plan` and `-Zbuild-std` consistently, not just for `build`

  Currently only `build` uses build-plan. But cargo may choose to add it to new commands in the future (e.g. check and doc).
  Future-proof it, since it's simple to do.
2022-05-03 20:07:14 -05:00
Joshua Nelson 727baf0db1 When documenting private items in a binary, ignore warnings about links to private items
Previously, rustdoc would warn about linking to items in a binary, even
though cargo unconditionally documents private items in a binary.
This changes cargo to silence the warning, since it's only relevant in
cases where the private items might not be documented.
2022-05-03 20:03:44 -05:00