7252 Commits

Author SHA1 Message Date
Urgau
208f817c83 Add preparatory tests for lib.test = false check-cfg changes 2025-01-04 13:42:59 +01:00
Kornel
22690a3236
Make --allow-dirty imply --allow-staged 2025-01-04 00:25:41 +00:00
Rustin170506
0c2bb4e5a8 test: add the dep case
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-02 23:17:15 +08:00
Rustin170506
feda97d9f2 test: add the no lock file case
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-02 23:17:15 +08:00
Rustin170506
5465e6a451 fix: remove unsupported embedded workspace check from cargo pkgid command
Signed-off-by: Rustin170506 <techregister@pm.me>
2025-01-02 23:17:11 +08:00
Weihang Lo
3c75c1532e
refactor(cargo-package): let-else to flatten code
This also adds some more debug logs
2024-12-19 08:37:24 -05:00
Ed Page
2438807048 test(git): Be consistent on shallow test names 2024-12-18 15:44:01 -06:00
Ed Page
e0f8cc06da test(git): Group related shallow tests 2024-12-18 15:44:01 -06:00
Ed Page
a739b00f30 test(git): Clarify we are doing shallow fetches 2024-12-18 15:44:01 -06:00
Ed Page
adf25782e0 test(git): Extract CLI arg creation 2024-12-18 15:43:59 -06:00
Ed Page
cade73a7a0 test(git): Make test backend clearer 2024-12-18 15:43:31 -06:00
Ed Page
4e3e353978 test(git): Reduce duplication in shallow test 2024-12-18 11:57:16 -06:00
Ed Page
1c82fe420e test(git): Prefer check over build for faster tests
If check passes, it should be sufficient.
2024-12-18 11:49:51 -06:00
Ed Page
4cc7ff5ab5 test(git): Fix masquerade feature list for shallow fetch 2024-12-18 11:32:54 -06:00
Ed Page
89b89bde65 test(git): Clarify test parameter 2024-12-18 11:32:53 -06:00
Ed Page
48e8a718ec test(git): Collect tests that use the same body 2024-12-18 11:31:50 -06:00
Weihang Lo
03a5f111b1
fix: env table config can't trigger rebuild with rerun-if-env-changed. (#14756)
### What does this PR try to resolve?

