Commit graph

47 commits

Author SHA1 Message Date
Ed Page
675224b3a0 test(config): Shift to config.toml 2024-01-26 13:40:46 -06:00
Ed Page
51b1200572 fix(cli): Improve bad script errors 2024-01-25 13:28:43 -06:00
Ed Page
2a7e5c05ed test(script): Show existing non-existent behavior 2024-01-25 13:28:43 -06:00
Ed Page
c377c2aae6 test(script): Avoid common subcommand name 2024-01-25 13:28:30 -06:00
Ed Page
c51ea384b0 fix(cli): Suggest fix for scripts that look like external subcommands 2024-01-25 11:28:48 -06:00
Ed Page
594c96ad51 refactor(metadata): Switch opaque ID from PackageID to PackageIDSpec 2023-12-06 08:58:56 -06:00
Ed Page
ec3ed20d2a fix(cli): Suggest cargo-search on bad commands
This is a low-tech solution alternative to the options proposed in #4682
- Search `[[bin]]`s within all packages in the registry (which aren't
  tracked atm), suggesting to `cargo install` what is found
- Check if `cargo-<cmd>` is in the registry, suggesting `cargo install
  if it is

By suggesting `cargo search`, we are giving them a tool so they can
verify if the package is what they want (a `cargo info` would help as a
next step).

Is is needed?
- New users might not know of `cargo search` but they can search on
  crates.io
- New users might not be aware of the `cargo-<cmd>` naming pattern

Seems like this can still offer some benefit

Fixes #4682
2023-10-17 14:46:30 -05:00
bors
25dc3bdc5d Auto merge of #12681 - epage:frontmatter, r=Muscraft
feat(embedded): Hack in code fence support

### What does this PR try to resolve?

This is to allow us to get feedback on the design proposed
[on zulip](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Embedding.20cargo.20manifests.20in.20rust.20source/near/391427092)
to verify we want to make an RFC for this syntax.

````rust
#!/usr/bin/env cargo
```cargo
[dependencies]
clap = { version = "4.2", features = ["derive"] }
```

use clap::Parser;

#[derive(Parser, Debug)]
#[clap(version)]
struct Args {
    #[clap(short, long, help = "Path to config")]
    config: Option<std::path::PathBuf>,
}

fn main() {
    let args = Args::parse();
    println!("{:?}", args);
}
````

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

The tests were updated in a separate commit to ensure there was no regression while then migrating to the new syntax to make sure it worked.

This involves some future work
- Removing doc comment support
- Getting the syntax approved and implemented
- Migrating to rustc support for the syntax

#12207 was updated to record these items so we don't lose track of them
2023-09-26 15:35:38 +00:00
Eric Huss
ebee726d8f Separately track files and directories removed.
The previous status line was a little awkward in the way it combined
both counts. I don't think showing the directories is particularly
interesting, so they are only displayed when no files are deleted.
2023-09-19 18:24:37 -07:00
Eric Huss
495ed7ebe2 Add a summary to cargo clean.
This adds a summary at the end when `cargo clean` finishes that displays
how many files and bytes were removed.
2023-09-19 18:16:40 -07:00
Ed Page
e4e10f2393 chore: Fix typos
This is a repeat of #11561
2023-09-19 15:28:48 -05:00
Ed Page
a365a69130 test(embedded): Migrate to new syntax 2023-09-18 14:47:56 -05:00
Bart Massey
b9bee5297e corrected unspecifiead to unspecified 2023-07-15 16:52:55 -07: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
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
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
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
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
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
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
Ed Page
aca7b08405 fix(embedded): Keep target dir in cargo home
This 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
2023-06-16 21:37:55 -05:00
Ed Page
7f2eca409f feat(cli): Accept 'cargo Cargo.toml'
This wasn't in the original Pre-RFC but in terms of consistently
accepting manifests everything, I think this makes sense.
2023-06-16 21:12:22 -05:00
Ed Page
ffb997fd2d test(cli): Verify you can't use Cargo.toml 2023-06-16 21:12:22 -05:00
Ed Page
5ed07925cc fix(embedded): Ensure we don't auto-discover any targets 2023-06-16 21:08:48 -05:00
Ed Page
575b9ac934 fix(embedded): Don't create an intermediate manifest
To parse the manifest, we have to write it out so our regular manifest
loading code could handle it.  This updates the manifest parsing code to
handle it.

This doesn't mean this will work everywhere in all cases though.  For
example, ephemeral workspaces parses a manifest from the SourceId and
these won't have valid SourceIds.

As a consequence, `Cargo.lock` and `CARGO_TARGET_DIR` are changing from being next to
the temp manifest to being next to the script.  This still isn't the
desired behavior but stepping stones.

This also exposes the fact that we didn't disable `autobins` like the
documentation says we should.
2023-06-16 21:08:47 -05:00
Ed Page
2c70983e8d test(embedded): Verify no autobin behavior is running 2023-06-16 21:06:01 -05:00
Ed Page
b116864d79 fix(embedded): Be consistent with existing style when sanitizing 2023-06-15 19:09:28 -05:00
Ed Page
56b2812a85 fix(embedded): Don't append hash to bin names
Background: the hash existed for sharing a target directory.  That code isn't
implemented yet and a per-user build cache might remove the need for it,
so let's remove it for now and more carefully weigh adding it back in.

Immediate: This reduces the chance of hitting file length issues on Windows.

Generally: This is a bit hacky and for an official solution, we should
probably try to find a better way.  This could become more important as
single-file packages are allowed in workspaces.
2023-06-14 12:25:59 -05:00
Ed Page
33c9d8e2fd feat(cli): Pull in cargo-script-mvs core logic
This is no where near the implementation we want but I think we should
develop incrementally on top of what we already have.

See https://github.com/epage/cargo-script-mvs/tree/main
2023-06-09 22:03:18 -05:00
Ed Page
3c15d24960 fix(cli): Warn on stable for precedence changes
This will give us a window to collect feedback on if this affects
anyone.
2023-06-09 22:02:54 -05:00
Ed Page
b2b4d9771f test(cli): Verify precedence over external subcommands 2023-06-09 13:16:12 -05:00
Ed Page
21736eda0c feat(cli): Interpret some subcommands as manifest-commands 2023-06-08 20:17:03 -05:00