Commit graph

3411 commits

Author SHA1 Message Date
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
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
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
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
bors 2cf2c32c1a Auto merge of #12221 - Swatinem:enable-doctest-in-workspace, r=weihanglo
Enable `doctest-in-workspace` by default

This stabilizes and enables the `-Z doctest-in-workspace` flag by default.

Also adds another testcase to make sure that the `include!()` and `file!()` macros interact well together.

fixes #9427
fixes https://github.com/rust-lang/rust/issues/46372
2023-06-17 20:37:43 +00:00
Arpad Borsos 18e290c0e4
Enable doctest-in-workspace by default
This stabilizes and enables the `-Z doctest-in-workspace` flag by default.

Also adds another testcase to make sure that the `include!()` and `file!()` macros interact well together.
2023-06-17 19:34:34 +02:00
bors e518f7c45e Auto merge of #12283 - epage:build, r=weihanglo
fix(embedded): Don't auto-discover build.rs files

With #12268, we moved the manifest root to be the scripts parent
directory, making it so auto-discovery might pick some things up.

We previously ensured `auto*` don't pick things up but missed `build.rs`
This is now addressed.
2023-06-17 17:06:00 +00:00
bors 81a73926b3 Auto merge of #12282 - epage:target, r=weihanglo
fix(embeded): Don't pollute the scripts dir with `target/`

### What does this PR try to resolve?

This PR is part of #12207.

This specific behavior was broken in #12268 when we stopped using an intermediate
`Cargo.toml` file.

Unlike pre-#12268,
- We are hashing the path, rather than the content, with the assumption
  that people change content more frequently than the path
- We are using a simpler hash than `blake3` in the hopes that we can get
  away with it

Unlike the Pre-RFC demo
- We are not forcing a single target dir for all scripts in the hopes
  that we get #5931

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

A new test was added specifically to show the target dir behavior, rather than overloading an existing test or making all tests sensitive to changes in this behavior.

### Additional information

In the future, we might want to resolve symlinks before we get to this point
2023-06-17 16:15:20 +00:00
Ed Page 3f93030614 fix(embedded): Don't auto-discover build.rs files
With #12268, we moved the manifest root to be the scripts parent
directory, making it so auto-discovery might pick some things up.

We previously ensured `auto*` don't pick things up but missed `build.rs`
This is now addressed.
2023-06-17 11:01:02 -05:00
Ed Page 4427cfe619 test(script): Verify existing build.rs behavior 2023-06-17 10:59:54 -05:00
Weihang Lo 65b292f7dc
test: encode URL params correctly for SourceId in Cargo.lock
This will happen in lockfile format v4.
2023-06-17 15:57:42 +01:00
Weihang Lo 5974123fda
test: v3 lockfile format doesn't respect url encode
These tests verify the existing buggy behavior.
2023-06-17 15:57:41 +01:00