As #10358 said, `When a build.rs script emits
cargo:rerun-if-env-changed, it is not re-run when the value of the
specified variable is changed via the env configuration.`

Fixes #10358

### How should we test and review this PR?
Add test bofore fixing to reflect the issue, the next commit fixed it.

### Additional information

The PR is a sucessor of https://github.com/rust-lang/cargo/pull/14058,
so the previous dicussion can be refer to it.
2025-01-01 06:46:41 +00:00
Lin Yihai
76ffbe0571 fix: envs in config can trigger rebuild by custom build script with rerun-if-env-changed. 2025-01-01 14:10:00 +08:00
Weihang Lo
24dd205d5a
fix(package): deduplicate dirty symlink detection
metdata path fields may point to a dirty symlilnk and cause
duplicate report. This commit combines `dirty_metadata_paths`
and `dirty_symlinks` into one so is able to de-duplicate them.
2024-12-31 16:25:31 -05:00
Weihang Lo
de39f59e26
fix(package): check dirtiness of symlink source files
This adds a special case for checking source files are symlinks
and have been modified when under a VCS control

This is required because those paths may link to a file outside the
current package root, but still under the git workdir, affecting the
final packaged `.crate` file.

This may have potential performance issue. If a package contains
thousands of symlinks, Cargo will fire `git status` for each of them.
2024-12-31 16:25:31 -05:00
Weihang Lo
014e516e74
test(package): symlink dirty also under dirtiness check
This show that a regular file under a symlink directory
is also not tarcked by the current vcs dirtiness check.
2024-12-31 16:25:31 -05:00
Weihang Lo
059fe16085
fix(package): warn if symlinks checked out as plain text files
`cargo package` will warn users when git `core.symlinks` is `false`
and some symlinks were checked out as plain files during packaging.

Git config [`core.symlinks`] defaults to true when unset.
In git-for-windows (and git as well),
the config should be set to false explicitly when the repo was created,
if symlink support wasn't detected [^1].

We assume the config was always set at creation time and never changed.
So, if it is true, we don't bother users with any warning.

[^1]: <f1241afcc7/setup.c (L2394-L2403)>

[`core.symlinks`]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-coresymlinks
2024-12-31 14:19:55 -05:00
Weihang Lo
871b17f59a
test(package): show behavior with core.symlinks=false 2024-12-31 11:52:44 -05:00
Lin Yihai
a014fd0814 test: add test for rerun-if-env-changed custom build script. 2024-12-31 14:44:13 +08:00
Rustin
9b5efd903c
test: relax panic output assertion (#14989)
### What does this PR try to resolve?

rust-lang/rust#122565 adds a new line to thread panic output.
To make the current test suites works on stable, beta, and nightly,
similar to rust-lang/cargo#14602,
this relaxes the assertion around that by globbing everything.
2024-12-30 11:48:12 +00:00
许杰友 Jieyou Xu (Joe)
17aaafd92f tests: relax bad_crate_type to only match error message prefix
So that the cargo test isn't sensitive to suggestions for known crate
types that a rustc PR <https://github.com/rust-lang/rust/pull/134720> is
trying to add.
2024-12-30 04:22:28 +08:00
Weihang Lo
b7d98618b6
test: relax panic output assertion
rust-lang/rust#122565 adds a new line to thread panic output.
To make the current test suites works on stable, beta, and nightly,
similar to rust-lang/cargo#14602,
this relaxes the assertion around that by globbing everything.
2024-12-29 13:45:24 -05:00
Weihang Lo
863e1f40de
fix(package): check dirtiness of path fields in manifest
This adds a special case for `package.{readme,license-file}`
to Git VCS status check.
If they were specified with paths outside the current package root,
but still under git workdir, Cargo checks git status of those files
to determine if they were dirty.

We don't need to take care of other fields with path values because

* `PathSource` only list files under the package root.
  Things like `target.path` works for `cargo build`, but won't be
  included in `.crate` file from `cargo publish`.
* The only exceptions are `package.readme`/`package.license-file`.
  Cargo would copy files over if they are outside package root.
2024-12-24 11:59:21 -05:00
Weihang Lo
a991a7dd98
test(package): show corner cases of vcs dirtiness check
This is a test showing corner cases that dirty files outside
the package being packaging actually made the `.crate` file dirty.
However, `cargo package` and `.cargo_vcs_info.json` didn't capture it.
2024-12-24 11:57:40 -05:00
Ed Page
4945803e53
test: make path arguments more generic and flexible (#14979)
### What does this PR try to resolve?

So we don't need to `p.to_str().unwrap()`
and are able to pass different types for each argument

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

No response.
2024-12-24 16:03:59 +00:00
Weihang Lo
0921264bc5
test: make path arguments more generic and flexible
So we don't need to `p.to_str().unwrap()`
and are able to pass different types for each argument
2024-12-24 10:33:21 -05:00
Weihang Lo
3447b1132f
Moved manifest metadata tracking from fingerprint to dep info (#14973)
<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

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

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

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

### What does this PR try to resolve?

Fixes #14154

~~Added some of the missing package metadata to the fingerprint so that
rebuilds are triggered correctly.~~
~~Also updated the test to prevent a future regression.~~

Moved the manifest metadata tracking to use dep info in favor of
fingerprint so that rebuilds are only triggered if the metadata is
actually used.
2024-12-24 14:10:47 +00:00
ranger-ross
3d7b154d15
Moved manifest metadata tracking from fingerprint to dep info
This change moves the manifest metadata track to dep-info files
with the goal of reduce unneeded rebuilds when metadata is changed as
well fixing issues where builds are not retrigged due to metadata
changes when they should (ie. #14154)
2024-12-24 16:52:51 +09:00
Sebastian Thiel
af92c4445b
Use snapshots instead of matching on parts of the output
Personally I liked that the test was only dependent on what really matters, the lack of presence of a particular filename. Now the test would fail if Cargo one day adds more (generated) files to the package.

Co-authored-by: Weihang Lo <weihanglo@users.noreply.github.com>
2024-12-24 08:03:16 +01:00
Sebastian Thiel
2c3f8d87c4
fix: assure possibly blocking non-files (like FIFOs) won't be picked up for publishing.
This would otherwise cause the publish to hang.
2024-12-23 08:14:42 +01:00
Weihang Lo
d325acea1d
fix(package): use relpath to cwd for vcs dirtiness report
Address https://github.com/rust-lang/cargo/pull/14968#issuecomment-2555901072
2024-12-19 20:22:21 -05:00
Weihang Lo
9e2b373acb
test(package): relative path to cwd for dirtiness report 2024-12-19 20:18:05 -05:00
Ed Page
efaaa0ce33
fixed the error message for a user to open the crate (#14969)
### What does this PR try to resolve?

This PR is resolving an
[issue](https://github.com/rust-lang/cargo/issues/14776#issuecomment-2515017963)
where `cargo doc --open --examples` does not give a clear message when
the examples file is given to it.

I changed the message from `no crates with documentation` in the
[cargo_doc.rs](58b2d609ec/src/cargo/ops/cargo_doc.rs (L62))
and
[doc.rs](58b2d609ec/tests/testsuite/doc.rs (L1504))
to `requested crate documentation is not available to open`. Now it
becomes easy for the user to understand what they're missing.

 Fixes #14776

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

Here is the command through which you can test this change:

`cargo test SNAPSHOTS=overwrite -- doc::open_no_doc_crate`

<!--
Thanks for submitting a pull request 🎉! Here are some tips for you:

* If this is your first contribution, read "Cargo Contribution Guide"
first:
  https://doc.crates.io/contrib/
* Run `cargo fmt --all` to format your code changes.
* Small commits and pull requests are always preferable and easy to
review.
* If your idea is large and needs feedback from the community, read how:
  https://doc.crates.io/contrib/process/#working-on-large-features
* Cargo takes care of compatibility. Read our design principles:
  https://doc.crates.io/contrib/design.html
* When changing help text of cargo commands, follow the steps to
generate docs:

https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages
* If your PR is not finished, set it as "draft" PR or add "WIP" in its
title.
* It's ok to use the CI resources to test your PR, but please don't
abuse them.

### What does this PR try to resolve?

Explain the motivation behind this change.
A clear overview along with an in-depth explanation are helpful.

You can use `Fixes #<issue number>` to associate this PR to an existing
issue.

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

