Commit graph

4615 commits

Author SHA1 Message Date
Scott Schafer c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05: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
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
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