Commit graph

3910 commits

Author SHA1 Message Date
hi-rustin
47f4b75847 fix: only inherit workspace package table if the new package is a member
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-09 21:24:32 +08:00
hi-rustin
87345a1932 test: correct not_inherit_workspace_package_table_if_not_members case
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2024-01-08 21:55:41 +08:00
Ed Page
633929d3aa refactor(schemas): Pull out cargo-util-schemas crate
Fixes #12801
2023-12-15 13:22:25 -06:00
Ed Page
1da305301c refactor: Validate via RegistryName/PackageName 2023-12-13 13:03:27 -06:00
Ed Page
db2e314077 fix: Improve registry name errors?
Because of workspace inheritance, the errors aren't the greatest
2023-12-13 11:37:08 -06:00
Ed Page
6b6eb06714 fix: Improve package name errors 2023-12-13 11:27:02 -06:00
Ed Page
a3976cd47c fix: Improve profile name errors 2023-12-13 10:53:40 -06:00
Ed Page
c1d9b76401 fix: Improve feature name errors
This moves feature name validation early enough in the process to get
TOML errors.
2023-12-13 10:53:40 -06:00
Ed Page
a383185c38 refactor: Centralize empty name check 2023-12-13 10:46:38 -06:00
Ed Page
2db5c9dd59 fix(new): Catch empty package names earlier 2023-12-13 10:44:55 -06:00
Ed Page
9de03cd1fd fix(add): Catch empty dep name early 2023-12-13 10:43:55 -06:00
Ed Page
1791353689 fix!: Disallow empty registry names
This was allowed when switching from `toml` v0.5 to `toml_edit` which
started allowing empty keys when parsing TOML.
This mirrors the change
we made for disallowing empty feature names in #12928.
2023-12-13 10:38:37 -06:00
Ed Page
7200646a97 test: Demonstrate existing empty name errors 2023-12-13 10:38:34 -06:00
bors
5dc5118c53 Auto merge of #13156 - hi-rustin:rustin-patch-fix-nightly-test, r=epage
Remove the deleted feature test_2018_feature from the test
2023-12-12 03:04:52 +00:00
hi-rustin
e540c66e09 Remove the deleted feature test_2018_feature from the test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-12 10:54:29 +08:00
bors
a0339b0ae3 Auto merge of #13155 - epage:lint, r=weihanglo
fix(toml)!: Disallow `[lints]` in virtual workspaces

This was missed with the initial `[lints]` implementation.

While this is a breaking change, this is aligned with ones we've done in the past.  A lot of times, we warn first.  My hope is that isn't needed this time because
- It only exists virtual workspaces so they aren't published
- It is a nop to have this which is likely to be caught
- This is so new that the number of people using it, and likely running into this case, is quite low.
2023-12-11 20:30:22 +00:00
Ed Page
66ce16c72b fix(toml)!: Disallow [lints] in virtual workspaces
This was missed with the initial `[lints]` implementation.

While this is a breaking change, this is aligned with ones we've done in
the past.  A lot of times, we warn first.  My hope is that isn't needed
this time because
- It only exists virtual workspaces so they aren't published
- It is a nop to have this which is likely to be caught
- This is so new that the number of people using it, and likely running
  into this case, is quite low.
2023-12-11 14:10:01 -06:00
bors
7688d896a8 Auto merge of #13135 - linyihai:limit-priv-to-library, r=epage
Limit exported-private-dependencies lints to libraries

### What does this PR try to resolve?
Completed https://github.com/rust-lang/cargo/issues/13039.

This PR limit `exported-private-dependencies`  lint in libraray `Target`.

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

Your can checkout out 2348ac2a20edf772495349d7911938251e343bf1 and run test, it will failed and then it will be passed in the commit 2348ac2a20edf772495349d7911938251e343bf1

### Additional information
2023-12-11 17:22:22 +00:00
Lin Yihai
58c673d040 test(pub_priv): covering build.rs test 2023-12-09 17:14:10 +08:00
Lin Yihai
ab13b10066 feat: limit -extern priv: to libraries 2023-12-09 16:11:05 +08:00
Lin Yihai
db0c5c1d72 test(priv_dep): verify -extern priv: do not limit in lib target. 2023-12-09 16:00:35 +08:00
bors
6feabf9477 Auto merge of #13114 - weihanglo:trim-paths-explicit-cwd, r=epage
fix: explicitly remap current dir by using `.`
2023-12-08 22:38:37 +00:00
Weihang Lo
fcd4221c5a
test(trim-paths): don't follow links to separate debuginfo files
For refeference:
https://sourceware.org/binutils/docs/binutils/readelf.html
2023-12-08 16:34:00 -05:00
Weihang Lo
bb86adfff7
fix(trim-paths): explicit remap to current dir .
In https://github.com/rust-lang/rust/blob/87e1447aa/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs#L856
when the remap result of `work_dir` is an empty string,
LLVM won't generate some symbols for root debuginfo node.
For example, `N_SO` and `N_OSO` on macOS,
or `DW_AT_comp_dir` on Linux when debuginfo is splitted.
Precisely, it is observed that when the `DIFile` of compile unit was
provied with an empty compilation `Directory` string,
LLVM would not emit those symbols for the root DI node.

This behavior is not desired,
resulting in corrupted debuginfo and degrading debugging experience.

This is might not be a bug of `--remap-path-prefix` in rustc,
since `-fdebug-prefix-map` in clang 16 could have the same result
(`DW_AT_comp_dir` is gone when `work_dir` is remapped to an empty string).
However, in gcc 12 `fdebug-prefix-map` will return an absolute work_dir
when an empty string occurs.

To not bother whether this needs to be fixed in rustc or not,
let's fix it by always appending an explicit `.`
when `--remap-path-prefix` remaps to relative workspace root
a.k.a. where rustc is invoking.