Demonstrate how you test this change and guide reviewers through your
PR.
With a smooth review process, a pull request usually gets reviewed
quicker.

If you don't know how to write and run your tests, please read the
guide:
https://doc.crates.io/contrib/tests

### Additional information

Other information you want to mention in this PR, such as prior arts,
future extensions, an unresolved problem, or a TODO list.
-->
2024-12-19 23:17:12 +00:00
Ed Page
71678a4cf4
fix(package): show dirty filepaths relative to git workdir (#14968)
### What does this PR try to resolve?

Dirty file paths in the original message were stripped relative to
package root.
User is not able to know the full path to find dirty files.

This PR makes it relative to git workdir.

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

This was found during #14962
2024-12-19 23:09:08 +00:00
Bilal Khan
871e281cff fixed the error message for a user to open the crate 2024-12-20 03:46:16 +05:00
Weihang Lo
982eb2de3a
fix(package): show dirty filepaths relative to git workdir 2024-12-19 17:34:38 -05:00
Weihang Lo
ecc8e37f40
test(package): track vcs status on workspace member granularity 2024-12-19 17:31:25 -05:00
Urgau
5720eb77db Add the test cfg as a well known cfg before of compiler change 2024-12-19 20:41:23 +01:00
Weihang Lo
1d74d955a7
fix(cargo-rustc): stabilize higher precedence trailing flags
This was always enabled on nightly since 1.83-nightly (2024-09).
We have no feedback since then, so assume it is a low-impact change.

This stabilization is targeted at 1.85 (2025-02-20)
2024-12-18 09:30:17 -05:00
Weihang Lo
0149bca5cc
fix(build-std): behavior revert of 125e873dffc4b68b
This is kinda a revert of 125e873dffc4b68b263c5decd88750ec10fd441e
in terms of the behavior.

After this, now `std_resolve` is always resolved by the same set of
packages that Cargo will use to generate the unit graph, (technically
the same set of crates + `sysroot`), by sharing the same set of primary
packages via `std_crates` functions.
2024-12-17 19:02:35 -05:00
Weihang Lo
f004691aa4
test(build-std): resolve too less deps
This failed because since 125e873dffc4b68b263c5decd88750ec10fd441e
[`std_resolve`][1] only includes `sysroot` as primary package.
When any custom Cargo feature is provided via `-Zbuild-std-feature`,
the default feature set `panic-unwind` would be gone, so no
`panic_unwind` crate presents in `std_resolve`.

When then calling [`std_resolve.query`][2] with the default set of
crates from [`std_crates`][3], which automatically includes
`panic_unwind` when `std` presents, it'll result in spec not found
because `panic_unwind` was not in `std_resolve` anyway.

[1]: addcc8ca71/src/cargo/core/compiler/standard_lib.rs (L96)
[2]: addcc8ca71/src/cargo/core/compiler/standard_lib.rs (L158)
[3]: addcc8ca71/src/cargo/core/compiler/standard_lib.rs (L156)

See rust-lang/cargo#14935
2024-12-17 19:02:35 -05:00
Weihang Lo
ca59614620
test(build-std): Isolate output test to avoid spurious [BLOCKING] messages from concurrent runs
47c2095b1dd580a91e42cb6197b58a318526b8c4 didn't really fix the flakiness.

build-std tests use the users `CARGO_HOME` for downloading registry
dependencies of the standard library. This reduces disk needs of the
tests, speeds up the tests, and reduces the number of network requests
that could fail.

However, this means all of the tests access the same locks for the
package cache.  In one test, we assert on the output and a `[BLOCKING]`
message can show up, depending on test execution time from concurrent
test runs.

We are going to hack around this by having the one test that asserts
on test output to use the standard `cargo-test-support` `CARGO_HOME`,
rather than the users `CARGO_HOME`. There will then only be one process
accessing the lock and no `[BLOCKING]` messages.
2024-12-17 18:43:17 -05:00
Weihang Lo
80409f7016
test(build-std): dont require rustup
It checks rustup existence even when test is skipped for other reasons
2024-12-13 22:36:09 -05:00
Ed Page
5b8b2ac248 fix(base): Support bases in patches in virtual manifests
This bug has been there since #14360
2024-12-13 11:00:57 -06:00
Ed Page
2d23b94a7f test(base): Verify bases in patches in virtual manifests 2024-12-13 11:00:04 -06:00