Commit graph

3368 commits

Author SHA1 Message Date
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 03556056d4
feat: prepare for the next lockfile bump
The `-Znext-lockfile-bump` is added, so we can prepare for all
lockfile format changes and then stabilize then all at once.

`-Znext-lockfile-bump` is not intended for using outside our test
suite and development. Hence it's hidden.
2023-06-17 10:24:53 +01: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 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
christian 56318e0b6c remove escapes and leading whitespace from string matches 2023-06-08 17:09:21 +00:00
christian 71b37f2fd1 add test case 2023-06-08 15:27:23 +00:00
Weihang Lo 51ebba2fc1
test: loose overly matches for git cli output
The output format should be stable I believe, but it turns out not.
This is how `git fetch` man page says [1]:

```
<flag> <summary> <from> -> <to> [<reason>]
```

In Git 2.41 they've changed the fetch output a bit [2].

I think let's just loose it to prevent future breakages.

[1]: https://git-scm.com/docs/git-fetch#_output
[2]: https://github.blog/2023-06-01-highlights-from-git-2-41/
2023-06-07 22:55:17 +01:00
MarcusGrass 03675ef6a4
Add additional info on a new line 2023-06-05 11:27:31 +02:00
MarcusGrass 073a32b61f
Add message on reusing previous temporary path on failed cargo installs 2023-06-04 18:31:06 +02:00
bors b0fa79679e Auto merge of #12226 - danilhendrasr:feat/emit-error-on-toolchain-add-and-install, r=weihanglo
Emit error when users try to use a toolchain via the `add` or `install` command

Running `cargo install +nightly` or `cargo add +nightly` does not actually use the nightly toolchain, but the user won't know until the compilation fails. With this PR, an error is emitted if the `install` and `add` command is given a crate name
that starts with a `+` as we assume the user's intention was to use a certain toolchain instead of installing/adding a crate.

Example:
<img width="758" alt="image" src="https://github.com/rust-lang/cargo/assets/45989466/16e59436-32ee-49ee-9933-8b68b176c09d">

Fixes #10362
2023-06-03 14:19:48 +00:00
Danil Hendra Suryawan 58b7bce63e feat(cli): emit error when install is given a toolchain name instead of crate name 2023-06-03 20:51:14 +07:00
Danil Hendra Suryawan a9c47cc3ab feat(cli): emit error when add is given a toolchain name instead of a crate name 2023-06-03 20:50:24 +07:00
Charalampos Mitrodimas a777b82d5f Support "default" option for build.jobs
This commit adds support for passing the keyword "default"
to either the CLI "--jobs" argument on the "[build.jobs]"
section of ".cargo/config".

This is dony by:
  1. Changing the "jobs" config type to an enum that holds
     a String or an Integer(i.e. i32).
  2. Matching the enum & casting it to an integer

Signed-off-by: Charalampos Mitrodimas <charmitro@gmail.com>
2023-06-03 15:24:41 +03:00
Weihang Lo d4067e4881
fix: should assert against stderr instead
This was an overlook in #12205
2023-05-31 20:46:11 +01:00
Weihang Lo 64a1f204f3
refactor: only when -C debuginfo > 0 will spilt-debuginfo be passed
It was unnecessary to pass `spilt-debuginfo` if there is no debuginfo.
Tests are touched here only for matching rustflags invocation stderr
in the original test suite.
2023-05-31 20:43:57 +01:00
jyn e2eacc6414 Don't distinguish Debuginfo::None and Debuginfo::Explicit(None)
Previously, `Debuginfo::None` meant "don't pass -C debuginfo" and `Explicit(None)` meant
"-C debuginfo=0", which occasionally led to caching bugs where cargo would sometimes pass
`-C debuginfo=0` and sometimes not. There are no such bugs currently that we know of, but
representing them the same within cargo avoids the possibility of the bug popping up again in the
future.

I tested the `with_stderr_does_not_contain_tests` with this diff to ensure they did not pass:
```diff
diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs
index 55ec17182..c186dd00a 100644
--- a/src/cargo/core/compiler/mod.rs
+++ b/src/cargo/core/compiler/mod.rs
@@ -1073,9 +1073,7 @@ fn build_base_args(

     let debuginfo = debuginfo.into_inner();
     // Shorten the number of arguments if possible.
-    if debuginfo != TomlDebugInfo::None {
         cmd.arg("-C").arg(format!("debuginfo={}", debuginfo));
-    }

     cmd.args(unit.pkg.manifest().lint_rustflags());
     if !rustflags.is_empty() {
```
2023-05-30 17:06:50 -05:00
Eric Huss 16ac6fae11 Re-enable code_generation test on Windows 2023-05-29 12:01:02 -07:00
bors 8f49b5556b Auto merge of #12191 - epage:mut, r=weihanglo
fix(add): Reduce the chance we re-format the user's `[features]` table

