7252 Commits

Author SHA1 Message Date
Ed Page
9b6e11e9b0 feat(tree): Color lines by dependency type 2025-02-28 09:46:50 -06:00
Ed Page
fb5407db7a feat(tree): Warn through colors for elided content 2025-02-28 09:46:08 -06:00
Ed Page
e293cd6cd2 test(tree): Add more UI tests 2025-02-28 09:45:57 -06:00
Ed Page
e2a991caf3 test(tree): Group all cargo-tree tests 2025-02-28 09:18:07 -06:00
Weihang Lo
58cfd96b59
fix: reset $CARGO if the running program is real cargo[.exe] (#15208)
Overwrite `$CARGO` when the current exe is detected to be a cargo
binary.

From
https://github.com/rust-lang/cargo/issues/15099#issuecomment-2666737150:
> opt-in behavior (set by cargo-the-bin):
>
> 1. `from_current_exe` if its `cargo[EXE_SUFFIX]`
> 2. `from_argv` if its `cargo[EXE_SUFFIX]`
> 3. `from_env`
> 4. `from_current_exe`
> 5. `from_argv`

r? @epage
2025-02-28 15:04:52 +00:00
Ed Page
726e2a70ea
Get all members as available targets even though default-members was specified. (#15199)
### What does this PR try to resolve?

The old behavior gets members from `default-members` if specified in a
virtual workspace, this PR gets all workspace members for `Available`
target hints.

Fixes https://github.com/rust-lang/cargo/issues/14544

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

The first commit added the test, the second commit addressed the issue.

### Additional information
2025-02-28 14:48:42 +00:00
Ed Page
8686e24c72
refactor: control byte display precision with std::fmt options (#15246)
### What does this PR try to resolve?

Just found we can simplify `human_readable_bytes` a bit.
This also remove the `bytesize` dependency,
since we already have a hand-rolled function.
(It is a good crate, though)

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

Should have no real functional difference.
`cargo package` starts reporting IEC (KiB) instead of SI (KB).
So do some thresholds of `cargo package`.

Could also switch entirely to `bytesize` if that is preferred.

### Additional information
2025-02-28 14:32:42 +00:00
Weihang Lo
425858c742
refactor: control byte display precision with std::fmt options 2025-02-28 08:56:28 -05:00
Yihai Lin
fa7712da82 feat: Make no target found hint more clear. 2025-02-28 10:03:59 +08:00
Yihai Lin
5ad084c3b0 feat(workspace): Search other crates if the default-members doesn't have the Target 2025-02-28 10:00:28 +08:00
Ed Page
730348ada9 fix(package): Ensure we can package directories ending with '.rs'
This might have also broken dependencies whose path ends with `.rs` as
well

This broke in #14961
2025-02-27 14:50:56 -06:00
Ed Page
45da135dba test(package): Show cargo script mistaken identity 2025-02-27 14:46:05 -06:00
Arlo Siemsen
5f833db69b feat: Add SBOM pre-cursor files
Adds a new option `build.sbom` that adds generation of a JSON file
containing dependency information alongside compiled artifacts.
2025-02-26 14:57:14 -06:00
Ed Page
3952e2dd28 feat(tree): Add --depth public impl 2025-02-26 14:51:54 -06:00
Ed Page
224222ee34 feat(tree): Add '--depth public' feature-gated value 2025-02-26 14:51:11 -06:00
Ed Page
0e73eb55f5 test(tree): Show exiting public/priv behavior 2025-02-26 14:50:31 -06:00
NoisyCoil
4e8b337eb3
feat(package): add --exclude-lockfile flag
When `--exclude-lockfile` is enabled,
`cargo package` will not verify the lock file if present,
nor will it generate a new one if absent.
Cargo.lock will not be included in the resulting tarball.

Together with `--no-verify`,
this flag decouples packaging from checking the registry index.
While this is useful for some non-normal workflows that requires
to assemble packages having unpublished dependencies.
It is recommended to use `-Zpackage-workspace` to package the entire
workspace, instead of opting out lockfile.
2025-02-26 12:48:48 -05:00
Weihang Lo
b7002ffd5e
test(package): fail with unpublished cyclic/transitive deps
After dd698ff0483bda065d1f78968e70ee86fb116a72,
`cargo package --no-verify` at least fails in three different cases:

* An unpublished package depending on itself as a dev-dependency (cyclic self-referential dev-dependencies).
  * Can be resolved by removing the `version` field from the affected dev-dependency.
  * `-Zpackage-workspace` doesn't help with it.
* Existing `cargo package` has `--package <pkg>` specifying certain unpublished packages.
  * Can be resolved by specifying all unpublished packages in one `cargo` call.
  * `-Zpackage-workspace` also requires all dependency versions available in the target registry when calling, so doesn't help.
* `cargo package --no-verify` has been used as a kind of “plumbing commands” to create tarballs without considering dependency orders. The use cases include:
  * Preparing tarballs for other package managers.
  * Integrating into custom develop workflows for unpublished/internal crates.
  * Constructing custom/private registries.

This commit shows the former two cases.
2025-02-26 12:45:45 -05:00
Ed Page
ffafda8fd4
fix(package): Register workspace member renames in overlay (#15228)
### What does this PR try to resolve?

This was reported at
https://github.com/rust-lang/cargo/issues/10948#issuecomment-2674289330

For the exact mapping between the publish payload and the index,
see

https://doc.rust-lang.org/cargo/reference/registry-index.html#json-schema,
particularly the note about differences.

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

### Additional information

I suspect there is a second bug here because my debugging only showed us
hitting this scenario for `val-json` and not `concepts` and only when
building `utils`. That difference in behavior between a transitive and
direct dependency is odd.
2025-02-25 15:19:55 +00:00
Yihai Lin
8b9dc21a24 test(workspace): Add test about workspace 2025-02-25 20:06:19 +08:00
Ross Sullivan
5874b6f347
Seperated build directory from target directory
This commits implements the seperation of the intermidate artifact
directory (called "build directory") from the target directory. (see #14125)
2025-02-25 21:05:23 +09:00
Ed Page
e1d61b8080 fix(package): Register workspace member renames in overlay
This was reported at https://github.com/rust-lang/cargo/issues/10948#issuecomment-2674289330

I suspect there is a second bug here because my debugging only showed us
doing this for `val-json` and not `concepts` and only when building `utils`.

For the exact mapping between the publish payload and the index,
see
https://doc.rust-lang.org/cargo/reference/registry-index.html#json-schema,
particularly the note about differences.
2025-02-24 11:27:37 -06:00
Ross Sullivan
1b82e1b0bf
Added build-dir unstable feature flag 2025-02-24 18:19:50 +09:00
Ross Sullivan
4ce639da9f
Added target-dir tests
These ares are in preparation to split target-dir into artifact-dir and build-dir
2025-02-24 18:19:49 +09:00
Samuel Moelius
a6fdc01cea Move test to cargo_command.rs 2025-02-23 17:37:39 -05:00
Samuel Moelius
44970a825d Fix #15099
Overwrite `$CARGO` when the current exe is detected to be a cargo
binary.

See: https://github.com/rust-lang/cargo/issues/15099#issuecomment-2666737150
2025-02-21 15:33:20 -05:00
Ed Page
4213e921ca test(package): Show behavior with renamed members 2025-02-21 08:39:40 -06:00
Ed Page
19d307170f fix(package): Fix lookups to capitalized workspace member's index entry 2025-02-21 08:25:23 -06:00
Ed Page
258db04176 test(package): Show behavior with capitalized member 2025-02-21 08:25:23 -06:00
Maurice Wangleng Tan
dbd64ec81f fix: mention "3" as a valid value for "resolver" field in error message 2025-02-21 21:46:22 +08:00
Ed Page
7e0da417c0 test(gc): Update tests for latest stable 2025-02-20 15:47:19 -06:00
Samuel Moelius
8e1931f3a4
Typo: "togother" -> "together"
In test name, `nonexistence_package_togother_with_workspace`.
2025-02-19 06:33:21 -05:00
Ed Page
524d123332 fix(add): Focus on error, rather than large feature lists
Inspired by #11100 and previous work to collapse feature lists down.
2025-02-18 12:44:13 -06:00
Ed Page
1f34b007e8 test(add): Show behavior with unrecognized feature with large list 2025-02-18 12:42:43 -06:00
brian m. carlson
7cd88900d3
util: provide a better error message for invalid SSH URLs
It's very common for users to attempt to use the pseudo-URLs that GitHub
or other providers provide in the form
`git@github.com:rust-lang/rust.git` as a source in Cargo.toml, which are
the default format accepted by OpenSSH. Unfortunately, these are not
actually URLs, and unsurprisingly, the `url` crate doesn't accept them.

However, our error message is unhelpful and looks like this:

    invalid url `git@github.com:rust-lang/rust.git`: relative URL without a base

This is technically true, but we can do better.  The user actually wants
to write a real SSH URL, so if the non-URL starts with `git@`, let's
rewrite it into a real URL for them to help them and include that in the
error message.

`git@` is the prefix used by all major forges, as well as the default
configuration for do-it-yourself implementations like Gitolite.  While
other options are possible, they are much less common, and this is an
extremely easy and cheap heuristic that does not necessitate complicated
parsing, but which we can change in the future should that be necessary.

This also avoids the problem where users try to turn the pseudo-URL into
a real URL by just prepending `ssh://`, which causes an error message
about the invalid port number due to the colon which they have not
changed.  Since they can just copy and paste the proposed answer,
they'll be less likely to attempt this invalid approach.
2025-02-14 19:43:16 +00:00
Eric Huss
b64750d83d
refactor(embedded): Integrate cargo-script logic into main parser (#15168)
### What does this PR try to resolve?

This is a part of #12207

Now that the experiment is over and we can be intrusive, this merges all
of the permanent cargo-script manifest logic into the regular manifest
loading code path with the goal of reducing the number of places people
need to be aware to check to know how things work so we're less likely
to overlook them (e.g. `package.name`s being optional). This should also
make error reporting better as we will eventually only use the real
manifest users specify, instead of one with a lot of edits by us.

This comes at the cost of some uglier code needed to check some of these
cases.

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

### Additional information
2025-02-11 14:54:56 +00:00
Andrew Liu
a471adbd2c feat: implement workspace feature unification 2025-02-11 15:10:39 +09:00
Andrew Liu
91e83d70ed test: verify feature unification behavior in workspaces 2025-02-11 12:15:12 +09:00
Eric Huss
be6598b7f0 Fix race condition in panic_abort_tests 2025-02-10 13:15:15 -08:00
Ed Page
6ec8da96f4 fix(schema): Mark package.name as optional 2025-02-10 14:29:15 -06:00
Ed Page
b7db1833b8 test(embedded): Verify fields are unsupported 2025-02-10 14:28:27 -06:00
Eric Huss
b5394da406 Update annotate-snippets from 0.11.4 to 0.11.5
Changelog: https://github.com/rust-lang/annotate-snippets-rs/blob/master/CHANGELOG.md#0115---2024-12-09

Looks to have some minor rendering differences.
2025-02-09 12:46:36 -08:00
Ed Page
5f529f792d test(toml): Verify missing package.name 2025-02-06 14:54:30 -06:00
Ed Page
027b415b52
feat: emit error if package not found within workspace (#15071)
### What does this PR try to resolve?

Fixes https://github.com/rust-lang/cargo/issues/12978

currently, if `--package `and `--workspace` passe in the same time, the
`--package` will be ignore even the package doesnt exist in the
workspace, this PR regards this behavior as an error

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

one commit add test, one commit fixes the issue.

### Additional information
2025-02-06 02:47:38 +00:00
Yihai Lin
23ab2afc25 feat: package doesnt exist in workspace is regarded as an error 2025-02-06 10:07:22 +08:00
Eric Huss
39cc418c04 Make cache tracking resilient to unexpected files
This makes the cache tracking synchronization code resilient to
unexpected files in the cache directory. Previously the code was
assuming that all entries in paths like `registry/index/*` are
directories. However, in circumstances like opening the directories in
macOS's finder, that can create files called `.DS_Store`. This caused it
to fail to scan within that path, since it isn't a directory.

This could in theory be made stricter, such as expecting directories to
have a particular pattern for its name. However, it seems like we never
enacted restrictions on what names are used for the git directories, so
it wouldn't work very well for that. Though that is something we could
consider in the future.
2025-02-05 14:39:47 -08:00
Eric Huss
dffa757620 Add test for unexpected stray files in the caches 2025-02-05 14:10:43 -08:00
Yihai Lin
69a3e0acac test: Add test to show --package nonexistence --workspace didn't warn. 2025-02-05 19:14:41 +08:00
Ed Page
f6514977ef
feat: add cargo pkgid support for cargo-script (#14961)
### What does this PR try to resolve?

close https://github.com/rust-lang/cargo/issues/14831

In this PR, we added the `cargo pkgid` support for the cargo-script.

For the package itself:

```console
cargo pkgid --manifest-path foo.rs
path+file:///my-project/foo.rs/foo#0.86.0
```

For its dependence:

```console
cargo pkgid --manifest-path foo.rs -p sqlx
registry+https://github.com/rust-lang/crates.io-index#sqlx@0.7.4
```

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

I have updated the unit tests and also added more test cases for it.

### Additional information

None
2025-02-04 19:52:07 +00:00
Daniel McNab
378f021a34 Suggest relevant feature names on the CLI
The left-aligned error message is there to
workaround rustfmt refusing to format files
which contain string literals which are too
wide. I have not found a consistent way to
fix this behaviour, but left-aligning does
resolve it in this case. I believe that this
should have an explanatory comment, but code
review determined that to be "noise" and so
I removed it.
2025-02-04 18:33:15 +00:00