Commit graph

5570 commits

Author SHA1 Message Date
Angelo Ross 72dccecb19
Display only feature list or summarized on cargo add 2023-09-19 13:14:44 -03:00
Ed Page a365a69130 test(embedded): Migrate to new syntax 2023-09-18 14:47:56 -05:00
Ethan Brierley 9831e83fb2 generalise suggestion on abiguous spec
Fixes #12433
2023-09-18 16:34:17 +01:00
bors 695416e8d8 Auto merge of #12660 - epage:dry, r=weihanglo
feat(cli): Add '-n' to dry-run

This came from #12638 and my many small frustrations from wanting to use `-n` and not being able to.

We do not have any existing `-n` flags for this to be confused with.

I would wager that `-n` is such an entrenched short flag in build tools that it would not make sense for us to use it with any other flag.

For a survey of where `-n` is used as a short, see https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table
2023-09-18 02:53:19 +00:00
bors 7149418ed3 Auto merge of #12649 - arlosi:cred-stable, r=weihanglo
feat: stabilize credential-process and registry-auth

Stabilization PR for `registry-auth` and `credential-process`.

Tracking approval of this stabilization is done in the via the FCP in [#8933](https://github.com/rust-lang/cargo/issues/8933#issuecomment-1711990123). This PR is here to help reviewers of the FCP.

* Stabilizes `registry-auth` and `credential-process`
* Makes authenticated registries require a credential provider
* Adds stable documentation for credential providers and authenticated registries

Closes #8933
Closes #10474
2023-09-18 01:17:44 +00:00
bors 41cef471d0 Auto merge of #12677 - weihanglo:registry-or-index, r=hi-rustin
refactor: use `RegistryOrIndex` enum to replace two booleans
2023-09-17 15:19:48 +00:00
Arlo Siemsen d345ca212f feat: stabilize credential-process and registry-auth 2023-09-16 22:40:45 -05:00
Weihang Lo e883054c59
test: verify publish failed with --index and the only implicit allowed registry
The message is misleading and shouldn't proceed when `--index` presents.
2023-09-16 00:48:41 +08:00
Weihang Lo e57ce13da8
refactor: --registry always conflicts with --index
Move the validation upfront to clap
2023-09-15 22:33:27 +08:00
Weihang Lo 1f172e4b76
refactor: extract registry and index arg for reuse 2023-09-15 18:30:28 +08:00
Arlo Siemsen 8f18f2bdc8 fix: emit a warning when a credential provider alias shadows a built-in provider 2023-09-14 14:33:59 -05:00
bors 5c84ce06f0 Auto merge of #12662 - Angelin01:limit-cargo-add-feature-print, r=weihanglo
Limit cargo add feature print
2023-09-14 13:19:16 +00:00
Angelo Ross 9928689d2c
Limit features printed during cargo add 2023-09-14 08:36:44 -03:00
Ed Page 82f9bd330e feat(spec): Allow partial versions when unambigious
This was proposed in #12425 to help improve usability of the existing
`cargo update` when dealing with the added workflows.
2023-09-13 22:00:00 -06:00
Ed Page 9008647ae2 test(clean): Verify spec version parsing 2023-09-13 21:59:28 -06:00
Ed Page 396298200d test(profile): Verify spec version parsing 2023-09-13 21:59:28 -06:00
Angelo Ross 3a40df85d6
Showcase output with too many features 2023-09-13 11:58:48 -03:00
Ed Page 033e06a1cc feat(cli): Add '-n' to dry-run
This came from #12638 and my many small frustrations from wanting to use
`-n` and not being able to.

We do not have any existing `-n` flags for this to be confused with.

I would wager that `-n` is such an entrenched short flag in build tools that it would
not make sense for us to use it with any other flag.

For a survey of where `-n` is used as a short, see
https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table
2023-09-12 13:42:00 -05:00
Jacob Finkelman dcde7eb316 move pre-release specific error message 2023-09-12 16:06:29 +00:00
loloicci 7880215265 fix error message trying patch non-existing package with prerelease version 2023-09-12 15:57:29 +00:00
loloicci c29c25be2e test error message trying patch non-existing package with prerelease version 2023-09-12 15:57:22 +00:00
Ed Page 385dfb6298 test(registry): Show current too-new schema error
This reproduces the problem in #10623.
2023-09-11 16:19:15 +00:00
Ed Page 293b71a961 test(registry): Provide more room from tests conflicting with reality 2023-09-11 16:19:15 +00:00
bors c2d26f32d3 Auto merge of #12578 - epage:help, r=weihanglo
feat(help): Add styling to help output

### What does this PR try to resolve?

Try to make `--help` output easier to parse by using terminal styling

Screenshots:

![Screenshot from 2023-09-06 09-57-11](https://github.com/rust-lang/cargo/assets/60961/61069af4-ef05-40ad-9240-fedea44d4c71)

![Screenshot from 2023-09-06 09-57-21](https://github.com/rust-lang/cargo/assets/60961/d2e69024-42aa-47c0-ad0f-24e43551b8db)

![Screenshot from 2023-09-06 09-57-36](https://github.com/rust-lang/cargo/assets/60961/e3d895e2-745f-48c6-9e84-d6fb67198d6d)

*(`nargo` is my shell script wrapping `cargo run --manifest-path cargo/Cargo.toml`)*

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

At this time, the only styling snapshotting library I know of is a pain to use, so testing this requires manually running the commands which I did.  Screenshots are included for easier evaluation of the general idea.

Snapshotting of the plain text output ensures we don't have accidental formatting regressions from this change since the formatting isn't as obvious from looking at the code.

### Additional information

Traditionally, cargo has disabled clap's styled output.  My assumed
reason is that cargo mixes custom help output with auto-generated and
you couldn't previously make it all styled.
Clap 4.2 allowed users to pass in strings styled using ANSI escape
codes, allowing us to pass in styled text that matches clap, unblocking this.  In clap
4.4.1, clap gained the ability for the user to override the style.

In this PR, I decided to use the new 4.4.1 feature to style clap's
output to match the rest of cargo's output.  Alternatively, we could use
a more subdue style that clap uses by default.

I used the `color-print` crate to allow something almost html-like for styling `&static str`.  Alternatively, we could directly embed the ANSI escape codes harder to get write, harder to inspect), or we could do the styling at runtime and enable the `string` feature in clap.

I decided to *not* style `Arg::help` messages because
- It might be distracting to have the descriptions lit up like a
  christmas tree
- It is a lot more work

The one exception I made was for `--list` since it is for a
psuedo-command (`...`) and I wanted to intentionally draw attention to
it.

#12593 made styling of `cargo -h` cleaner imo.
#12592 and #12594 were improvements I noticed while doing this.
2023-09-11 06:25:47 +00:00
bors 2fc85d15a5 Auto merge of #12648 - epage:lint, r=weihanglo
feat: Stabilize lints

Fixes #12115
2023-09-09 01:49:46 +00:00
bors 8bd32310f5 Auto merge of #12631 - Eh2406:strip_prefix, r=epage
Ues strip_prefix for cleaner code

### What does this PR try to resolve?

In https://github.com/rust-lang/cargo/pull/12629#pullrequestreview-1614154046 Ed pointed out how much cleaner the code can be using `strip_prefix`, so I found a bunch more places where we should be using it.

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

Internal refactor and test still pass.
2023-09-08 20:05:02 +00:00
Jacob Finkelman eb188831da
add a missing is:
Co-authored-by: Eric Huss <eric@huss.org>
2023-09-08 15:14:10 -04:00
Ed Page e539380512 feat: Stabilize lints
Fixes #12115
2023-09-08 10:44:00 -05:00
Arlo Siemsen 803fd6909c fix: don't print _TOKEN suggestion when not applicable
Cargo should not suggest the _TOKEN environment variable
when the cargo:token provider isn't available
2023-09-07 21:14:50 -05:00
Jacob Finkelman 44666f7377 Ues strip_prefix for cleaner code 2023-09-07 17:57:28 +00:00
Weihang Lo e575448574
refactor: flatten module path of SourceId 2023-09-07 21:06:35 +08:00
Weihang Lo b6c4e47cc0
refactor: put Source trait under cargo::sources 2023-09-07 21:06:34 +08:00
Eric Huss f49b038a3f Error out if cargo clean --doc is mixed with -p.
Currently the `-p` is ignored. This should help with any confusion
about the interaction of different flags.
https://github.com/rust-lang/cargo/issues/8790 is tracking to fix this.
2023-09-06 21:42:38 -07:00
bors d9a4cf1938 Auto merge of #12626 - arlosi:cred-error-both, r=weihanglo
fix: improve warning for both token & credential-provider

Cargo issues a warning when both a `credential-provider` and a `token` are configured for a registry.

This change removes the warning if the `credential-provider` is `cargo:token` since that *will* use the token. The warning message text is also tweaked to include the name of the `credential-provider` that's overriding the token.
2023-09-06 18:02:59 +00:00
Arlo Siemsen 3f004c613c fix: improve error for token & provider 2023-09-06 10:10:02 -05:00
hi-rustin 63ccc35642 Add skip gc glob profile test 2023-09-06 12:51:39 +08:00
bors d14c85f4e6 Auto merge of #12602 - epage:resolver, r=Eh2406
fix(resolver): Make resolver behavior independent of package order

This address one of the problems mentioned in #12599

The intent behind the `path_pkg` check is to make sure we update
workspace members in the lockfile if their version number changed.
In this case, we don't need to recursively walk, because the change
doesn't affect dependencies.  However, we also shouldn't *prevent*
recursive walks which is what we are doing today, both for packages
marked to keep and for packages that have been "poisoned".  So we fix
this by moving that call after all recursive adds are complete so as to
not interfere with them.

This should not affect `Cargo.lock` at rest, so no upgrade compatibility concerns.

This just allows more packages to be considered available to change which can prevent unclear failures.

The main case I can think of that this does something "undesirable" is when wanting to prevent another "bug" from manifesting: the updating of git dependencies when updating workspace members (#12599).  I think I'm ok with that as that needs to be looked into separately.
2023-09-05 22:28:10 +00:00
Arlo Siemsen e58b84d35e breaking change(cargo-credential)
Changes the JSON format for cache:expires
2023-09-05 15:22:27 -05:00
Arlo Siemsen b8099be284 fix: make more credential JSON fields skip_serializing if None 2023-09-05 13:31:23 -05:00
bors 5f40a97e5c Auto merge of #12618 - weihanglo:cleanup-170-debuginfo, r=Muscraft
test: new options of debuginfo are no longer unstable
2023-09-03 16:52:20 +00:00
Weihang Lo 63be1e0d8b
test: new options of debuginfo are no longer unstable 2023-09-01 16:19:47 +01:00
Ed Page e46379a7f3 fix(remove): Include 'cargo help' suggestion in -h 2023-09-01 09:30:00 -05:00
Ed Page 802cb380ed fix(cli): Be more specific in what is needed 2023-08-31 08:56:16 -05:00
Ed Page adea3d148e fix(cli): Help people find possible --target values 2023-08-31 08:55:36 -05:00
Ed Page b87c9323bb refactor(cli): Manually implement missing arg error for --target 2023-08-30 20:42:45 -05:00
Ed Page 801b223135 test(cli): Show existing --target behavior 2023-08-30 20:34:42 -05:00
Ed Page a78bba7a92 fix(manifest): Improve error on good pre-release 2023-08-30 16:42:08 -05:00
Ed Page 9fb8128d9e test(manifest): Verify error on good pre-release 2023-08-30 16:42:08 -05:00
bors 0bd1f71579 Auto merge of #12593 - epage:help-list, r=ehuss
fix(help): Provide better commands heading for styling

In working on #12578, I felt it would be weird to style the entire statement about commands but it also felt weird to not style it.  So this change explores an alternatively way of communicating the information.
2023-08-30 19:08:23 +00:00
Ed Page 0af2f65ce8 fix(resolver): Make resolver behavior independent of package order
This addresses the ordering issue of for one of the problems from #12599.

The intent behind the `path_pkg` check is to make sure we update
workspace members in the lockfile if their version number changed.
In this case, we don't need to recursively walk, because the change
doesn't affect dependencies.  However, we also shouldn't *prevent*
recursive walks which is what we are doing today, both for packages
marked to keep and for packages that have been "poisoned".  So we fix
this by moving that call after all recursive adds are complete so as to
not interfere with them.
2023-08-30 13:12:52 -05:00
Ed Page 2676a4ae79 test(update): Verify extra-update behavior 2023-08-30 13:07:15 -05:00
Ed Page 31e414cccb fix(help): Provide better commands heading for styling
In working on #12578, I felt it would be weird to style the entire
statement about commands but it also felt weird to not style it.  So
this change explores an alternatively way of communicating the
information.
2023-08-29 15:31:17 -05:00
bors 40f1f67ea6 Auto merge of #12590 - arlosi:cred-unsupported-error, r=epage
fix: add error for unsupported credential provider version

Cargo currently ignores the version in the `CredentialHello` message, and proceeds to use version `1` regardless of what the credential provider claims it can support.

This change does the following:
* Adds a new error if Cargo doesn't support any of the supported protocol versions offered by the provider.
* Kills the credential provider subprocess if it fails. This prevents it from hanging or printing spurious errors such as "broken pipe" when it's attempting to read the next JSON message.
* Adds a new test for an unsupported credential provider protocol.
2023-08-30 03:35:48 +00:00
Arlo Siemsen 39db61e26e fix: add error for unsupported credential provider version 2023-08-29 21:22:29 -05:00
Ed Page 58fb982f44 fix(help): Explain --explain
In working on #12578, I'm focusing on each help string to decide how it
should be handled and I noticed this.  It feels weird to explain
something in terms of another command's CLI, so I took `rustc --help`s
message and added `rustc` to clarify it.

Looking back, the flag was added in #2551 with the message we have
today.  Nothing seems to really be said about it.

In reflecting on this, I'm not 100% convinced and am open to other
opinions.
2023-08-29 15:21:02 -05:00
bors a873df5c39 Auto merge of #12594 - epage:help-redundant, r=weihanglo
fix(help): Remove redundant information from new/init

Auditing all of the `--help` in prep for #12578 and noticed that we list the VCS information twice, once on our end and once by clap.
2023-08-29 22:36:21 +00:00
Ed Page ad0a11349e fix(help): Remove redundant information from new/init
Auditing all of the `--help` in prep for #12578 and noticed that we list
the VCS information twice, once on our end and once by clap.
2023-08-29 16:28:49 -05:00
bors 96fe1c9e1a Auto merge of #12584 - epage:lints, r=arlosi
fix(lints): Fail when overriding inherited lints

### What does this PR try to resolve?

Overriding of inherited lints was reserved for the future but as pointed out in https://github.com/rust-lang/cargo/issues/12115#issuecomment-1695293006, we aren't failing on these when we should but silently ignoring the overrides.

This turns it into a hard error.

In fixing this, I had to add a `#[serde(expecting)]` attribute to maintain behavior on an error case (otherwise it would say "expecting struct WorkspaceLints").  Since this drew the error message to my attention, I also tweaked it to make it more specific.

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

Commits are broken down by the relevant tests and fixes to make the intended behavior changes obvious.
2023-08-29 20:10:34 +00:00
bors 333ca23bf8 Auto merge of #12575 - cardoso:missing_git_flag, r=arlosi
cargo install: suggest --git when package name is url

### What does this PR try to resolve?

Improve the error message when specifying a URL for a package name in `cargo install`.

Fixes #10485

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

Just cargo test and trying a common case like `cargo install https://github.com/rust-lang/cargo`

### Additional information

I found this PR after finishing this one: #10522
But it seems have a larger scope to refactor some of the related code.

Perhaps this one would be easier to merge and that one could focus on the refactor, otherwise sorry for the noise and feel free to close.
2023-08-29 19:03:00 +00:00
bors 0b29588c61 Auto merge of #12588 - arlosi:logout-is-stable, r=weihanglo
chore: remove unstable-options for logout

`cargo logout` is stable, and doesn't need `masquerade_as_nightly_cargo`
2023-08-29 18:17:10 +00:00
Arlo Siemsen bd4444fbdd chore: remove unstable-options for logout 2023-08-29 11:34:29 -05:00
Arlo Siemsen 0a5050c0d0 Improve logout message for asymmetric tokens 2023-08-29 11:28:02 -05:00
Ed Page c88137cd62 fix(pkgid): More consistently refer to SemVer 2023-08-29 10:49:09 -05:00
Ed Page 4238f689f5 fix(install): More consistently refer to SemVer 2023-08-29 10:49:02 -05:00
Ed Page 3d2f371737 test(pkgid): Add cases for partial versions 2023-08-29 10:40:47 -05:00
Ed Page 018b7589e8 test(pkgid): Focus tests on use cases, rather than success/failure
I assume the reason these aren't all individual tests is test-time but
if we divide by success/failure, I'll need to duplicate things to handle
partial versions.

Overall, I feel like this makes the tests make more sense.
2023-08-29 10:36:36 -05:00
Ed Page 3138f91d4d test(pkgid): Include test for ambiguous spec 2023-08-29 10:29:09 -05:00
Ed Page 82d78097c8 fix(update): Clarify meaning of --aggressive as --recursive
When working on cargo-upgrade, I found the meaning of `--aggressive`
confusing and named it `--recursive` there.

Renaming this in `cargo update` (with a backwards compatible alias) was
referenced in #12425.
2023-08-29 10:18:25 -05:00
Ed Page 66f0b13d47 fix(update): Remove references to -p in help
Missed these in #12545
2023-08-29 08:49:14 -05:00
Ed Page 6568e2c466 fix(lints): Improve error message on bad data 2023-08-28 20:55:29 -05:00
Ed Page 1c578b1a99 fix(lints): Error when overriding workspace lints 2023-08-28 20:34:19 -05:00
Ed Page c63b51deeb test(lints): Show existing package/workspace mix behavior 2023-08-28 13:59:40 -05:00
Matheus Cardoso ecf05e4ff1
cargo install: suggest --git when package name is url 2023-08-27 23:04:21 -03:00
Ethan Brierley 1f80ffabd1 Improve resolver version mismatch warning
fixes: #12557
2023-08-27 21:11:20 +01:00
David Tolnay ece5269e97
Stabilize --keep-going 2023-08-26 13:14:39 -07:00
bors f797978283 Auto merge of #12553 - epage:version, r=weihanglo
refactor: Pull out cargo-add MSRV code for reuse

### What does this PR try to resolve?

#12078 added MSRV code in `cargo add`. Our assumption when writing it is that we'd need to generalize the code before reusing it in other places, like `cargo install`.  This PR focused purely on that refactor because I'm hopeful it will be useful for other work I'm doing.  Despite not having a user for this yet, I think the `cargo install` case is inevitable and I feel this does a bit to clean up MSRV related code by using a more specific type everywhere.

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

Each commit gradually progresses things along
2023-08-25 14:56:24 +00:00
Deadbeef 43dccc7535 apply suggestions 2023-08-25 01:43:29 +00:00
Deadbeef b2b34e4ca2 update tests 2023-08-25 01:43:29 +00:00
Ed Page 1701b4e3d8 fix(manifest): Improve rust-version error messages
Since we have tests for a couple of cases, I figured we could
improve the error messages for them.
2023-08-24 20:29:14 -05:00
bors b2c162c067 Auto merge of #12556 - epage:serde, r=arlosi
fix(toml): Improve parse errors

### What does this PR try to resolve?

When we adopted `toml_edit`, we got TOML syntax errors that showed the context for where the error occurred.  However, the work was not done to extend this to semantic errors reported by serde.

This updates `Cargo.toml` and `Cargo.lock` code to provide that context on semantic errors.  `config.toml` is not done because the schema is decentralized.

In theory, this will also improve performance because we aren't having to allocate a lot of intermediate data to then throw away for every `Cargo.toml` we read.

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

Check by commit to see this change gradually.
- The `package.cargo-features` change was made to drop out dependence on `toml::Table` so we could do the direct deserialization
2023-08-24 23:01:52 +00:00
bors 3b20907926 Auto merge of #12551 - arlosi:asymmetric-token, r=Eh2406
Create dedicated unstable flag for asymmetric-token

Asymmetric tokens are gated by `-Zcredential-process`. Since we're considering stabilizing that soon, this moves asymmetric token support to have its own unstable flag.

It was previously gated by `-Zregistry-auth`, and some of the docs were not updated when it moved.

r? `@Eh2406`
2023-08-24 22:07:16 +00:00
Ed Page 53dcd2f454 fix(manifest): Provide more context on sematic errors 2023-08-24 16:27:53 -05:00
Ed Page 8927ea99d1 refactor(manifest): Process the package.cargo-features error in serde 2023-08-24 16:27:45 -05:00
Ed Page 511c17c961 fix(lock): Render source for serde errors
Before, we'd render the source for TOML syntax errors but not semantic errors.
Now we render for both.

Originally I changed `parse_document` to returned `T: DeserializeOwned`
but that adds an extra "could not parse TOML" which is both redundant
and makes it sound like its a syntax issue.
2023-08-24 16:27:37 -05:00
Ed Page 5cac7aa8c6 fix(toml): Remove redundant error messages 2023-08-24 16:19:48 -05:00
Ed Page 423a334520 refactor: Parse, don't validate, rust_version
By using the `PartialVersion` type with serde, we get the context for
the error automatically.
2023-08-24 14:15:35 -05:00
Arlo Siemsen 8c13e9ae3f Create dedicated unstable flag for asymmetric-token 2023-08-24 00:12:50 -05:00
Ed Page 937932520b refactor(install): Move version parsing to the CLI 2023-08-23 16:22:31 -05:00
Ed Page 28b7c846af refactor(install): Shift crate argument parsing to clap 2023-08-23 15:25:05 -05:00
Ed Page dc3722254d fix(update): Improve error on bad argument order
This is inspired by `cargo install`
2023-08-23 14:44:13 -05:00
Ed Page 4bf1af0cd0 fix(update): Make -p more convenient by being positional
Generally, cargo avoids positional arguments.  Mostly for the commands
that might forward arguments to another command, like `cargo test`.
It also allows some flexibility in turning flags into options.

For `cargo add` and `cargo remove`, we decided to accept positionals
because the motivations didn't seem to apply as much (similar to `cargo
install`).

This applies the pattern to `cargo update` as well which is in the same
category of commands as `cargo add` and `cargo remove`.

As for `--help` formatting, I'm mixed on whether `[SPEC]...` should be at the top like
other positionals or should be relegated to "Package selection".  I went
with the latter mostly to make it easier to visualize the less common
choice.

Switching to a positional for `cargo update` (while keeping `-p` for
backwards compatibility) was referenced in #12425.
2023-08-23 11:57:36 -05:00
bors 0c2b370b35 Auto merge of #12560 - epage:msrv, r=🙈eh2406🙈
feat(resolver): **Very** preliminary MSRV resolver support

### What does this PR try to resolve?

A bare bones implementation of an MSRV resolver that is good enough for people running on nightly when they really need it but is not ready for general use.

Current limitations
- Does not honor `--ignore-version`
- Gives terrible error messages
- Nothing is done yet regarding `cargo install`
- Doesn't inform the user when choosing non-latest

These will be  noted in #9930 on merge.

Implementation wise, this is yet another hack (sorry `@Eh2406).`  Our expectation to get this GA is to refactor the resolver to make the cargo/resolver boundary look a little more like the cargo/pubgrub boundary so we can better control policy without any of these hacks which will also make having all of the policy we need for this easier to maintain.

This is a part of #9930

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

Per commit
2023-08-28 21:11:20 +00:00
bors 97e73c75c7 Auto merge of #12574 - dtolnay-contrib:untagged, r=epage
Improve deserialization errors of untagged enums

### What does this PR try to resolve?

```toml
# .cargo/config.toml

[http]
ssl-version.min = false
```

**Before:**

```console
$ cargo check
error: data did not match any variant of untagged enum SslVersionConfig
```

**After:**

```console
$ cargo check
error: error in /path/to/.cargo/config.toml: could not load config key `http.ssl-version`

Caused by:
  error in /path/to/.cargo/config.toml: `http.ssl-version.min` expected a string, but found a boolean
```

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

The first commit adds tests showing the pre-existing error messages &mdash; mostly just _"data did not match any variant of untagged enum T"_ with no location information. The second commit replaces all `#[derive(Deserialize)] #[serde(untagged)]` with Deserialize impls based on https://docs.rs/serde-untagged/0.1, showing the effect on the error messages.

Tested with `cargo test`, and by handwriting some bad .cargo/config.toml files and looking at the error produced by `rust-lang/cargo/target/release/cargo check`.
2023-08-28 15:06:20 +00:00
bors bfa04bb32b Auto merge of #12535 - hi-rustin:rustin-patch-linker, r=weihanglo
Add support for `target.'cfg(..)'.linker`
2023-08-28 06:14:25 +00:00
hi-rustin 7cbc858b71 Add some tests 2023-08-28 09:29:17 +08:00
hi-rustin 55f0163fb2 Add support for target.'cfg(..)'.linker 2023-08-28 09:28:22 +08:00
David Tolnay 3871aecf3e
Improve deserialization errors of untagged enums 2023-08-27 16:27:08 -07:00
David Tolnay 58d042516e
Fill in more configuration deserialization and manifest deserialization tests 2023-08-27 16:14:29 -07:00
Ed Page 4abd05ea44 test(resolver): Enable msrv-policy
This was kept separate to show that the prior commit didn't change
anything for stable users.
2023-08-25 14:19:22 -05:00
Ed Page 4820624ce7 feat(resolver): Respect MSRV 2023-08-25 10:42:26 -05:00
Ed Page 10196aaee3 test(resolver): Demonstrate existing behavior 2023-08-25 09:59:16 -05:00
bors 2cc50bc0b6 Auto merge of #12515 - arlosi:high-pri-last, r=weihanglo
config: merge lists in precedence order

When merging configuration lists, the current order does not match the expected precedence. This makes merged lists follow precedence order, with higher precedence items merged later in lists.

When a list in configuration exists in multiple places, Cargo merges the lists together. The ordering of this merging is unexpected and does not follow the precedence rules that non-list configuration uses.

The current merging order appears to be:
* project-specific `config.toml`
* global `config.toml`
* command-line (`--config`)
* environment variable (`CARGO_*`)

This PR changes the order to follow the precedence rules with higher precedence configuration merging later in the lists.
* global `config.toml`
* project-specific `config.toml`
* environment variable (`CARGO_*`)
* command-line (`--config`)

This aligns with config such as `build.rustflags` where later flags take precedence over earlier ones.

Since `--config` is relatively new, it's unlikely to cause too much breakage by making it come after environment variables.

Switching global and project-specific ordering is more likely to cause breakage, since it's been around longer (reported as an issue in #8128). Projects relying on global configuration flags (in `$CARGO_HOME\config.toml` or in `.cargo/config.toml` further from the project) being merged first in lists will be broken.

For most uses of merged lists (such as `build.rustflags`), if the flags do not conflict with each other, there will be no impact.

Fixes #12506
Fixes #8128
2023-08-22 22:43:08 +00:00
Weihang Lo 77da514529
test: move --keep-going suggestion match tests to UI tests
We don't want to overly match to suggestion help from clap.
2023-08-22 19:21:09 +01:00
Weihang Lo 4d0958587b
refactor(arg): use UnknownArgumentValueParser to suggest arg for unknown args 2023-08-22 17:24:40 +01:00
Arlo Siemsen 6d7531a163 Add error message for when no credential providers are available 2023-08-18 16:15:30 -05:00
bors 37a0514c75 Auto merge of #12499 - arlosi:cred-args, r=Eh2406
login: allow passing additional args to provider

As part of moving asymmetric token support to a credential provider in #12334, support for passing `--key-subject` to `cargo login` was removed.

This change allows passing additional arguments to credential providers when running `cargo login`. For example:
`cargo login -- --key-subject foo`.

The asymmetric token provider (`cargo:paseto`) is updated to take advantage of this and re-enables setting `--key-subject` from `cargo login`.

r? `@Eh2406`

cc #8933
2023-08-17 19:10:24 +00:00
bors 7b61184ad1 Auto merge of #12498 - Kobzol:run-verbose-print-env, r=arlosi
Print environment variables for `cargo run` in extra verbose mode
2023-08-17 05:32:16 +00:00
Arlo Siemsen 687ace1ddc Merge higher precedence config lists later
When merging configuration lists, the current order does not match
the expected precedence. This makes merged lists follow precedence
order, with higher precedence items merged later in lists.
2023-08-16 11:21:38 -05:00
Jakub Beránek 4eac5a1fd1
Add test for environment variables in verbose mode for cargo bench 2023-08-16 13:47:39 +02:00
Jakub Beránek 9267277048
Print environment variables for cargo test in extra verbose mode 2023-08-16 13:41:54 +02:00
Arlo Siemsen 1065f213e3 credential: rename cargo:basic to cargo:token-from-stdout 2023-08-15 23:56:11 -05:00
bors a11f624c97 Auto merge of #11447 - arlosi:exact, r=weihanglo
Crate checksum lookup query should match on semver build metadata

Since crates.io allows crate versions to differ only by build metadata, a query using `OptVersionReq::exact` + `next()` can return nondeterministic results.

This change fixes the issue by adding an additional `filter` that ensures the version is equal (including build metadata).

It still feels somewhat wrong that a query using `exact` can match multiple crates, so an alternative fix would be to add a new variant of `OptVersionReq` that also matched on build metadata.

Fixes #11412
2023-08-15 20:44:15 +00:00
Jakub Beránek 5405cd3a8b
Print environment variables for cargo run in extra verbose mode 2023-08-15 13:45:42 +02:00
Arlo Siemsen 589a111893 login: allow passing additional args to provider 2023-08-14 15:24:09 -05:00
bors 7c3904d6c3 Auto merge of #12501 - epage:rustdoc, r=weihanglo
fix(lints): Doctest extraction should respect `[lints]`

Note the first commit shows the bug and the second commit fixes it

Fixes #12497
2023-08-14 20:11:43 +00:00
Ed Page 9984855904 fix(lints): Doctest extraction should respect [lints]
Fixes #12497
2023-08-14 14:23:59 -05:00
Ed Page a80dfae761 test(lints): Demo doctest bug 2023-08-14 14:21:25 -05:00
Weihang Lo 689defd4ba
test: relax assertions of panic message (again) 2023-08-14 19:32:39 +01:00
Weihang Lo b567a67d5c
test: bypass rustc --test impl details for -Zfuture-incompat-test
Switch to an empty `lib.rs` from `main.rs`.

See https://github.com/rust-lang/rust/issues/114804#issuecomment-1677233355
2023-08-14 13:40:47 +01:00
Arlo Siemsen fb98f3fcba Add test differ_only_by_metadata 2023-08-11 18:42:40 -05:00
Weihang Lo 5ae529b24e
feat: remove --keep-going from cargo test/bench
It confuses people that both `--no-fail-fast` and `--keep-going` exist
on `cargo test` and `cargo bench` but with slightly different behavior.
The intended use cases for `--keep-going` involve build commands like
`build`/`check`/`clippy` but never `test`/`bench`.

Hence, this commit removes `--keep-going` from `test`/`bench` and
provides guidance of `--no-fail-fast` instead.

If people really want to build as many tests as possible, they can also
do it in two steps:

    cargo build --tests --keep-going
    cargo test --test --no-fail-fast
2023-08-11 14:29:02 +01:00
bors 7da103076e Auto merge of #12463 - stupendoussuperpowers:nocapture_test_msg, r=epage
prompt the use of `--nocapture` flag if `cargo test` process is terminated via a signal.

Fixes #10855

As per the discussion on this issue, we want to prompt the user to use `--nocapture` if a test is terminated abnormally. The motivation for this change is described in the issue.

We check for 3 things before we display this flag. -
- `!is_simple` (if the test ended with a non 101 status code)
- `harness` (if the standard test harness was used), and
- `!nocapture` (whether or not the `--nocapture` flag was already passed to the test)

There's further tests added to `test::nonzero_exit_status` that check that the `stderr` is correct for the various combinations possible when a test ends with a non-101 status code.

The new expected behavior is -
- Display `--nocapture` note for only non-zero exit statuses, when the `--nocapture` flag is not passed.
- Only display the note if we use a standard test harness since custom test harnesses do not implement the `--nocapture` flag.

To implement the check for the `--nocapture` flag, the function definition for `report_test_errors` was changed to add the `test_args: &[&str]` parameter. This parameter is passed from the immediate calling function. This private function is only called twice change and is not causing regression after making the appropriate changes to both the places it's called in.
2023-08-10 21:20:25 +00:00
bors af431e1bb7 Auto merge of #12454 - alcolmenar:alcolmenar/fix-invalid-rm, r=epage
Fix cargo remove incorrectly removing used patches

### What does this PR try to resolve?

Fixes an issue where patches are being removed when member dependencies don't explicitly contain the patched crate.

Fixes #12419

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

- Created a test for the failing use case
- Verify passing test

<!--
### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.

-->
2023-08-10 18:00:32 +00:00
alcolmenar 72e66fb645
fix: add quiet verbosity around resolve and fix tests 2023-08-10 09:51:36 -07:00
alcolmenar a64ed3976f
fix: add gc unused patches logic and fix tests 2023-08-10 07:27:36 -07:00
alcolmenar 7ad774a3ff
chore: add passing test 2023-08-10 07:27:24 -07:00
alcolmenar dde256fb93
fix: ensure patches are different dependencies to enable unused 2023-08-09 13:09:41 -07:00
sanchit dd8cd9c9a9 add nocapture message to report_test_err 2023-08-10 01:16:27 +05:30
sanchit dde17cf0cf add --nocapture tests 2023-08-10 01:16:00 +05:30
bors 2b3554f773 Auto merge of #11905 - epage:help_heading, r=weihanglo
fix(cli): Make `--help` easier to browse

This mirrors some of the categories from `cargo help` (the man pages) using [`clap::Arg::help_heading`](https://docs.rs/clap/latest/clap/struct.Arg.html#method.help_heading).
There are fewer categories to avoid extra vertical space.  Instead, they
are left int the `Options` category but put first.

The goal is to try to make it easier to scan `--help` output as the list of flags can get quite long and its easy to miss what features are there.
2023-08-08 20:35:52 +00:00
Ed Page 853102f7de fix(cli): Make --help easier to browse
This mirrors some of the categories from `cargo help` (the man pages).
There are fewer categories to avoid extra vertical space.  Instead, they
are left int the `Options` category but put first.
2023-08-08 13:50:05 -05:00
bors d432dec355 Auto merge of #12332 - hi-rustin:rustin-patch-syntax, r=arlosi
Bail out an error when using cargo:: in custom build script
2023-08-07 16:58:15 +00:00
bors abc115972e Auto merge of #12439 - arlosi:registry-multiple-warning, r=ehuss
Fix printing multiple warning messages for unused fields in [registries] table

Cargo currently prints the same warning message multiple times for unexpected fields in the `[registries.<registry>]` or `[registry]` tables. This is because Cargo warns each time that the structure is deserialized from `Config`. Depending on which code path is taken I've seen the warning printed up to 6 times.

* A cache of deserialized registry configurations is added to the `Config` struct.
* Registry authentication is changed to directly read the config when searching for a registry name, rather than deserializing each registry configuration.

A test is added to ensure both `[registries]` and `[registry]` only warn once for unexpected fields.
2023-08-06 18:29:22 +00:00
Eric Huss 1df0f1d734 Add allow(internal_features) 2023-08-05 12:11:07 -07:00
Weihang Lo c60c06585c
fix: clear cache for old .cargo-ok format
In 1.71, `.cargo-ok` changed to contain a JSON `{ v: 1 }` to indicate
the version of it. A failure of parsing will result in a heavy-hammer
approach that unpacks the `.crate` file again. This is in response to a
security issue that the unpacking didn't respect umask on Unix systems.
2023-08-03 13:42:54 +01:00
Weihang Lo 4fafa69a4d
fix: respect umask when unpacking .crate files
Without this, an attacker can leverage globally writable files buried
in the `.crate` file. After a user downloaded and unpacked the file,
the attacker can then write malicous code to the downloaded sources.
2023-08-03 13:41:08 +01:00
Weihang Lo 789a2fb4bf
test: verify permissions bits are preserved when unpacking
This is not secure and will be fixed in the next commit.
2023-08-03 13:39:48 +01:00
Arlo Siemsen 65ec65fe1e Fix printing multiple warning messages for unused fields in [registries] table 2023-08-02 18:20:46 -05:00
bors 6dc1deaddf Auto merge of #12429 - Nilstrieb:we-love-internal-features, r=weihanglo
`#[allow(internal_features)]` in RUSTC_BOOTSTRAP test

This will be required in the future (where "the future" is rust-lang/rust#108955 which fails CI because of cargo here).

This does emit the unknown lints lint right now but that doesn't matter as it's just warn-by-default - internal_features is deny-by-default though, so it causes errors.
2023-08-02 00:23:54 +00:00
Nilstrieb b2720536b0 #[allow(internal_features)] in RUSTC_BOOTSTRAP test
This will be required in the future (where "the future" is my PR
which fails CI because of cargo here).
2023-08-01 18:18:29 +02:00
bors baebd2bfb6 Auto merge of #12428 - epage:update, r=weihanglo
fix(update): Tweak CLI behavior

### What does this PR try to resolve?

When looking at `cargo update` for #12425, I noticed that the two flags related to `--package` were not next to it or each other.  I figured grouping them like that would make things easier to browse.

When looking into that, I noticed that the two flags conflict and figured we'd provide a better error message if we did that through clap.

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

Looking per commit will help show the behavior changes.

### Additional information

I wanted to scope this to being simple, non-controversial, low effort, incremental improvements with this change so I did not look into the history of `--aggressive` not requiring  `--package` like `--precise` does and figure out if there is any consistency we can be working towards.
2023-08-01 15:20:25 +00:00
Ed Page 4fd0c3c46c fix(update): Group -p related flags 2023-07-31 21:21:02 -05:00
Ed Page 57762917fb fix(update): Perform error check in clap 2023-07-31 21:18:31 -05:00
Ed Page e290ed7a02 test(update): Add a --aggressive --precise error test 2023-07-31 21:16:54 -05:00
bors 29a6f2fab2 Auto merge of #12424 - arlosi:credential-thiserror, r=arlosi
Use thiserror for credential provider errors

### What does this PR try to resolve?
Errors from credential providers currently must a single string. This leads to a lot of `.map_err(|e|cargo_credential::Error::Other(e.to_string())`, which loses the `source()` of these errors.

This changes the `cargo_credential::Error` to use `thiserror` and adds a custom serialization for `std::error::Error` that preserves the source error chain across serialization / deserialization.

A unit test is added to verify serialization / deserialization.
2023-07-31 22:00:41 +00:00
Predrag Gruevski 2f59b20df6 Mention that cargo test --all-targets excludes doctests
Per my proposal here: https://github.com/rust-lang/cargo/issues/6669#issuecomment-1658593167

I tried to keep the edit minimalistic to match the surrounding style.

If the maintainers are amenable to it, I think it could also be useful to do one or more of:
- Offer concrete guidance on what to do to run actually-all tests (`--all-targets` then separately `--doc`).
- Link to the issue at: https://github.com/rust-lang/cargo/issues/6669
- Mention that `cargo test` without `--all-targets` runs doctests by default, which seems not immediately obvious.

I'd be happy to attempt to add any of the above that the maintainers feel would be a good fit here.
2023-07-31 20:09:24 +00:00
Arlo Siemsen a81d558941 Use thiserror for credential provider errors 2023-07-31 13:45:08 -05:00
bors 9fe58acfb7 Auto merge of #12411 - weihanglo:issue/12404, r=ehuss
fix: normalize relative git submodule urls with `ssh://`
2023-07-30 17:05:18 +00:00
Weihang Lo 8a4d04414e fix: normalize relative git submodule urls with ssh://
Git only assumes a submodule URL is a relative path if it starts with `./`
or `../` [^1]. To fetch the correct repo, we need to construct an aboslute
submodule URL.

At this moment it comes with some limitations:

* GitHub doesn't accept non-normalized URLs wth relative paths.
  (`ssh://git@github.com/rust-lang/cargo.git/relative/..` is invalid)
* `url` crate cannot parse SCP-like URLs.
  (`git@github.com:rust-lang/cargo.git` is not a valid WHATWG URL)

To overcome these, this patch always tries `Url::parse` first to normalize
the path. If it couldn't, append the relative path as the last resort and
pray the remote git service supports non-normalized URLs.

See also rust-lang/cargo#12404 and rust-lang/cargo#12295.

[^1]: <https://git-scm.com/docs/git-submodule>
2023-07-30 10:04:32 -07:00
Weihang Lo b59527901d
test: relax help text assertion
When running test in rust-lang/rust via `./x test src/tool/cargo`,
there is no rustup integrated.
2023-07-30 07:42:04 +01:00
bors 1680ab508e Auto merge of #12413 - weihanglo:tweak-panic-msg, r=ehuss
test: relax assertions of panic handler message format
2023-07-29 22:50:14 +00:00
Weihang Lo b9e70ec0a2
test: relax assertions of panic handler message format 2023-07-29 17:12:46 +01:00
hi-rustin 4bdeb53cb5 Bail out an error when using cargo:: in custom build script
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-07-27 23:00:52 +08:00
Ed Page cc6b6c9584 fix(package): Avoid multiple package list entries
To keep things simple, especially in getting a `Hash` implementation
correct, I'm leveraging `unicase` for case-insensitive
comparisons which is an existing dependency and I've been using for
years on other projects.

This also opens the door for us to add cross-platform compatibility
hazard warnings about multiple paths that would write to the same
location on a case insensitive file system.  I held off on that because
I assume we would want #12235 first.

This does mean we can't test the "no manifest" case anymore because the
one case (no pun intended) I knew of for hitting it is now gone.
2023-07-26 11:02:47 -05:00
Ed Page 9b14e39cd7 test(package): Verify mixed-case Cargo.toml 2023-07-26 10:10:21 -05:00
Ed Page 5101372312 test(cli): Track --help output
This makes it easier to evaluate the usability of PRs, like #11905
2023-07-24 17:12:20 -05:00
Ed Page 3166e5f614 fix(package): Warn when manifest is not more generally found
Being a bit cautious about not turning this into an error since this is
most likely because of case insensitive filesystems.
2023-07-24 16:49:38 -05:00
Ed Page f4c97b24a8 test(package): Verify the no-manifest case 2023-07-24 16:41:15 -05:00
Ed Page bbb6aff67a fix(package): Normalize cargo.toml to Cargo.toml for windows 2023-07-24 16:29:14 -05:00
Ed Page 5dd39df6f1 test(package): Verify cargo.toml behavior 2023-07-24 16:13:21 -05:00
bors 55281fd3ee Auto merge of #12398 - epage:cargo-config, r=weihanglo
refactor(test): Move cargo-config into a dir

This is split out of #11912 and is prep for adding more UI tests.

Generally our UI tests are in a directory named after the full cargo command (`cargo config`).  These tend to use `snapbox`.

Here we are tests for the `cargo config` command not written by `snapbox` in a `cargo_config.rs` file.  This conflicts with adding snapbox UI tests later in a `cargo_config/` folder.  Upon looking at this file, it appears to be UI tests, so I think it would make sense to move them into the `cargo_config/` folder.  Definitely wouldn't make sense to move them into `config.rs` since that is general config testing.
2023-07-24 20:14:19 +00:00
Ed Page f06911cb90 refactor(test): Move cargo-config into a dir
This is split out of #11912 and is prep for adding more UI tests.

Generally our UI tests are in a directory named after the full cargo
command (`cargo config`).  These tend to use `snapbox`.

Here we are tests for the `cargo config` command not written by
`snapbox` in a `cargo_config.rs` file.  This conflicts with adding
snapbox UI tests later in a `cargo_config/` folder.  Upon looking at this
file, it appears to be UI tests, so I think it would make sense to move
them into the `cargo_config/` folder.  Definitely wouldn't make sense to
move them into `config.rs` since that is general config testing.
2023-07-24 14:47:29 -05:00
Ed Page 79469f3019 refactor(tests): Name init ui tests more consistently
Currently, the UI tests are
- `cargo add`
- `cargo new`
- `cargo remove`
- `init`

One of these is not like the others. This change renames `init` to
`cargo_init` to suggest it is the UI tests for the `cargo init` command,
rather than `init` functionality.
2023-07-24 13:39:37 -05:00
bors 7c82ff2e06 Auto merge of #12280 - weihanglo:git-ref-ambiguity, r=ehuss
fix: encode URL params correctly for SourceId in Cargo.lock

We use [`form_urlencoded::byte_serialize`](https://docs.rs/form_urlencoded/1.2.0/form_urlencoded/fn.byte_serialize.html), which is re-exported by `url` crate. Tests are copied from <https://github.com/rust-lang/cargo/pull/11086>. Kudos to the original author!
2023-07-23 19:01:50 +00:00
Arlo Siemsen 6151a4152b Send all headers to cred provider 2023-07-21 17:30:01 -05:00
Arlo Siemsen 2b39792aef Credential provider implementation 2023-07-21 16:02:24 -05:00
bors b40be8bdcf Auto merge of #12310 - weihanglo:asymmetric-challenge, r=Eh2406
feat(crates-io): expose HTTP headers and Error type

### What does this PR try to resolve?

This is part of #11521.

[RFC 3231] mentions the authentication process could have an additional **challenge-response mechanism** to prevent potential replay attacks. The challenge usually comes from HTTP `www-authenticate` header as a opaque string. When a client gets a 401/403 response with such a challenge, it may attach the `challenge` to the payload and request again to anwser the challenge.

```
➡️ cargo  requests
⬅️ server responds with `www-authenticate` containing some opaque challenge string
➡️ cargo  automatically requests again without any user perception
⬅️ server responds ok
```

However, `crates-io` crate doesn't expose HTTP headers. There is no access to `www-authenticate` header.

This PR make it expose HTTP headers and the custom `Error` type, so `cargo` can access and do further on the authentication process.

[RFC 3231]: https://rust-lang.github.io/rfcs/3231-cargo-asymmetric-tokens.html#the-authentication-process
2023-07-20 22:19:10 +00:00
Charles Samborski 54ad4a01df fix(new): Don't ignore Cargo.lock for all package types
Following the default guidance to commit a lockfile, this updates
`cargo new` to do it by default.
2023-07-19 11:56:40 -05:00
bors fc6cf8c7f8 Auto merge of #12369 - jo1gi:readonly-cargo-home-subdirs, r=weihanglo
fix: only skip mtime check on `~/.cargo/{git,registry}`

Fixes #12090

Make cargo only skip mtime checks on `$CARGO_HOME/{git, registry}`.
2023-07-19 11:16:15 +00:00
Joakim Holm 839069f03f only skip mtime check on $CARGO_HOME/{git,registry}
Closes #12090

Commit

Fix formatting

Fix tests

Fix formatting

Fix formatting

Fix formatting
2023-07-19 12:38:56 +02:00
Weihang Lo 31b500c7c0
refactor(crates-io): use thiserror
Optionally use `thiserror` to reduce boilerplates but this part can
be dropped if we don't want.
2023-07-18 22:22:47 +01:00
bors 5a9f611178 Auto merge of #12359 - weihanglo:issue/12295, r=ehuss
fix(git): respect scp-like URL for nested submodules
2023-07-18 00:50:01 +00:00
Bart Massey b9bee5297e corrected unspecifiead to unspecified 2023-07-15 16:52:55 -07:00
Weihang Lo a7247babf6
fix(git): respect scp-like URL for nested submodules
`parent_remote_url` used to be `&str` before #12244. However, we changed
the type to `Url` and it started failing to parse scp-like URLs since
they are not compliant with WHATWG URL spec.

In this commit, we change it back to `&str` and construct the URL
manually. This should be safe since Cargo already checks if it is a
relative URL for that if branch.
2023-07-15 09:01:08 +01:00
bors 694a579566 Auto merge of #12349 - epage:sanitize, r=weihanglo
fix(embedded): Always generate valid package names

### What does this PR try to resolve?

The sanitization logic uses a placeholder for the first character that isn't valid in the first character position.  #12329 took the approach of always using `_` which has the problem of mixing separators if the user used `-` or we had other placeholders to insert.  Instead, this takes the approach of stripping the leading invalid characters and using a placeholder name if nothing is left.

Fixes #12330

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

Per-commit.  The first adds tests so the change in behavior can be observed over each additional commit.

### Additional information

I was also hoping to make the binary name not use placeholders by setting `bin.name` to `file_stem` but then I got
```
   Compiling s-h-w-c- v0.0.0 (/home/epage/src/personal/cargo/target/tmp/cit/t133/foo)
error: invalid character `'.'` in crate name: `s_h.w§c!`

error: invalid character `'§'` in crate name: `s_h.w§c!`

error: invalid character `'!'` in crate name: `s_h.w§c!`

error: could not compile `s-h-w-c-` (bin "s-h.w§c!") due to 3 previous errors
```
I decided to not get into what are or aren't valid characters according to rustc.
2023-07-11 22:28:29 +00:00
Ed Page 10fbb470bb fix(embedded): Error on unsupported commands
- `cargo pkgid` is unsupported because we can't (yet) generate valid
  pkgids for embedded manifests.  Adding support for this would be a
  step towards workspace support
- `cargo package` and `cargo publish` are being deferred.  These would
  be more important for `[lib]` support.  `cargo install` for `[[bin]]`s
  is a small case and As single-file packages are fairly restrictive, a
  `[[bin]]` is a lower priority.
2023-07-11 15:34:17 -05:00
Ed Page aaaa37f409 test(embedded): Add tests for unsupported commands 2023-07-11 15:26:28 -05:00
Ed Page 7d4e39c4f5 fix(embedded): Don't generate empty package names 2023-07-11 14:37:44 -05:00
Ed Page 87be661989 fix(embedded): Don't generate package names with invalid leading digit 2023-07-11 14:35:50 -05:00
Ed Page 09d6c79278 test(script): Verify existing leading number behavior 2023-07-11 14:27:36 -05:00
Ed Page 0e648c3ee4 fix(script): Be quiet on programmatic output
The goal is that we shouldn't interefere with end-user output when
"cargo script"s are used programmatically.  The only way to detect this
is when piping.  CI will also look like this.

My thought is that if someone does want to do `#!/usr/bin/env -S cargo -v`, it
should have a consistent meaning between local development
(`cargo run --manifest-path`) and "script mode" (`cargo`), so I
effectively added a new verbosity level in these cases.  To get normal
output in all cases, add a `-v` like the tests do.  Do `-vv` if you want
the normal `-v` mode.  If you want it always quiet, do `--quiet`.

I want to see the default verbosity for interactive "script mode" a bit
quieter to the point that all normal output cargo makes is cleared before
running the built binary.  I am holding off on that now as that could
tie into bigger conversations / refactors
(see https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/Re-thinking.20cargo's.20output).
2023-06-22 19:27:00 -05:00
Ed Page 279077987b test(script): Verify verbosity 2023-06-22 19:27:00 -05:00
bors 2035d0d1b9 Auto merge of #12303 - epage:config, r=joshtriplett
fix(script): Process config relative to script, not CWD

### What does this PR try to resolve?

This is part of the work for #12207.

When you put in your path `foo.rs`:
```rust
#!/usr/bin/env cargo

fn main() {}
```

You expect it to build once and then repeatedly run the same version.  However, `.cargo/config.toml` doesn't work like that (normally).  It is an environment file, like `.env`, and is based on your current working directory.  So if you run `foo.rs` from within a random project, it might rebuild due to RUSTFLAGS in `.cargo/config.toml`.

I had some concern about whether this current behavior is right or not and [noted this in the Pre-RFC](https://github.com/epage/cargo-script-mvs/blob/main/0000-cargo-script.md#unresolved-questions).  This came up again while we were [discussing editions on zulip](https://rust-lang.zulipchat.com/#narrow/stream/246057-t-cargo/topic/cargo.20script.20and.20edition).  In looking further into this, it turns out we already have precedence for this with `cargo install --path <path>`.

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

The second commit has the fix, the docs, and a change to a test (from the first commit) to show that the fix actually changed behavior.
2023-06-22 21:47:34 +00:00
Ed Page 78334e868e fix(script): Process config relative to script, not CWD 2023-06-22 14:15:20 -05:00
Ed Page 9d85c891e8 test(script): Verify existing config behavior 2023-06-22 14:05:44 -05:00
Eric Huss 604c8f8122 -Znext-lockfile-bump: Don't suggest using -Z on stable 2023-06-22 11:55:42 -07:00
bors 05cd14ecf9 Auto merge of #12298 - weihanglo:config-include-toml, r=epage
Add `.toml` file extension restriction for `-Zconfig-include`
2023-06-21 21:48:29 +00:00
Weihang Lo 33b0a24082
test(config-include): assert config merged in DFS 2023-06-21 20:18:09 +01:00
Weihang Lo 3f82ec7093
feat: check if config-include file ends with .toml
This is to avoid possible name collisions. For example, a user
creates a file called `.cargo/cache`, and then in the future
cargo wants to create a directory called `.cargo/cache/`, that
would collide with what the user specified. Restricting to `.toml`
extensions would avoid that since we won’t make a directory named
with a `.toml` extension.
2023-06-21 20:18:08 +01:00
bors 4cebd130eb Auto merge of #12289 - epage:basic, r=weihanglo
fix: Allow embedded manifests in all commands

### What does this PR try to resolve?

This is a part of #12207.

One of the goals is for embedded manifests to be a first class citizen.  If you have a script, you should be able to run tests on it, for example.

This expands the error check from just `Cargo.toml` to also single-file packages so you can use it in `--manifest-path`.

This, however, does mean that these *can* be used in places that likely won't work yet, like `cargo publish`.

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

By commit.  We introduce tests for basic commands and then implement and refine the support for this.

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
2023-06-21 18:59:29 +00:00
bors 3de1cc462b Auto merge of #12281 - epage:toml, r=weihanglo
feat(cli): Support `cargo Cargo.toml`

### What does this PR try to resolve?

This is making the assumption that we want full unity between places accepting both single-file packages and `Cargo.toml` for #12207.   This has not been brought up before in any of the discussions (Internals, eRFC), so I can understand if there are concerns about this and we decide to hold off.

We might want to resolve symlinks before this so people can have a prettier name for these.

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

The test for this was added in a commit before the actual change, letting people see how the behavior changed.
2023-06-21 18:07:32 +00:00
Ed Page d8583f4a5e fix(cli): Improve error on manifest dir 2023-06-21 12:26:15 -05:00
Ed Page 85023c46e4 test(cli): Verify missing-manifest behavior 2023-06-21 11:46:36 -05:00
Ed Page af69746ba6 test(cli): Verify directory-manifest behaivor 2023-06-21 11:30:55 -05:00
Eric Huss 9835622853 Convert valid feature name warning to an error. 2023-06-20 12:39:27 -07:00
Ed Page b1394895ad fix(cli): Ensure we don't accidentally let embedded manifests on stable
There should be a later check when parsing but just in case, let's have
a check here as well.
2023-06-19 21:26:49 -05:00
Ed Page 4e49af4071 fix: Allow embedded manifests in all commands
I originally centralized the error reporting until I realized it likely
is intentionally not centralized so we report errors in terms of the
arguments the user provided.
2023-06-19 20:33:30 -05:00
Ed Page 98ed8abe6d test(embedded): Verify existing behavior on basic commands 2023-06-19 16:12:20 -05:00
Ed Page bb1f6f29bc fix(embedded): Don't pollute script dir with lockfile
This puts the lockfile back into a target directory in the users home,
like before #12268.

Another idea that came up was to move the workspace root to be in the
target directory (which would effectively be like pre-#12268) but I
think that is a bit hacky / misleading.

This does mean that the lockfile is buried away from the user and they
can't pass it along with their script.  In most cases I've dealt with,
this would be fine.  When the lockfile is needed, they will also most
likely have a workspace, so it shoud have a local lockfile in that case.
The inbetween case is something that needs further evaluation for
whether we should handle it and how.
2023-06-17 15:27:03 -05:00
Ed Page 53a63b2775 test(embedded): Verify existing lockfile behavior 2023-06-17 15:11:46 -05:00