16927 Commits

Author SHA1 Message Date
bors
ecb89a1a4e Auto merge of #13606 - dvdhrm:pr/initlib, r=weihanglo
cargo/init: avoid target.name assignments if possible

Make `cargo init` skip `target.name` assignments if the default value is suitable.

Currently, all paths of `cargo init` will set target-names to the package-name, ensuring that a suitable target-name is set. This is required for all targets but libraries. Unfortunately, library-names have more restrictions than other targets. For example, creating a library with dashes will lead to errors:

    mkdir foo-bar
    cd foo-bar
    touch foo-bar.rs
    cargo init --lib

Fortunately, target-names for libraries are inferred from the package-name. Hence, by omitting the target-name, a valid configuration will be produced.

Instead of adjusting `SourceFileInformation::target_name` to use `Option<String>`, this commit strips the field completely, since all callers set it to the package-name.

Fixes: #11259
2024-03-19 15:39:48 +00:00
bors
3e7852bb65 Auto merge of #13602 - mrobinson:fix-minor-grammar-error, r=weihanglo
chore: Fix minor grammar nit in command-line help

This change fixes a *very* minor grammar mistake. "Require" used in this way is
typically followed by the infinitive. In addition, since "up-to-date" is used
an adjective now it should be hyphenated.

See https://www.merriam-webster.com/dictionary/up-to-date

### Testing

I have run `cargo test` with `CFG_DISABLE_CROSS_TESTS=1` as well as `cargo
build-man` to regenerate the man pages.

Fixes #13601.
2024-03-19 15:04:32 +00:00
David Rheinsberg
b673c1010f cargo/init: avoid target.name assignments if possible
Make `cargo init` skip `target.name` assignments if the default value is
suitable.

Currently, all paths of `cargo init` will set target-names to the
package-name, ensuring that a suitable target-name is set. This is
required for all targets but libraries. Unfortunately, library-names
have more restrictions than other targets. For example, creating a
library with dashes will lead to errors:

    mkdir foo-bar
    cd foo-bar
    touch foo-bar.rs
    cargo init --lib

Fortunately, target-names for libraries are inferred from the
package-name. Hence, by omitting the target-name, a valid configuration
will be produced.

Instead of adjusting `SourceFileInformation::target_name` to use
`Option<String>`, this commit strips the field completely, since all
callers set it to the package-name.

Signed-off-by: David Rheinsberg <david@readahead.eu>
2024-03-19 11:07:41 +01:00
bors
1e70a10a25 Auto merge of #13604 - weihanglo:version-bump, r=epage
Bump to 0.80.0; update changelog