For more on gcc/clang remap options, see
https://reproducible-builds.org/docs/build-path/
2023-12-08 15:52:06 -05:00
Weihang Lo
7cb7b47fe7
test(trim-paths): add test for each split-debuginfo options
Also demonstarte that on Linux with split-debuginfo on the remap is broken
2023-12-08 15:51:55 -05:00
Chris Denton
4ef503fc2d
Don't rely on mtime to test changes 2023-12-08 20:32:28 +00:00
Weihang Lo
985d49b916
test(trim-paths): use --config CLI to change options 2023-12-08 13:57:45 -05:00
Sebastian Thiel
189de40a6f
re-enable flaky tests thanks to update to gix-config. (#11821)
With `gix-config` now being fixed, it will properly respect `GIT_CONFIG_NOSYSTEM`
both for system-wide configuration as well as for the git installation configuration.

That way, credential helpers provided by the git installation won't be called anymore,
which prevents them from 'somehow' emitting information to stderr.

The latter was previously disabled for credential helpers, and despite
everything^1 looking like it should work, it simply didn't.

[1]: https://github.com/rust-lang/cargo/pull/13117#issuecomment-1844881287
2023-12-07 10:19:07 +01:00
Weihang Lo
7ec1367973
test: re-ignore git auth tests for gitoxide 2023-12-06 20:18:22 -05:00
bors
000d279306 Auto merge of #13125 - epage:public, r=weihanglo
fix(toml): Disallow inheriting of dependency public status

### What does this PR try to resolve?

This is a step towards rust-lang/rust#44663.  When discussing inheriting this field
for #13046, we realized that we should probably start by disallowing
inheritance.  We can always add it later.  imo the principle of what should
be inherited is what is truely common among dependencies.  For example,
we don't allow removing features.  Public should not be universally
applied and likely should be explicit so its not over-done, especially
since we can't (atm) lint for when a public dependency could be
non-public.

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

### Additional information

This reverts parts of #12817
2023-12-06 22:08:40 +00:00
bors
862e53a985 Auto merge of #13117 - Byron:enable-tests, r=weihanglo
re-enable previously disabled tests with Windows-specific fix

Related to #11821 for which this is a fix.
However, it's probably not yet the optimal solution, depending on how `stderr` of subprocesses should be handled.

### Tasks

* [x] try to fix the issue with an env var.
    - Failure, as one warning remains that seems to originate from a C# HTTP client
* [x] figure out if `stderr` should be on or off by default - on by default like before, but now one can control it.
* [x] create a new `gix` release and use it here

### Review Notes

* Personally, I think `cargo` should keep `stderr` to be inherited so users can see potentially relevant warnings or errors provided by credential helpers. Thus this is still the default, but the tests that need it explicitly disabled `stderr` of credential helpers.

----

On Windows, `gix` will call the `git-credential-manager, but with
`stderr` set to `inherit` which makes any errors visible to the user,
just like `git` does.

```
1   1         Updating git repository `https://foo.bar/foo/bar`
    2    +warning: auto-detection of host provider took too long (>2000ms)
    3    +warning: see https://aka.ms/gcm/autodetect for more information.
    4    +fatal: A task was canceled.
    5    +warning: auto-detection of host provider took too long (>2000ms)
    6    +warning: see https://aka.ms/gcm/autodetect for more information.`
````

This, however, isn't what's desirable in tests sometimes, nor may
it be desirable in Cargo.

For now, it seems easiest to disable this particular feature that
issues the warning messages, even though a future `gix` update
should allow to control what to do with `stderr`.
2023-12-06 19:04:36 +00:00
Sebastian Thiel
49c48b88cc
re-enable previously disabled tests (#11821)
On Windows, `gix` will call the `git-credential-manager, but with
`stderr` set to `inherit` it makes any errors visible to the user,
just like `git` does.

```
1   1         Updating git repository `https://foo.bar/foo/bar`
    2    +warning: auto-detection of host provider took too long (>2000ms)
    3    +warning: see https://aka.ms/gcm/autodetect for more information.
    4    +fatal: A task was canceled.
    5    +warning: auto-detection of host provider took too long (>2000ms)
    6    +warning: see https://aka.ms/gcm/autodetect for more information.`
````

This, however, isn't what's desirable in tests sometimes, nor may
it be desirable in Cargo.

In the latest version of `gix`, it's possible to control `stderr`
which is now set on a per-test basis.

Also note that for `cargo` as a whole the default didn't change,
and stderr of spawned helper programs will remain visible in the
enclosing terminal.
2023-12-06 17:09:17 +01:00
Ed Page
594c96ad51 refactor(metadata): Switch opaque ID from PackageID to PackageIDSpec 2023-12-06 08:58:56 -06:00
bors
9787229614 Auto merge of #12933 - epage:pkgid-spec, r=weihanglo
feat(spec): Extend PackageIdSpec with source kind + git ref for unambiguous specs

### What does this PR try to resolve?

This tries to add just enough information to Package ID Specs that we can be sure they are unambiguous.  On its own thats important but this will unblock #12914 so we can have a user-facing ID that can be used with cargo's CLI.

More specifically, this adds
- `git+`, etc prefixes to the scheme
  - These were previously stabilized for `cargo metadata`s source id urls
  - Like with `SourceID`, this will allow `PackageIDSpec` to generate `directory+` and `local-registry+` prefixes but not parse them.  I'm assuming that the layers where those are dealt with they won't appear here but I don't have enough experience with them
- git ref query strings for URLs

Things from `SourceID` that this does not include
- precise: this seems less related to matching (e.g. ignored for `impl Ord for SourceId`)
- canonical URL for git kinds: this could be nice for users but users aren't the target audience and we can switch to these later

Fixes #10256

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

Per-commit

### Additional information
2023-12-06 02:29:23 +00:00
bors
0124d280ff Auto merge of #13118 - weihanglo:object-works-macos, r=epage
test(trim-paths): assert `OSO` and `SO` cannot be trimmed
2023-12-06 01:50:28 +00:00
Ed Page
00557a2a77 fix(toml): Disallow inheriting of dependency public status
This is a step towards #44663.  When discussing inheriting this field
for #13046, we realized that we should probably start by disallowing
inheritance.  We can always add it later.  imo the principle of what should
be inherited is what is truely common among dependencies.  For example,
we don't allow removing features.  Public should not be universally
applied and likely should be explicit so its not over-done, especially
since we can't (atm) lint for when a public dependency could be
non-public.

This reverts parts of #12817
2023-12-05 17:00:01 -06:00
Weihang Lo
a4c607cde4
test(trim-paths): assert OSO and SO cannot be trimmed
See
* rust-lang/rust issue 117652
* rust-lang/rust issue 116948
2023-12-05 17:58:32 -05:00
bors
a5fa676731 Auto merge of #13097 - epage:schemas, r=ehuss
refactor(schemas): Pull out mod for proposed schemas package

Originally for #12801 we talked about a `cargo-util-manifest-schema` package
- `util` in the name to not clash with plugins
- manifest specific to keep the scope down

The problem is we have types that aren't manifest specific, like
- `PartialVersion` (currently slated for `cargo-util-semverext`)
- `RustVersion`
- `PackageIdSpec`
- `SourceKind` (soon)

Things get messy if we try to break things down into common packages. Instead, I think it'd be useful to have a schemas package that has mods for each type of schema, re-exporting what is needed.

Normally, componentizing your package by the layer in the stack is a recipe for pain.
I don't think that'll apply here because these are meant to be so low level.

The other big concern could be compile times.  My hope is it won't be too bad.

So this moves the `util/toml` types into the module and we can add more in the future.
2023-12-05 00:15:22 +00:00
Lin Yihai
b7b036f3a1 Chore(test): remove unnecesary packages and versions for optionals tests 2023-12-04 11:25:38 +08:00
bors
58fb231409 Auto merge of #13099 - weihanglo:running-binary, r=epage
test(install): use TCP connection instead of thread sleep
2023-12-02 14:15:16 +00:00
Weihang Lo
297b827fa3
test(install): use TCP connection instead of thread sleep
This is more robust than `thread::sleep`, ensuring

* foo is running before the first `cargo uninstall` call
* foo is stopped before the second `cargo uninstall` call
2023-12-02 01:54:20 -05:00
bors
aa6e46e8ca Auto merge of #13012 - Urgau:check-cfg-fingerprint, r=epage
Include declared list of features in fingerprint for `-Zcheck-cfg`

This PR include the declared list of features in fingerprint for `-Zcheck-cfg` (#10554)

`--check-cfg` verifies that `#[cfg()]` attributes are valid in Rust code, which includes `--cfg features foo` definitions that came from `[features]` tables in `Cargo.toml`.  For us to correctly re-check cfgs on feature changes,we need to include them in the fingerprint.

For example, if a user deletes an entry from `[features]`, they should then get warnings about any `#[cfg()]` attributes left in the code.  Without this change, that won't happen.  With this change, it now does.
2023-12-01 21:46:28 +00:00
Ed Page
64f5b0c869 feat(spec): Track git ref 2023-12-01 15:16:26 -06:00
Ed Page
9b9c683810 feat(spec): Track source kind 2023-12-01 15:16:26 -06:00
Ed Page
e7ca585445 test(pkgid): Demonstrate ambiguos specs 2023-12-01 15:16:26 -06:00
Urgau
f32f43d879 Avoid fingerprint invalidation when reordering the declared features 2023-12-01 22:07:03 +01:00
Urgau
7d1fc45a29 Include declared list of features in fingerprint for -Zcheck-cfg
Otherwise changing (add, removing, ...) features from the `[features]`
table would not cause rustc to be called with the new `--check-cfg`,
showing potentially outdated warnings.
2023-12-01 22:05:22 +01:00
Urgau
6c4069b4b5 Add test showing the buggy behavior of check-cfg and the fingerprint 2023-12-01 21:59:26 +01:00
Ed Page
e46df98241 refactor(schemas): Pull out mod for proposed schemas package
Originally for #12801 we talked about a `cargo-util-manifest-schema` package
- `util` in the name to not clash with plugins
- manifest specific to keep the scope down

The problem is we have types that aren't manifest specific, like
- `PartialVersion` (currently slated for `cargo-util-semverext`)
- `RustVersion`
- `PackageIdSpec`
- `SourceKind` (soon)

Things get messy if we try to break things down into common packages.
Instead, I think it'd be useful to have a schemas package that has mods
for each type of schema, re-exporting what is needed.

Normally, componentizing your package by the layer in the stack is a
recipe for pain.
I don't think that'll apply here because these are meant to be so low
level.

The other big concern could be compile times.  My hope is it won't be
too bad.

So this moves the `util/toml` types into the module and we can add more
in the future.
2023-12-01 13:31:30 -06:00
bors
78109c0d2c Auto merge of #13071 - LuuuXXX:issue-11010, r=epage
Have cargo add --optional <dep> create a <dep> = "dep:<dep> feature

### What does this PR try to resolve?

`cargo add --optional <dep>` would create a `<dep> = "dep:<dep>` feature iff

- `rust-version` is unset or is new enough for the syntax
- `dep:<dep>` doesn't already exist

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

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

As the `dep:` syntax is only available starting with Rust 1.60. this pr maintains the previous usage convention in the earlier version.

run

```shell
cargo add --optional <dep>
```

with different rust-version to verify.
2023-12-01 18:13:54 +00:00
LuuuX
036a03709b Fix issue-11010 2023-12-02 01:36:16 +08:00
bors
60e65eefb2 Auto merge of #13046 - linyihai:cargo-add-public, r=epage
Add `--public` for `cargo add`

## What does this PR try to resolve?
Complete https://github.com/rust-lang/cargo/issues/13037

This PR want to add `--public/--no public` flag for `cargo add`

Note: this assumes we'll remove workspace inheritance support for `public` as it sounds like we'll be reverting it https://github.com/rust-lang/rust/issues/44663#issuecomment-1826474620.  If we decide to keep workspace inheritance, we'll need to come back and update this.

## How should we test and review this PR?
Most of Code were reference `cargo add --optional`, So can reviewed the new code based on the part of  `optional` code.

The new testcases were origin from the `cargo add --optional` part.
- `public` testcase:there is no dependencies and will be add `public` dependencies.
- `no_public` testcase:  there is no dependencies  and will be add `no_public` dependencies.
- `overwrite_public` testcase: the dependencies already exists but will be overwrite with `public`.
- `overwrite_no_public` testcase: the dependencies already exists but will be overwrite with `no_public`.
- `overwrite_public_with_no_public` testcase: the dependencies already marked as `no_public` and will be overwrite with `public`.
- `overwrite_no_public_with_public` testcase: the dependencies already marked as `public` and will be overwrite with `no_public`.
2023-12-01 17:33:20 +00:00
Ed Page
378502bf20 refactor: Try to make PackageId conversion clearer 2023-12-01 10:48:14 -06:00
bors
c192d989b3 Auto merge of #13091 - weihanglo:trim-paths-lldb, r=epage
test(trim-paths): exercise with real world debugger
2023-12-01 15:47:10 +00:00
bors
847958971b Auto merge of #13053 - linyihai:cargo-uninstall-fixed, r=weihanglo
Fixed uninstall a running binary failed on Windows

### What does this PR try to resolve?
 Fixes https://github.com/rust-lang/cargo/issues/3364

The problem reproduce when you try to uninstall a running binary and it will failed on Windows,  this is because that cargo had already remove the installed binary tracker information in disk,  and next to remove the running binary but it is not allowed in Windows.  And to the worst,  you can not uninstall the binary already and only to reinstall it by the `--force` flag.

### How to solve the issue?
This PR try to make the uninstall a binary more reasonable that  only after remove the binary sucessfully then remove the tracker information on binary and make the remove binary one by one.

### How should we test and review this PR?
Add testcase 0fd4fd357b
- install the `foo`
- run `foo` in another thread.
- try to uninstall running `foo` and only failed in Windows.
- wait the `foo` finish, uninstall `foo`
- install the `foo`

### Additional information
2023-12-01 15:10:56 +00:00
Lin Yihai
db144c9d0a Add tracker verification for test case uninstall_running_binary 2023-12-01 22:23:40 +08:00
Weihang Lo
5c32fe0432
test(trim-paths): exercise with real world debugger 2023-12-01 08:48:24 -05:00
Lin Yihai
48c998fec7 Add detect_workspace_inherit_public test case. 2023-12-01 11:22:26 +08:00
Lin Yihai
a6ca281948 chore: add lib.rs for new test cases 2023-12-01 10:21:33 +08:00
bors
1ef8575839 Auto merge of #13077 - GuillaumeGomez:filter-workspace-scrape-example, r=epage
Don't filter on workspace members when scraping doc examples

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

I confirmed locally that it fixed the issue in docs.rs.

cc `@willcrichton`
r? `@epage`
2023-11-30 16:42:35 +00:00
Guillaume Gomez
689d9a7e4f Don't filter on workspace members when scraping doc examples 2023-11-30 17:38:49 +01:00
Guillaume Gomez
95a27cdbd1 Add regression test for scraped examples in crates without [workspace] 2023-11-30 17:36:46 +01:00
Lin Yihai
1e3b4231da chore: fixed clippy 2023-11-30 15:46:02 +08:00
bors
430effa37d Auto merge of #12484 - adrianEffe:fix/error-count, r=weihanglo
Fixes error count display is different when there's only one error left

### What does this PR try to resolve?

When there's only 1 error left, the number 1 appears in the output so that it scans the same as the output when there's more than 1 error, so:

```
error: could not compile `crate` (lib test) due to 1 previous error
```
instead of the current:
```
error: could not compile `crate` (lib test) due to a previous error
```

Fixes #12390

rustc related PR [#114759](https://github.com/rust-lang/rust/pull/114759)
2023-11-29 19:07:16 +00:00
bors
07f1208a9f Auto merge of #13065 - weihanglo:remap-path-prefix-order, r=ehuss
fix: reorder `--remap-path-prefix` flags for `-Zbuild-std`

### What does this PR try to resolve?

Order of `--remap-path-prefix` flags is important for `-Zbuild-std`.
We want to show `/rustc/<hash>/library/std` instead of `std-0.0.0`.

Fixes rust-lang/rust#117839

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

Follow the steps in rust-lang/rust#117839, or run

```
CARGO_RUN_BUILD_STD_TESTS=true cargo +nightly t --test build-std
```

to verify.
2023-11-29 18:28:07 +00:00
Adrian
3e297a6803
Update test for override respects spec metadata 2023-11-29 18:47:27 +02:00
Adrian
b7b5a093a1
Fix cargo errors counter 2023-11-29 18:47:14 +02:00
belovdv
6b86f93713 remove jobserver in shim for tests in testsuite/fix 2023-11-29 15:30:58 +03:00
Lin Yihai
0fd4fd357b Add test case for cargo uninstall while try to uninstalling a running Bin. 2023-11-29 17:52:22 +08:00
Weihang Lo
8709835a01
fix: reorder --remap-path-prefix flags for -Zbuild-std
Order of `--remap-path-prefix` flags is important for `-Zbuild-std`.
We want to show `/rustc/<hash>/library/std` instead of `std-0.0.0`.
2023-11-28 15:29:03 -05:00
Lin Yihai
703446165b chore: add the missing flag for cargo add --public 2023-11-28 11:25:10 +08:00
Lin Yihai
07ba57dd8b Remove unnecessary code for cargo add --public testcases 2023-11-27 08:54:05 +08:00
Lin Yihai
509535675b Make the public/no-public next to the pair optional/no-optional 2023-11-27 08:09:54 +08:00
Lin Yihai
58e0ab825b reuse add_basic.in/lib.rs for testcase 2023-11-25 12:41:01 +08:00
Lin Yihai
9ac30323b3 Add not overwrite testcase for cargo add --public 2023-11-25 11:29:39 +08:00
Lin Yihai
7c8d997e26 Add overwrite testcase for cargo add --public 2023-11-24 15:11:51 +08:00
Lin Yihai
a1a75e81c9 Update cargo add --help testcase 2023-11-24 15:04:52 +08:00
bors
65d0eb536d Auto merge of #12997 - hi-rustin:rustin-patch-cargo-test-support, r=epage
cargo-test-support: Add features to the default Cargo.toml file
2023-11-22 01:47:31 +00:00
bors
71cd3a926f Auto merge of #13016 - dtolnay-contrib:messagetype, r=ehuss
Handle $message_type in JSON diagnostics

### What does this PR try to resolve?

Unblocks https://github.com/rust-lang/rust/pull/115691.

Without this change, Cargo's testsuite fails in `doc::doc_message_format` and `metabuild::metabuild_failed_build_json`.

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

Tested with and without https://github.com/rust-lang/rust/pull/115691.

In Cargo repo: `cargo test --test testsuite`
In Rust repo: `x.py test src/tools/cargo` (separately on master and $message_type PR)
2023-11-20 15:30:57 +00:00
David Tolnay
65bb09d434
Handle $message_type in JSON diagnostics 2023-11-19 20:37:16 -08:00
Urgau
4781592e18 Fix --check-cfg invocation with zero features 2023-11-19 18:08:32 +01:00
hi-rustin
12d7818192 Add features to the default Cargo.toml file
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-19 22:03:57 +08:00
Eric Huss
2eac6f5c0c Fix clippy-wrapper test race condition. 2023-11-18 17:23:29 -08:00
Yerkebulan Tulibergenov
e81d84cc17 feat: Add CARGO_RUSTC_CURRENT_DIR
This is an alternative to #12158's `CARGO_WORKSPACE_DIR` that was
implementing the solution to #3946 that previously discussed in the
cargo team meeting.

`CARGO_WORKSPACE_DIR` is a bit awkward to document / describe because
its the effective workspace directory of the thing being built.
If the thing being built doesn't have a workspace, it falls back to
`CARGO_MANIFEST_DIR`.

It would also be hard to take into account what the
`CARGO_WORKSPACE_DIR` would be for path dependencies into foreign
workspaces *and* it wouldn't solve the problem the user is having.

What the user really wants is the CWD of rustc when it is invoked.
This is much simpler to describe and is accurate when using a path
dependency to a foreign package.

Because the CWD is a much simpler mechanism to talk about, I figured we
could diverge from our prior consensus and make it always present,
rather than limiting it to tests.

Remaining work for #3946: get this stabilized
2023-11-17 09:25:46 -06:00
Ed Page
c75c456de4 test(compiler): Make inner test names more specific
This will make it easier to verify other env variables later
2023-11-17 09:25:34 -06:00
bors
22bbc95f3c Auto merge of #12995 - linyihai:issue_11383, r=weihanglo
Exited with hard error when custom build file no existence or not in package

## What does this PR try to resolve?
Fixed https://github.com/rust-lang/cargo/issues/11383

## How should we test and review this PR?
Add test `build_script_outside_pkg_root`,  this will check `custom_build.rs` existence and whether in the package root, if not then exited with a hard error

## Additional information
The code just handle the `custom build` target that i know how to test it.  Other target type is skipped.
2023-11-24 01:41:19 +00:00
Lin Yihai
75aaa40c78 Remove the unnecessary backticks 2023-11-22 11:09:55 +08:00
Lin Yihai
edfbcf0a6c Return a hard error when custom build outside package 2023-11-21 11:10:46 +08:00
Lin Yihai
92ce5a2b27 Change the logging level and other improvement. 2023-11-20 12:57:26 +08:00
Lin Yihai
ac1e66d947 Add testcase for custom build file warning 2023-11-17 17:11:57 +08:00
bors
9f3b4883e8 Auto merge of #12178 - weihanglo:dogfood-lints-table, r=epage
chore: dogfood Cargo `-Zlints` table feature
2023-11-16 19:40:13 +00:00
Mohammad AlSaleh
0bbabecbf3 Fix a rustflags test using a wrong buildfile name
The test seem to have always had the wrong buildfile `build.rs.rs`.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
2023-11-16 20:03:01 +03:00
Weihang Lo
7a4754a1d3
lint: allow print_stdout and print_stderr 2023-11-16 11:35:21 -05:00
Weihang Lo
870f9ea7b3
lint: allow disallow_methods 2023-11-16 11:35:21 -05:00
Weihang Lo
1539b3dfc1
lint: dogfood ourselves lints table in manifest
These lint rules are from src/lib.rs. We aim to remove
them in the source code once `Zlints` hit stable.
2023-11-16 11:35:21 -05:00
Eric Huss
0afd943dad Fix some test output validation. 2023-11-15 15:10:18 -08:00
bors
6658e1abe3 Auto merge of #12977 - Eh2406:bug_12941, r=epage
If the only path is a loop then counted as the shortest path.

This is a fix for #12941

This graph data structure is used to store dependency DAGs. Where each edge represents a dependency from a package to the package that fulfilled the dependency. Different parts of the resolver store this data in opposite directions, sometimes packages point at the things that depend on them other times packages point to the parents that required them. Error messages often need to report on why a package is in the graph, either by walking up toward parents or down toward children depending on how this graph is stored. #12678 unified the two different walking implementations, and replace them with a breadth first search so as to find the shortest path. This code ignored when edge pointed at a package that had already been reached, because that generally describes a longer path to an existing package.

Unfortunately, when I said this was a DAG that was a simplification. There can be cycles introduced as dev-dependencies. The existing code would reasonably ignore the cycles figuring that if we continue searching we would eventually find the root package (a package that nothing depended on). Missing the possibility that the root package created the cycle.

Now we search through the entire graph looking for a root package. If we do not find a root package we report the path to the last package we processed.
2023-11-15 16:09:00 +00:00
bors
0fcc90dc24 Auto merge of #12950 - epage:msrv, r=Eh2406
fix(resolver): Prefer MSRV, rather than ignore incompatible

### What does this PR try to resolve?

This is another experiment for #9930.

Comparing preferring over exclusively using MSRV compatible:

Benefits
- Better error messages
- `--ignore-rust-version` is implicitly sticky

Downsides
- Can't backtrack for MSRV compatible version
- Still requires workspace-wide MSRV (compared to our desired end state of declaring MSRV as yet another dependency)

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

### Additional information

Note: `--ignore-rust-version` is not yet implemented for the resolver.

This builds on #12930
2023-11-14 21:56:00 +00:00
Ed Page
0d29d3f71b fix(resolver): Prefer MSRV, rather than ignore incompatible
This is another experiment for #9930.

Comparing preferring over exclusively using MSRV compatible:

Benefits
- Better error messages
- `--ignore-rust-version` is implicitly sticky

Downsides
- Can't backtrack for MSRV compatible version
- Still requires workspace-wide MSRV (compared to our desired end state of declaring MSRV as yet another dependency)

This builds on #12930
2023-11-14 14:56:58 -06:00
Ed Page
0bc5d22285 test(resolver): Verify backtracking for MSRV resolver 2023-11-14 14:56:53 -06:00
Jacob Finkelman
d19273c04d If the only path is a loop then counted as the shortest path. 2023-11-14 20:18:43 +00:00
Jacob Finkelman
cd2e4e3912 add a test 2023-11-14 20:18:43 +00:00
Ed Page
9ca6376f29 fix(resolver): Don't do git fetches when updating workspace members
Before, when running `cargo update <member>`, we'd not reuse the
previous resolve result and when the resolver started walking into the
dependencies, it would do a git fetch.

Now, we won't even try to resolve the workspace members and so we won't
look at those dependencies and do git fetch.

This will make `cargo update <workspace-member>`
match `cargo update --workspace`.
I considered whether there were other ways of handling this but I
figured aiming for consistency in approaches was the best way.
We can investigate improving those approaches separately.

There are other discrepancies in the different code paths (handling of
patches, adding sources) but I'm deferring looking over those.

Between this and #12602, this should finnally resolve #12599.

Fixes #12599
2023-11-14 13:47:10 -06:00
Ed Page
80225bbf46 test(update): Verify --workspace behavior
Looks like `--workspace` and `-p <workspace-member>` behave differently.
2023-11-14 12:05:19 -06:00
David Hotham
962d89a8d8
fix error message for duplicate links 2023-11-14 17:53:58 +00:00
bors
dd94e9d9ce Auto merge of #12944 - linyihai:issue_12790, r=weihanglo
Only filter out target if its in the package root

### What does this PR try to resolve?
Only filter out target if its in the package root. Fixed https://github.com/rust-lang/cargo/issues/12790

### How should we test and review this PR?
Add two testcase in tests/testsuite/package.rs for this PR.

- `include_files_called_target_project` testcase test the logic for none git repository. By the way, our PR was based on git repository,  so this testcase was a little irrelevant.
-  `include_files_called_target_git` testcase was made for git repository.  There are two cases here, one is the target in the uncommitted state, at this time should not be included, and one is the target in the committed state, at this time should be included

### Additional information
2023-11-14 13:39:28 +00:00
Lin Yihai
b2b026bfbb Improve testcase include_files_called_target_git 2023-11-14 11:25:11 +08:00
Eric Huss
8161ba50cd Ignore changing_spec_relearns_crate_types on windows-gnu 2023-11-13 19:17:51 -08:00
bors
a4764b0dd8 Auto merge of #12962 - hi-rustin:rustin-patch-cargo-search, r=weihanglo
Improve about information of `cargo search`
2023-11-13 12:40:10 +00:00
hi-rustin
918d32b34d Improve about information of cargo search
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-13 19:50:21 +08:00
Eric Huss
80ffb1de1c Fix --quiet being used with nested subcommands.
This fixes an issue where `--quiet` doesn't work with commands that have
subcommands. This is because `config_configure` only looks at the global
and top-level subcommand, and not deeper subcommands. The issue was that
`--quiet` was not defined as a global flag. This was changed in
https://github.com/rust-lang/cargo/pull/6358 in order to give a better
help message for `cargo test --quiet`. I don't remember if clap just
didn't support overriding at the time, or if we just didn't know how it
worked. Anyways, it seems to work to override it now, so I think it
should be fine to mark it as global.

This should bring in `--quiet` more in-line with how `--verbose` works.
This means that `--quiet` is now accepted with `cargo report`,
`cargo help`, and `cargo config`.

This also fixes `--quiet` with `cargo clean gc`.

This should also help with supporting `--quiet` with the new `cargo
owner` subcommands being added in
https://github.com/rust-lang/cargo/pull/11879.

Fixes #12957
2023-11-12 11:17:43 -08:00
Eric Huss
0cd970b1c0 Move gc options under a cargo clean gc subcommand.
This was requested to separate the interaction of `cargo clean` and the
cleaning of global cache data, and to minimize the impact of this
initial implementation.
2023-11-11 12:36:25 -08:00
Eric Huss
9a41a6110c Remove shared-target gc kind.
This kind is unlikely to be implemented in the foreseeable future, and
we don't really know what it is going to look like.
2023-11-11 10:56:58 -08:00
Eric Huss
ead7904ad4 Add gc tracing target. 2023-11-11 10:56:58 -08:00
Eric Huss
da3ca05677 Add a global cache garbage collector.
This adds a garbage collector which will remove old files from cargo's
global cache.

A general overview of the changes here:

- `cargo::core::global_cache_tracker` contains the `GlobalCacheTracker`
  which handles the interface to a sqlite database which stores
  timestamps of the last time a file was used.
- `DeferredGlobalLastUse` is a type that implements an optimization for
  collecting last-use timestamps so that they can be flushed to disk all
  at once.
- `cargo::core::gc` contains the `Gc` type which is the interface for
  performing garbage collection. It coordinates with the
  `GlobalCacheTracker` for determining what to delete.
- Garbage collection can either be automatic or manual. The automatic
  garbage collection supports some config options for defining when
  it runs and how much it deletes.
- Manual garbage collection can be performed via options to `cargo
  clean`.
- `cargo clean` uses the new package cache locking system to coordinate
  access to the package cache to prevent interference with other cargo
  commands running concurrently.
2023-11-11 10:56:58 -08:00
Lin Yihai
722d8f1c1d Add target folder but not committed 2023-11-10 15:49:57 +08:00
Lin Yihai
4577c0ec61 Correct the situation with git repository test cases 2023-11-10 14:22:03 +08:00
Karel Peeters
2c503f89c4 Add unit test for files called target.
https://github.com/rust-lang/cargo/issues/12790
2023-11-10 10:38:26 +08:00
bors
2ef56214b3 Auto merge of #12939 - hi-rustin:rustin-patch-feature-msg, r=epage
Fix the invalidate feature name message
2023-11-08 17:15:01 +00:00
hi-rustin
976835d045 Update the test for the msg change
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-08 23:40:24 +08:00
hi-rustin
d61816465f Add test for empty feature name
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-08 22:52:35 +08:00
Ed Page
e70e310ce0 fix: Report more detailed semver errors
For `cargo install` we'll now show a more specific parse error for
semver, much like other parts of cargo.

This came out of my work on #12801.  I was looking at what might be
appropriate to put in a `cargo-util-semver` crate and realized we have
the `ToSemver` trait that exists but doesn't do much, so I dropped it.
2023-11-06 15:24:32 -06:00
hi-rustin
fb0bbe36f1 Search dep in other tables and update tests
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-07 09:33:44 +08:00
bors
f095603db0 Auto merge of #12923 - Eh2406:bug_12920, r=epage
Bug 12920

Fix for #12920, a regression introduced in #12749.

This also as a test case for an existing Terrible error message.
2023-11-06 20:58:55 +00:00
Jacob Finkelman
7997306a0b restore error message 2023-11-06 20:16:26 +00:00
Jacob Finkelman
2352cbd1f9 add a test 2023-11-06 20:13:56 +00:00
bors
4300dd7394 Auto merge of #12911 - epage:manifest-schema, r=weihanglo
refactor(toml): Pull out the schema

### What does this PR try to resolve?

On its own, this PR is a net negative for readability / complexity.  It moves all of the serde types related to manifest from `toml/mod.rs` to `toml/schema.rs`, leaving a lot of the functions and some trait implementations back in `toml/mod.rs` (some basic functions that made sense for the type on their own were also moved).

So why do this?  This is an ooch towards having the schema broken out into a separate package (#12801).  To do this, we need to
- Identify what all types need to be put in the package.  This refactor highlights the dependence on `RustVersion` and `PackageIdSpec`
- Highlights what functionality we need to find a new home for

Follow up PRs would
- Find better homes for the logic in `toml/mod.rs`, moving us away from having `impl schema::Type` blocks.
- Pull out a `src/cargo/util_semver` package to own `PartialVersion` (at least) as prep for making a `cargo-util-semver` package
- Move `RustVersion` to `manifest-toml/schema.rs`, deciding what functionality needs to move with the type
- Move or copy `PackageIdSpec` into `manfest-toml/schema.rs`, deciding what functionality remain in `core/` and what moves over
- Move `toml/schema.rs` to `src/cargo/util_schema`
- Actually make `cargo-util-semver` and `cargo-util-manifest-schema` packages

So why do this now? This is a big change!  By being incremental
- Reduce churn for me and others
- Be easier to review
- Collect feedback as we go on the whole plan to avoid more painful changes later

We *can* back this out if needed but the further we go, the more painful it will be.

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

### Additional information
2023-11-06 19:49:14 +00:00
Ed Page
c12c4c3f8d tests: Remove plugin tests
Compiler plugins were removed in rust-lang/rust#116412, so we don't need
these tests.

As for the `plugin` field on build-targets, it appears to be
[stable-but-deprecated](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-plugin-field),
so I left it alone
2023-11-06 09:55:31 -06:00
bors
65e297d1ec Auto merge of #12915 - epage:test-targets, r=weihanglo
fix(cli): Clarify --test is for targets, not test functions

We already refer to test targets as "test targets" instead of "tests" in `--test` but not `--tests` or in the error output.  This makes it uniformly refer to them as "test targets", making it clearer that these aren't test functions.

Fixes #7864
2023-11-03 20:56:31 +00:00
Ed Page
76918a0e99 fix(cli): Clarify --test is for targets, not test functions
We already refer to test targets as "test targets" instead of "tests" in
`--test` but not `--tests` or in the error output.  This makes it
uniformly refer to them as "test targets", making it clearer that these
aren't test functions.

Fixes #7864
2023-11-03 15:45:00 -05:00
bors
6354bb3d81 Auto merge of #12908 - weihanglo:profile-merge-trim-paths, r=epage
fix: merge `trim-paths` from different profiles
2023-11-02 12:29:20 +00:00
Weihang Lo
7535971d8b
fix(trim-paths): merge trim-paths from different profiles
In 4d29af1 we forgot to add trim-paths to `fn merge()`.
This commit follows how `-Zprofile-rustflags` works ---
overriding instead of merging array.
2023-11-01 23:24:15 -04:00
Weihang Lo
618701921d
test(trim-paths): profile merge doesn't work
This demonstrate the buggy behavior that
profile merge on `trim-paths` doesn't work as expected.
2023-11-01 23:19:49 -04:00
Ed Page
9a1bbc9625 refactor(toml): Pull out schema
Remaining steps
- Decouple `toml/mod.rs` functionality from `toml/schema.rs`
- Pull out `core/` types referenced by `toml/schema.rs`
2023-11-01 20:59:46 -05:00
David Tolnay
649a14d470
Add regression test for issue 6915: features and transitive dev deps 2023-11-01 14:22:16 -07:00
renovate[bot]
b4efcdbf32 chore(deps): update rust crate gix to 0.55.2 2023-11-01 00:12:37 +00:00
Weihang Lo
dd0aea350c
feat(trim-paths): set env CARGO_TRIM_PATHS for build scripts 2023-10-31 12:00:48 -04:00
bors
4aee12c1f8 Auto merge of #12625 - weihanglo:rfc3127, r=epage
feat: implement RFC 3127 `-Ztrim-paths`
2023-10-31 02:23:00 +00:00
Weihang Lo
63cef2c4fc
feat(trim-paths): rustc invocation integration 2023-10-30 16:38:56 -04:00
Weihang Lo
557fc4fd3e
test(trim-paths): verify current behavior with -Ztrim-paths 2023-10-30 16:38:55 -04:00
Weihang Lo
08c5e35f60
test(trim-paths): parsing in mainfest and config 2023-10-30 16:38:55 -04:00
Weihang Lo
4d29af1d81
feat(trim-paths): parsing in mainfest and config 2023-10-30 16:38:55 -04:00
bors
04621e2e0f Auto merge of #12779 - calavera:workspace_adds_implicit_members, r=epage
Add new packages to [workspace.members] automatically

### What does this PR try to resolve?

If a new package is created in a workspace, this change adds the package's path to the workspace's members list automatically.

It doesn't add the package to the list if the path is in the workspace's exclude list, or if the members list doesn't exist already. I noticed that a `cargo_new` test broke if I create the members list when it doesn't exist. This is because the workspace's manifest can be used for package templating. I think it's better to not break that use case.

Fixes #6378

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

I've included tests in the `cargo_new` suite.
2023-10-29 03:02:08 +00:00
David Calavera
1a8bfdf0cf Update workspace manifest with new members.
When a user runs `cargo new` or `cargo init` within a workspace, Cargo will automatically add the new package to the members list in the workspace if necessary. The heuristic to add the new package is as follows:

- If there is no `members` list in the workspace yet, a new `members` list is created.
- If there is an `exclude` statement, Cargo checks if the new package should be excluded. If it doesn't match the `exclude` list, the package is added to the `members` list.
- If there is a glob expression in the `members` list that matches the new package, the package is not added to the `members` list.
- If the existent `members` list is sorted, Cargo tries to preserve the ordering when it adds the new package.

This change doesn't try to format the resulting `members` list in any way, leaving the formatting decissions to the user.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2023-10-28 07:42:23 -07:00
Ed Page
acc52f362b refactor(toml): Decouple parsing from interning system
To have a separate manifest API (#12801), we can't rely on interning
because it might be used in longer-lifetime applications.

I consulted https://github.com/rosetta-rs/string-rosetta-rs when
deciding on what string type to use for performance.

Originally, I hoped to entirely replacing string interning.  For that, I
was looking at `arcstr` as it had a fast equality operator.  However,
that is only helpful so long as the two strings we are comparing came
from the original source.  Unsure how likely that is to happen (and
daunted by converting all of the `Copy`s into `Clone`s), I decided to
scale back.

Concerned about all of the small allocations when parsing a manifest, I
assumed I'd need a string type with small-string optimizations, like
`hipstr`, `compact_str`, `flexstr`, and `ecow`.
The first three give us more wiggle room and `hipstr` was the fastest of
them, so I went with that.

I then double checked macro benchmarks, and realized `hipstr` made no
difference and switched to `String` to keep things simple / with lower
dependencies.

When doing this, I had created a type alias (`TomlStr`) for the string
type so I could more easily swap it out if needed
(and not have to always write out a lifetime).
With just using `String`, I went ahead and dropped that.

I had problems getting the cargo benchmarks running, so I did a quick
and dirty benchmark that is end-to-end, covering fresh builds, clean
builds, and resolution.  I ran these against a fresh clone of cargo's
code base.
```console
$ ../dump/cargo-12801-bench.rs run
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/cargo -Zscript -Zmsrv-policy ../dump/cargo-12801-bench.rs run`
warning: `package.edition` is unspecified, defaulting to `2021`
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/epage/.cargo/target/0a/7f4c1ab500f045/debug/cargo-12801-bench run`
$ hyperfine "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     119.3 ms ±   3.2 ms    [User: 98.6 ms, System: 20.3 ms]
  Range (min … max):   115.6 ms … 124.3 ms    24 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     119.4 ms ±   2.4 ms    [User: 98.0 ms, System: 21.1 ms]
  Range (min … max):   115.7 ms … 123.6 ms    24 runs

Summary
  ../cargo-old check ran
    1.00 ± 0.03 times faster than ../cargo-new check
$ hyperfine --prepare "cargo clean" "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     20.249 s ±  0.392 s    [User: 157.719 s, System: 22.771 s]
  Range (min … max):   19.605 s … 21.123 s    10 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     20.123 s ±  0.212 s    [User: 156.156 s, System: 22.325 s]
  Range (min … max):   19.764 s … 20.420 s    10 runs

Summary
  ../cargo-new check ran
    1.01 ± 0.02 times faster than ../cargo-old check
$ hyperfine --prepare "cargo clean && rm -f Cargo.lock" "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     21.105 s ±  0.465 s    [User: 156.482 s, System: 22.799 s]
  Range (min … max):   20.156 s … 22.010 s    10 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     21.358 s ±  0.538 s    [User: 156.187 s, System: 22.979 s]
  Range (min … max):   20.703 s … 22.462 s    10 runs

Summary
  ../cargo-old check ran
    1.01 ± 0.03 times faster than ../cargo-new check
```
2023-10-27 12:09:44 -05:00
Ed Page
293f2250d6 feat(doc): Print the generated docs links
I've wanted something like this myself.  I dislike using `--open`
because I tend to move up to re-run my `cargo doc` run but then have to
edit it to remove `--open`.
Also makes it annoying when opening docs when `cargo doc` is wrapped by
a tool like `make`.

This was previously attempted in #5592:
- Unlike the request in #5562, this aligns with #5592 in always printing
  rather than using a flag as this seems generally useful
- Unlike #5592, this prints as an alternative to "Opening" to keep
  things light
- Unlike #5592, this prints afterwards as the link is only valid then

Fixes #5562
2023-10-19 10:51:56 -05:00
bors
307486ed18 Auto merge of #12786 - epage:version, r=weihanglo
feat(toml): Allow version-less manifests

### What does this PR try to resolve?

Expected behavior with this PR:
- `package.version` defaults to `0.0.0`
- `package.publish` is defaulted to `version.is_some()`

This also updates "cargo script" to rely on this new behavior.

My motivation is to find ways to close the gap between "cargo script" and `Cargo.toml`.  With "cargo script", we want to allow people to only write however much of a manifest is directly needed for the work they are doing (which includes having no manifest).  Each difference between "cargo script" and `Cargo.toml` is a cost we have to pay in our documentation and a hurdle in a users understanding of what is happening.

There has been other interest in this which I also find of interest (from #9829):
- Lower boilerplate, whether for [cargo xtasks](https://github.com/matklad/cargo-xtask), nested packages (rust-lang/rfcs#3452), etc
- Unmet expectations from users because this field is primarily targeted at registry operations when they want it for their marketing version (#6583).
- Make "unpublished" packages stand out

This then unblocks unifying `package.publish` by making the field's default based on the presence of a version as inspired by the proposal in #9829.  Without this change, we were trading one form of boilerplate (`version = "0.0.0"`) for another (`publish = false`).

Fixes #9829
Fixes #12690
Fixes #6153

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

The initial commit has test cases I thought would be relevant for this change and you can see how each commit affects those or existing test cases.  Would definitely be interested in hearing of other troubling cases to test

Implementation wise, I made `MaybeWorkspaceVersion` deserializer trim spaces so I could more easily handle the field being an `Option`.  This is in its own commit.

### Additional information

Alternatives considered
- Making the default version "stand out more" with it being something like `0.0.0+HEAD`.  The extra noise didn't seem worth it and people would contend over what the metadata field *should be*
- Make the default version the lowest version possible (`0.0.0-0`?).  Unsure if this will ever really matter especially since you can't publish
- Defer defaulting `package.publish` and instead error
  - Further unifying more fields made this too compelling for me :)
- Put this behind `-Zscript` and make it a part of rust-lang/rfcs#3502
  - Having an affect outside of that RFC, I wanted to make sure this got the attention it deserved rather than getting lost in the noise of a large RFC.
- Don't just default the version but make packages versionless
  - I extended the concept of versionless to `PackageId`'s internals and saw no observable difference
  - I then started to examine the idea of version being optional everywhere (via `PackageId`s API) and ... things got messy especially when starting to look at the resolver.  This would have also added a lot of error checks / asserts for "the version must be set here".  Overall, the gains seemed questionable and the cost high, so I held off.
2023-10-27 16:09:12 +00:00
Urgau
e396904b25 Add feature gate test for check-cfg config, build script and override 2023-10-27 17:10:49 +02:00
bors
fcc3786d73 Auto merge of #12868 - hi-rustin:rustin-patch-install, r=weihanglo
Remove duplicate binaries during install
2023-10-27 01:28:20 +00:00
hi-rustin
731ae05ae3 Dedup the same version binaries
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-27 09:16:18 +08:00