### What does this PR try to resolve?

#11743 pointed out that we re-format the users `[features]` table when running `cargo add`  which was a bug introduced in #11099.

This reduces the chance people will run into this problem
- Reducing the scope of the `fmt` call
- Preserving formatting in a simple case

Actually removing the `fmt` case can make some common formatting cases more complex to do "right", so I'm punting on that for now.

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

Look at the individual commits as I show how each change improves the behavior of `cargo add`.
2023-05-27 10:33:39 +00:00
Ed Page 0da6997ccc test(add): Remove expensive test
This is a carry-over from cargo-edit where we had to worry about the UX
of all of the behavior while now we are just relying on built-in cargo
behavior and don't need to test it specifically for `cargo add`.

On my machine, this test takes 11s.
2023-05-26 19:24:13 -05:00
bors c412aa4fac Auto merge of #12189 - epage:add, r=weihanglo
refactor(tests): Reduce cargo-add setup load

This just gets rid of irrelevant packages in the registry.  Looking into which versions aren't needed would require a deeper pass, so I held off on that for now.

Before, the tests were in the 300-500ms range and now they take 100-300ms.

This did call to my attention that `unrelated` is misspelled as `unrelateed` but holding off on fixing that to reduce conflicts.
2023-05-26 22:15:09 +00:00
Ed Page dbf9134d57 fix(add): Preserve formatting 2023-05-26 16:49:59 -05:00
Ed Page 6d8f35f729 fix(add): Reduce the chance of breaking the user's formatting 2023-05-26 16:49:59 -05:00
Ed Page b903527f28 test(add): Show features table fmt bug 2023-05-26 16:49:14 -05:00
bors d08c587469 Auto merge of #10910 - Nemo157:lint-different-resolver-10112, r=epage
Warn when an edition 2021 crate is in a virtual workspace with default resolver

Edition 2021 updates the default resolver to version "2", but developers using virtual workspaces commonly don't get this update because the virtual workspace defaults to version "1". Warn when this situation occurs so those developers can explicitly configure their workspace and will be more likely to know that they will need to update it in the future.

Fixes #10112
2023-05-26 19:57:28 +00:00
Wim Looman 3dec6f234d
Remove unnecessary warning line 2023-05-26 20:27:34 +02:00
Wim Looman 49cc60b1aa
Add notes on how to configure the virtual workspace's resolver 2023-05-26 20:20:56 +02:00
Wim Looman 7067d0df58
Improve warning message grammar 2023-05-26 20:09:27 +02:00
Wim Looman c31877def5
Update cargo new workspace inheritance tests to specify resolver 2023-05-26 17:14:34 +02:00
Wim Looman 620f66fa92
Mention workspace root's manifest explicitly 2023-05-26 16:41:04 +02:00
Ed Page 29dc47fa9a refactor(tests): Reduce cargo-add setup load
This just gets rid of irrelevant packages in the registry.  Looking into
which versions aren't needed would require a deeper pass, so I held off
on that for now.

Before, the tests were in the 300-500ms range and now they take
100-300ms.

This did call to my attention that `unrelated` is misspelled as
`unrelateed` but holding off on fixing that to reduce conflicts.
2023-05-26 09:24:45 -05:00
Wim Looman 2e2b3c1f1e
Warn when an edition 2021 crate is in a virtual workspace with default resolver
Edition 2021 updates the default resolver to version "2", but developers
using virtual workspaces commonly don't get this update because the
virtual workspace defaults to version "1". Warn when this situation
occurs so those developers can explicitly configure their workspace and
will be more likely to know that they will need to update it in the
future.
2023-05-26 16:11:09 +02:00
bors b9b5a45e3c Auto merge of #12184 - epage:rm, r=weihanglo
refactor(tests): Reduce cargo-remove setup load

This reduces the number of packages published in tests.  This is an artifact of when I changed `cargo-edit` from relying on crates.io to test-generated published packages.  I took the fastest path to making that conversion and took the shortcut of creating everything for every test.  I had assumed the cost was low but `@Muscraft` noticed that this takes up a lot of space which we run out of on CI occasionally and I expect a lot of small files are slowing down windows.

This only updates `cargo-remove`.  I'll be doing a follow up for `cargo-add`.
2023-05-26 13:53:32 +00:00
Ed Page ad9a44ddde refactor(tests): Reduce cargo-remove setup load
Benefits
- Clarifies a tests needs
- Speeds up testing, especially on Windows
- Reduces disk space issues within CI
2023-05-25 13:43:16 -05:00
bors fc905782cf Auto merge of #12174 - hi-rustin:rustin-patch-lints, r=epage
Automatically inherit workspace lints when running cargo new/init
2023-05-24 13:46:51 +00:00