[rendered](https://github.com/weihanglo/cargo/blob/version-bump/CHANGELOG.md)
2024-03-18 21:34:35 +00:00
Weihang Lo
d85644ea55
Update changelog for 1.79.0 2024-03-18 17:29:31 -04:00
Weihang Lo
6706ee9c35
Update changelog for 1.78.0 2024-03-18 17:29:31 -04:00
Weihang Lo
e6dccf946f
Bump to 0.80.0 2024-03-18 11:44:35 -04:00
Martin Robinson
8fa25ba41d chore: Fix minor grammar nit in command-line help
A *very* minor grammar correction. "Require" used in this way is
typically followed by the infinitive.
2024-03-18 14:32:28 +01:00
bors
69726309bf Auto merge of #12783 - dvdhrm:pr/libname2, r=ehuss
cargo: prevent dashes in lib.name

The TOML parser of Cargo currently refuses `lib.name` entries that contain dashes. Unfortunately, it uses the package-name as default if no explicit `lib.name` entry is specified. This package-name, however, can contain dashes.

Cargo documentation states that the package name is converted first, yet this was never implemented by the code-base.

Fix this inconsistency and convert the package name to a suitable crate-name first.

This fixes #12780. It is an alternative to #12640.
2024-03-16 20:50:35 +00:00
bors
2fe739fcf1 Auto merge of #13591 - epage:namespace, r=weihanglo
feat: Add 'open-namespaces' feature

### What does this PR try to resolve?

This is a step towards #13576

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

### Additional information
2024-03-15 21:39:18 +00:00
bors
36108cbebf Auto merge of #13593 - epage:toml2, r=Muscraft
refactor: Expose source/spans to Manifest for emitting lints

### What does this PR try to resolve?

This is a follow up to #13589.

This does nothing on its own.

This is meant to short-circuit some of my refactorings so Muscraft can
start on their work on adding lints while I work to move out existing
warnings into being able to be converted to lints.

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

This includes documentation changes suggested in #13589

### Additional information
2024-03-15 21:09:29 +00:00
bors
c319962079 Auto merge of #13337 - epage:unicode, r=weihanglo
feat(tree): Control `--charset` via auto-detecting config value

### What does this PR try to resolve?

This tries to generalize `cargo tree --charset` so any part of cargo's output can use it.  For example,
- `cargo search` could use this for fancier tables
- `cargo add` could use this for fancier feature lists
- #12235 could use this for fancy rendering like miette does (CC `@Muscraft` )
- Progress bars could use fancier characters <-- this is what I'm personally working towards

This builds on the idea from #12889 that we can use fancier terminal features so long as we have good auto-detection and provide users an escape hatch until the auto-detection is improved or in case they disagree.

As a side benefit
- `cargo tree` will auto-detect when the prior default of `--charset utf8` is a good choice
- Users can control `cargo tree --charset` via `.cargo/config.toml`

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

This is gradually introduced through the individual commits.

### Additional information
2024-03-15 20:41:31 +00:00
Ed Page
a1fc7fe269 refactor: Expose source/spans to Manifest for emitting lints
This does nothing on its own.

This is meant to short-circuit some of my refactorings so Muscraft can
start on their work on adding lints while I work to move out existing
warnings into being able to be converted to lints.
2024-03-15 15:41:03 -05:00
Ed Page
196e8b44e7 docs: Explain what a resolved toml is 2024-03-15 15:29:56 -05:00
Ed Page
05feb07245 refactor: Group 'Manifest' accessors like we did the fields 2024-03-15 15:29:31 -05:00
bors
48fb957dcc Auto merge of #13589 - epage:toml, r=Muscraft
refactor(toml): Flatten manifest parsing

### What does this PR try to resolve?

This is just a clean up but the goals are
- Support diagnostics that show source by tracking `&str`, `ImDocument`, etc in `Manifest` by making each accessible in the creation of a `Manifest`
- Defer warning analysis until we know what is a local vs non-local workspace by refactoring warnings out into a dedicated step
- Centralize the logic for `cargo publish` stripping of dev-dependencies and their feature activations by allowing a `Summary` to be created from any "resolved" `TomlManifest`
- Enumerate all build targets in the "resolved" `TomlManifest` so they get included in `cargo publish`, reducing the work done on registry dependencies and resolving problems like #13456

Along the way, this fixed a bug where we were not reporting warnings from virtual manifests

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

### Additional information
2024-03-15 19:50:39 +00:00
Ed Page
9ea3f260a8 feat(toml): Add support for open namespaces 2024-03-15 12:54:05 -05:00
Ed Page
489dde1114 test: Show open-namespaces behavior 2024-03-15 12:53:55 -05:00
Ed Page
4ed67e3a33 refactor(toml): Flatten convert_toml
This is to work towards tracking everything needed for diagnostics in
`Manifest`
2024-03-15 12:00:06 -05:00
Ed Page
dd56d79c83 refactor(toml): Only collect nested paths when needed
This simplifies the interface for `toml/mod.rs` and reduces the work we
do.
2024-03-15 12:00:06 -05:00
Ed Page
954142e582 refactor(toml): Move path workspace dep validation out of convert_toml
This is part of an effort to remove `convert_toml`
2024-03-15 12:00:06 -05:00
Ed Page
37c3080bea refactor(toml): Move path processing out of convert_toml
This is in an effort to remove `convert_toml`
2024-03-15 12:00:06 -05:00
Ed Page
ff454fd452 refactor(toml): Consolidate how we track unused keys
This makes it act more like everything else, making this easier to
evolve over time.
2024-03-15 12:00:06 -05:00
Ed Page
714359289d fix(toml): Produce warnings for virtual manifests
This is prep for shifting unused keys warnings out of `convert_toml`
2024-03-15 12:00:06 -05:00
Ed Page
fcc6981d00 refactor(toml): Centralize error wrapping 2024-03-15 12:00:06 -05:00
Ed Page
65bf96a10b fix(toml): Remove redundant trace 2024-03-15 12:00:06 -05:00
Ed Page
401c502e6a refactor(toml): Consolidate no-target errors
Moving this out for collapsing `convert_toml`
2024-03-15 12:00:06 -05:00
Ed Page
a7b70e98f9 refactor(toml): Pull out unused warning code 2024-03-15 12:00:06 -05:00
Ed Page
8cd94e4cc4 refactor(toml): Simplify virtual manifest check 2024-03-15 12:00:06 -05:00
Ed Page
069c67a9aa refactor(toml): Move steps to top-level
Before, we split things up.  This makes it so everything has access to
every step so we can reap the benefits
- use `&str` and `ImDocument` for diagnostics
- access `original`
2024-03-15 12:00:06 -05:00
Ed Page
b1743463bc refactor(toml): Pull out toml parsing
So we can track spans for diagnostics
2024-03-15 12:00:06 -05:00
Ed Page
c272cd7e37 refactor(toml): Resolve toml_edit deprecations 2024-03-15 12:00:06 -05:00
Ed Page
66b19adaa0 refactor(toml): Pull out deserialize code
- So we can eventually track the `original`
- So we can track spans for diagnostics
2024-03-15 12:00:06 -05:00
Ed Page
490583a573 refactor(toml): Pull out diagnostic emitting 2024-03-15 12:00:06 -05:00
Ed Page
69ee34a274 refactor(toml): Pull fs out as explicit step
So diagnostics can use this for reporting.
2024-03-15 12:00:06 -05:00
Ed Page
89f1cce439 refactor: Clarify what Manifest::original means
I plan to add a true `original`
2024-03-15 12:00:05 -05:00
Ed Page
b321285501 refactor(schema): Decouple forms of name validation 2024-03-15 11:49:07 -05:00
Ed Page
b8a684674a feat: Add 'open-namespaces' feature
This is a step towards #13576
2024-03-15 11:23:18 -05:00
Ed Page
c8fa7096d4 refactor: Group alt Manifest formats
This is prep for adding more
2024-03-15 10:37:30 -05:00
bors
403fbe2b49 Auto merge of #13518 - baby230211:fix/strip-feature-dev-dep, r=epage
fix: strip feature dep when dep is dev dep

### What does this PR try to resolve?
This change aims to strip features dependencies without a version key to be published.
If a dev-dependency is missing the version, it will be stripped from the packaged manifest.

The features table may contains the deps in following places.
- Target
  - normal
  - dev
  - build
  - normal-and-dev
- normal
- dev
- build
- normal-and-dev

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

See the initial commit, it shows current behavior that will cause error when feature has deps that point to dev_dep and doesn't have a version specified.

Title | orignal toml | published toml |
---- | ---- | ---- |
Before |   feature = ["dev-dep/feature"]  <br/> [dev-dependencies] <br/> dev-dep = { .., features: ["feature"] }   |   feature = ["dev-dep/feature"] <br/> [dev-dependencies] <br/> dev-dep = { .., features: ["feature"] } |
After |  feature = ["dev-dep/feature"]  <br/> [dev-dependencies] <br/> dev-dep = { .., features: ["feature"] }  | feature = [] <br/> [dev-dependencies] ```

Fix: #12225
2024-03-14 20:20:14 +00:00
bors
601670a218 Auto merge of #13581 - LuuuXXX:issue-12692, r=weihanglo
fix(ci): bump check error when PR is behind master

### What does this PR try to resolve?

Fixes: https://github.com/rust-lang/cargo/issues/12692
2024-03-14 14:05:25 +00:00
LuuuX
fb616a0f69 fix: bump check error 2024-03-14 21:28:14 +08:00
SeanHsieh
75130eb6e3 fix(add): strip feature dep when dep is dev dep or target dev dep 2024-03-14 14:27:21 +08:00
bors
7065f0ef4a Auto merge of #13575 - pavedroad:master, r=ehuss
chore: remove repetitive word
2024-03-12 13:25:15 +00:00
SeanHsieh
465e36150c test(add): add publish feature contains different kinds dep 2024-03-12 20:42:45 +08:00
pavedroad
b540813a90 chore: remove repetitive words
Signed-off-by: pavedroad <qcqs@outlook.com>
2024-03-12 14:40:20 +08:00
bors
685c18d17e Auto merge of #13564 - epage:r, r=weihanglo
refactor(lockfile): Make diffing/printing more reusable

### What does this PR try to resolve?

This is prep for #13561 so we can tailor the printing of lockfile changes to each use without a bunch of flags.

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

### Additional information
2024-03-12 00:48:46 +00:00
bors
fe5de0755d Auto merge of #13567 - LuuuXXX:issue-7876, r=weihanglo
test: Add tests for using worktrees and sparse checkouts

### What does this PR try to resolve?

Based on `@eminence's` [comment](https://github.com/rust-lang/cargo/issues/7876#issuecomment-1325974682), Add tests for using worktrees or spase checkouts.

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

Checkout and run tests:
```
cargo test --package cargo --test testsuite -- git::git_worktree_with_original_repo_renamed
```
```
cargo test --package cargo --test testsuite -- git::git_worktree_with_bare_original_repo
```
2024-03-11 15:44:10 +00:00
LuuuX
062d8ce66a Add tests for using worktrees and sparse checkouts 2024-03-11 23:00:09 +08:00
bors
d79fdf33ee Auto merge of #13548 - Turbo87:user-agent, r=weihanglo
util/network/http: Use `cargo/1.2.3` user-agent header

... instead of `cargo 1.2.3`.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent#syntax declares that the product and product version are usually separated by a slash. This commit changes the cargo `User-Agent` header to follow that syntax instead of using whitespace for the separator.
2024-03-09 16:16:37 +00:00