Commit graph

620 commits

Author SHA1 Message Date
Eric Huss 47c7ff0f96 Deduplicate the similar dependency. 2023-11-21 10:18:15 -08:00
Eric Huss 70f56e9004 Add a general introduction to the rustfix library docs. 2023-11-21 10:10:22 -08:00
Eric Huss 402d072d72 Ignore rustfix for semver-checks since it doesn't exist on the beta branch. 2023-11-21 10:02:14 -08:00
David Tolnay 65bb09d434
Handle $message_type in JSON diagnostics 2023-11-19 20:37:16 -08:00
Eric Huss f99a494c31 Remove copyright headers in tests.
These were all removed a while ago in https://github.com/rust-lang/rust/pull/57108
2023-11-19 08:20:21 -08:00
Eric Huss b5308f648b Fix tests to run on stable. 2023-11-19 08:17:17 -08:00
Eric Huss d6e49ca06b Fix clippy warnings. 2023-11-19 08:07:37 -08:00
hi-rustin 504c4b2fbb Add optional flag to manifest for dependencies
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-19 22:04:04 +08:00
hi-rustin 12d7818192 Add features to the default Cargo.toml file
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-11-19 22:03:57 +08:00
Eric Huss b8ba6cd333 Bump the rustfix version. 2023-11-18 18:46:34 -08:00
Eric Huss 6e798b39bd Update rustfix readme to be a little more current. 2023-11-18 18:44:40 -08:00
Eric Huss a4fd77ce35 Switch rustfix license files to be symlinks 2023-11-18 18:31:08 -08:00
Eric Huss 63830afede Remove some unused rustfix files. 2023-11-18 18:29:58 -08:00
Eric Huss 3c0126aec4 rustfix: Drop test dependency on duct
It didn't seem to be doing anything that `Command` doesn't already
support. This helps lighten the dependency size.
2023-11-18 18:21:01 -08:00
Eric Huss f25cc63617 Update rustfix to use a newer proptest.
This uses the same version used elsewhere in cargo.
2023-11-18 18:14:00 -08:00
Eric Huss d0d9bd5cbb Switch rustfix to using tracing instead of log.
This helps bring it in line with the rust of cargo.
2023-11-18 18:10:44 -08:00
Eric Huss 9cb59bc202 Idiom lints are now configured in the manifest. 2023-11-18 17:49:18 -08:00
Eric Huss 3ca00ad8cd Integrate rustfix's manifest into the workspace. 2023-11-18 17:40:20 -08:00
Eric Huss 2eac6f5c0c Fix clippy-wrapper test race condition. 2023-11-18 17:23:29 -08:00
Eric Huss 73e5506338 Merge remote-tracking branch 'rustfix/master' into rustfix 2023-11-18 16:51:22 -08:00
Weihang Lo e2f5925bb0
chore: bump version for member crates 2023-11-16 13:19:44 -05:00
Weihang Lo 7a4754a1d3
lint: allow print_stdout and print_stderr 2023-11-16 11:35:21 -05:00
Weihang Lo 870f9ea7b3
lint: allow disallow_methods 2023-11-16 11:35:21 -05:00
Weihang Lo 1539b3dfc1
lint: dogfood ourselves lints table in manifest
These lint rules are from src/lib.rs. We aim to remove
them in the source code once `Zlints` hit stable.
2023-11-16 11:35:21 -05:00
Eric Huss 1d35833e3b Switch from AtomicU64 to Mutex.
Not all platforms support AtomicU64, so this swaps the usage with
Mutex. The difference in performance should be imperceptible.
2023-11-15 14:41:56 -08:00
Jacob Finkelman 6835fa3867 query{_vec} should use IndexSummary 2023-11-13 19:39:25 +00:00
Eric Huss 80ffb1de1c Fix --quiet being used with nested subcommands.
This fixes an issue where `--quiet` doesn't work with commands that have
subcommands. This is because `config_configure` only looks at the global
and top-level subcommand, and not deeper subcommands. The issue was that
`--quiet` was not defined as a global flag. This was changed in
https://github.com/rust-lang/cargo/pull/6358 in order to give a better
help message for `cargo test --quiet`. I don't remember if clap just
didn't support overriding at the time, or if we just didn't know how it
worked. Anyways, it seems to work to override it now, so I think it
should be fine to mark it as global.

This should bring in `--quiet` more in-line with how `--verbose` works.
This means that `--quiet` is now accepted with `cargo report`,
`cargo help`, and `cargo config`.

This also fixes `--quiet` with `cargo clean gc`.

This should also help with supporting `--quiet` with the new `cargo
owner` subcommands being added in
https://github.com/rust-lang/cargo/pull/11879.

Fixes #12957
2023-11-12 11:17:43 -08:00
Eric Huss 56c8d90d13 Use walkdir's built-in sorting option. 2023-11-11 10:56:59 -08:00
Eric Huss da3ca05677 Add a global cache garbage collector.
This adds a garbage collector which will remove old files from cargo's
global cache.

A general overview of the changes here:

- `cargo::core::global_cache_tracker` contains the `GlobalCacheTracker`
  which handles the interface to a sqlite database which stores
  timestamps of the last time a file was used.
- `DeferredGlobalLastUse` is a type that implements an optimization for
  collecting last-use timestamps so that they can be flushed to disk all
  at once.
- `cargo::core::gc` contains the `Gc` type which is the interface for
  performing garbage collection. It coordinates with the
  `GlobalCacheTracker` for determining what to delete.
- Garbage collection can either be automatic or manual. The automatic
  garbage collection supports some config options for defining when
  it runs and how much it deletes.
- Manual garbage collection can be performed via options to `cargo
  clean`.
- `cargo clean` uses the new package cache locking system to coordinate
  access to the package cache to prevent interference with other cargo
  commands running concurrently.
2023-11-11 10:56:58 -08:00
Eric Huss 9588fb6dda Add a du utility function.
This adds a very primitive `du` function for determining the disk usage
in a directory. This should probably be improved or replaced at some
point in the future, this is just a start for supporting tracking sizes
of cache data.
2023-11-11 10:56:58 -08:00
Ed Page 6bfc32a15e refactor(resolver): Pull MSRV handling to VersionPreferences 2023-11-07 20:39:35 -06:00
Ed Page bf2987b09b refactor(resolver): Track minimal-versions in VersionPreferences
This had repurcussions on direct-minimal-versions as it before relied on
the ordering parameter to `sort_sumarries`.
2023-11-07 20:39:35 -06:00
Ed Page 3cdddbf033 test(resolver): Improve failure output 2023-11-07 20:39:35 -06:00
Ed Page e70e310ce0 fix: Report more detailed semver errors
For `cargo install` we'll now show a more specific parse error for
semver, much like other parts of cargo.

This came out of my work on #12801.  I was looking at what might be
appropriate to put in a `cargo-util-semver` crate and realized we have
the `ToSemver` trait that exists but doesn't do much, so I dropped it.
2023-11-06 15:24:32 -06:00
Ed Page 293f2250d6 feat(doc): Print the generated docs links
I've wanted something like this myself.  I dislike using `--open`
because I tend to move up to re-run my `cargo doc` run but then have to
edit it to remove `--open`.
Also makes it annoying when opening docs when `cargo doc` is wrapped by
a tool like `make`.

This was previously attempted in #5592:
- Unlike the request in #5562, this aligns with #5592 in always printing
  rather than using a flag as this seems generally useful
- Unlike #5592, this prints as an alternative to "Opening" to keep
  things light
- Unlike #5592, this prints afterwards as the link is only valid then

Fixes #5562
2023-10-19 10:51:56 -05:00
bors f7e7cc2356 Auto merge of #12820 - linyihai:broken-symlink-target, r=weihanglo
add detailed message when target folder path is invalid

# What does this PR try to resolve?
close https://github.com/rust-lang/cargo/issues/12789

add more detailed message when target folder path is invalid

# How should we test and review this PR?

Before this PR, if the target folder refer to broken symbolic link like /a/b/c, then run cargo build, the output is:

```
error: Not a directory (os error 20)
```
the detailed error message is missing.

This PR will add the error context for it, the finall output will be
```
cargo build
error: failed to create directory `/root/workspace/playground/target`

Caused by:
  Not a directory (os error 20)
```
2023-10-14 04:43:58 +00:00
Lin Yihai ceac419776 add detailed message when target folder path is invalid 2023-10-14 11:34:42 +08:00
Ed Page 7846fe8cb4 chore: Sort dependency tables
This will make `cargo add` put things in the right place.

Verified by doing `cargo add arcstr && git diff && git reset --hard`
2023-10-10 15:03:22 -05:00
bors b48c41aedb Auto merge of #12706 - ehuss:cache-lock-mode, r=epage
Add new package cache lock modes

The way locking worked before this PR is that only one cargo could write to the package cache at once (otherwise it could cause corruption). However, it allowed cargo's to read from the package cache while running a build under the assumption that writers are append-only and won't affect reading. This allows multiple builds to run concurrently, only blocking on the part where it is not possible to run concurrently (downloading to the cache).

This introduces a new package cache locking strategy to support the ability to safely modify existing cache entries while other cargos are potentially reading from the cache. It has different locking modes:

- `MutateExclusive` (new) — Held when cargo wants to modify existing cache entries (such as being introduced for garbage collection in #12634), and ensures only one cargo has access to the cache during that time.
- `DownloadExclusive`  (renamed) — This is a more specialized name for the lock that was before this PR.   A caller should acquire this when downloading into the cache and doing resolution.  It ensures that only one cargo can append to the cache, but allows other cargos to concurrently read from the cache.
- `Shared` (new) — This is to preserve the old concurrent build behavior by allowing multiple concurrent cargos to hold this while a build is running when it is reading from the cache

**Reviewing suggestions:**
There are a few commits needed to help with testing which are first. The main commit has the following:
- `src/cargo/util/cache_lock.rs` is an abstraction around package cache locks, and is the heart of the change. It should have comments and notes which should guide what it is doing. The `CacheLocker` is stored in `Config` along with all our other global stuff.
- Every call to `config.acquire_package_cache_lock()` has been changed to explicitly state which lock mode it wants to lock the package cache in.
- `Context::compile` is the key point where the `Shared` lock is acquired, ensuring that no mutation is done while the cache is being read.
- `MutateExclusive` is not used in this PR, but is being added in preparation for #12634.
- The non-blocking `try_acquire_package_cache_lock` API is not used in this PR, but is being added in preparation for #12634 to allow automatic gc to skip running if another cargo is already running (to avoid unnecessary blocking).
- `src/cargo/util/flock.rs` has been updated with some code cleanup (removing unused stuff), adds support for non-blocking locks, and renames some functions to make their operation clearer.
- `tests/testsuite/cache_lock.rs` contains tests for all the different permutations of ways of acquiring locks.
2023-10-09 15:56:42 +00:00
Eric Huss b4982adfd9 Add a new package cache locking system.
This introduces a new `CacheLocker` which manages locks on the package
cache. Instead of either being "locked" or "not locked", the new locker
supports multiple modes:

- Shared lock: Cargo can read from the package sources, along with any
  other cargos reading at the same time.
- Download exclusive lock: Only one cargo can perform downloads.
  Download locks do not interfere with Shared locks, since it is
  expected that downloading does not modify existing files (only adds
  new ones).
- Mutate exclusive lock: Only one cargo can have this lock, and it also
  prevents shared locks. This is so that the cargo can modify the
  package cache (such as deleting files) without breaking concurrent
  processes.
2023-10-08 14:16:51 -07:00
Eric Huss b85ef38187 Add test helpers for waiting for an operation with a timeout. 2023-10-08 14:16:51 -07:00
Eric Huss 83fff2d1b1 Add a test helper for retrying a function multiple times. 2023-10-08 14:16:51 -07:00
bors 0871c0e2f4 Auto merge of #12795 - weihanglo:semver-checks, r=ehuss
ci: bump cargo-semver-checks to 0.24.0
2023-10-08 21:15:54 +00:00
Weihang Lo 60539e94dc
ci: bump cargo-semver-checks to 0.24.0
Also remove workaround since the issue was fixed in upstream.
2023-10-08 16:24:23 -04:00
Ed Page 03a642b1d8 fix: Set MSRV in all published packages 2023-10-06 16:34:42 -05:00
Tobias Bieniek 9e5dac18b9
crates.io: Bump version to 0.39.1 2023-10-06 16:11:38 +02:00
Tobias Bieniek e287f43006
crates-io: Add doc comment for NewCrate struct 2023-10-06 14:04:03 +02:00
Ed Page 72f4f0cb3f chore: Simplify releasing home
I'm not seeing any benefit derived by `html_root_url`
2023-10-02 12:13:49 -05:00
bors 9a94183771 Auto merge of #12744 - tompscanlan:atomic-write, r=epage
fix bug: corruption when cargo killed while writing

### What does this PR try to resolve?

fix  #11386, superseding #12362

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

Added unit test showing basic equivalency to existing `write(path, content)`. Full test suite should exercise write.
Added tests for cargo add and remove. These are timing tests, so take a bit of time to run. 5-10s each.  They may not fail every time, but do so regularly.  Making the change to these two writes seems to prevent me from failing these tests at all.

### Additional information

This uses tempfile::persist which was an existing dependency. atomicwrites crate, an alternative option for this fix, indicates `tempfile::persist` is the same thing.  Since we already use tempfile as a dep, I stuck with that.
2023-10-02 13:34:00 +00:00
Tom Scanlan aee8c75410
bug: corruption when killed while writing 2023-10-01 08:29:24 -04:00
Ed Page 37c6f3d085 fix(test): Add back in newlines to diffs
Errors like this aren't too helpful
```
error: stderr did not match:
1   1     error: failed to parse manifest at `[..]`2   2     3   3     Caused by:4   4       TOML parse error at line 3, column 275   5         |6   6       3 |                 version = 17
  7         |                           ^8        -  invalid type: integer `1`, expected SemVer version    8    +  invalid type: integer `1`, expected a string or workspace
```

This was broken in #12581
2023-09-29 20:02:53 -05:00
Ed Page 796398563a refactor(test): Switch termcolor to anstream 2023-09-29 10:16:15 -05:00
cui fliter c8f4d234bb Fix some typos
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-09-24 23:10:07 +08:00
Eric Huss ebea09d8f4 Fix spurious errors with networking tests. 2023-09-22 13:37:26 -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
bors f9335babbc Auto merge of #12707 - epage:spell, r=ehuss
chore: Fix typos

This is a repeat of #11561
2023-09-19 22:07:03 +00:00
Jacob Finkelman 679d65103f shortest path is probably more informative than random path for error messages 2023-09-19 20:39:02 +00:00
Ed Page e4e10f2393 chore: Fix typos
This is a repeat of #11561
2023-09-19 15:28:48 -05:00
Jacob Finkelman 245e69ce10 add a test for shortest path 2023-09-19 20:22:13 +00:00
Ed Page 4135f562b8 refactor(manifest): Clarify the specialized role of RustVersion 2023-09-13 21:59:26 -06:00
Weihang Lo 463622ad81
lint: fix errors for self-named module files 2023-09-14 13:43:48 +08:00
Weihang Lo aef3bd22d3
lint: fix errors for rust 2018 idioms 2023-09-14 13:43:48 +08:00
Weihang Lo 437942ee7e
lint: use eprintln for human-facing outputs 2023-09-14 13:43:47 +08:00
Weihang Lo f9d82a1703
lint: remove unused dbg! 2023-09-14 13:43:47 +08:00
Jacob Finkelman 205fd1a765 libgit2 fixed upstream 2023-09-11 19:25:45 +00:00
Jacob Finkelman 2b2838302f bump cargo-platform 2023-09-08 19:16:42 +00:00
Jacob Finkelman 44666f7377 Ues strip_prefix for cleaner code 2023-09-07 17:57:28 +00:00
Weihang Lo e575448574
refactor: flatten module path of SourceId 2023-09-07 21:06:35 +08:00
Weihang Lo b6c4e47cc0
refactor: put Source trait under cargo::sources 2023-09-07 21:06:34 +08:00
bors baca00ebe1 Auto merge of #12636 - ehuss:fs-metadata-wrappers, r=weihanglo
Add wrappers around std::fs::metadata

This adds wrappers around `std::fs::metadata` and `std::fs::symlink_metadata` which provide better error messages indicating the path that caused the error. This just helps clean up some duplicated code, and is also going to be used to assist with some code changes in #12634.
2023-09-07 08:54:50 +00:00
bors 282424e42d Auto merge of #12635 - ehuss:with-stdout-unordered, r=weihanglo
Add with_stdout_unordered.

This adds the `with_stdout_unordered` method to cargo's test system so that tests can use it to check stdout but ignoring the order of lines. Nothing in this PR actually uses this method, but it is added to support #12634. I also expect it could potentially be useful in other cases in the future.
2023-09-07 06:26:51 +00:00
Eric Huss 62d86470d1 Add wrappers around std::fs::metadata
This adds wrappers around std::fs::metadata and
std::fs::symlink_metadata which provide better error messages indicating
the path that caused the error.
2023-09-06 21:41:54 -07:00
Eric Huss 0adb9f1b2a Add with_stdout_unordered.
This adds Execs::with_stdout_unordered to check stdout ignoring the
order of lines.
2023-09-06 21:40:56 -07:00
Eric Huss 8964f3fd5d Fix example for creating a git project test. 2023-09-06 18:56:12 -07:00
bors cff6d19f6e Auto merge of #12615 - Eh2406:split_once, r=epage
use split_once for cleaner code

### What does this PR try to resolve?

Search the code base for `.splitn(2` and replace with `.split_once` where it was clearer. I don't think any of them matter in practice.

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

This was an internal re-factor, and the tests still pass.
The two methods have subtly different semantics, so please review carefully.
2023-09-03 02:27:49 +00:00
Jacob Finkelman 1ea81a3692 use split_once for cleaner code 2023-09-01 21:45:55 +00:00
Jacob Finkelman 16b330bc59 stop using lazy_static 2023-09-01 21:38:03 +00:00
Ed Page 4820624ce7 feat(resolver): Respect MSRV 2023-08-25 10:42:26 -05:00
bors f797978283 Auto merge of #12553 - epage:version, r=weihanglo
refactor: Pull out cargo-add MSRV code for reuse

### What does this PR try to resolve?

#12078 added MSRV code in `cargo add`. Our assumption when writing it is that we'd need to generalize the code before reusing it in other places, like `cargo install`.  This PR focused purely on that refactor because I'm hopeful it will be useful for other work I'm doing.  Despite not having a user for this yet, I think the `cargo install` case is inevitable and I feel this does a bit to clean up MSRV related code by using a more specific type everywhere.

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

Each commit gradually progresses things along
2023-08-25 14:56:24 +00:00
Deadbeef b2b34e4ca2 update tests 2023-08-25 01:43:29 +00:00
Deadbeef 3d50f47197 Add fields for bindeps on the registry 2023-08-25 01:43:29 +00:00
Ed Page 423a334520 refactor: Parse, don't validate, rust_version
By using the `PartialVersion` type with serde, we get the context for
the error automatically.
2023-08-24 14:15:35 -05:00
Ed Page 7a65c826a0 fix: Set MSRV for internal packages
For now, I'm punting on packages we generally expect others to use
2023-08-22 16:46:47 -05:00
Ed Page 576f901f81 fix(log): Use a more compact relative-time format
This changes logged messages from
```
2023-08-23T01:01:59.922018Z DEBUG cargo::core::compiler::fingerprint: filesystem up-to-date "/home/epage/src/personal/dump"
```
To
```
   0.041729583s DEBUG cargo::core::compiler::fingerprint: filesystem up-to-date "/home/epage/src/personal/dump"
```
Benefits
- Less horizontal space taken up in boilerplate
- Easier to compare within a run

Downsides
- Harder to correlate with other processes, like with crates.io server
  operations

This gives us up to 4 digits for seconds which should be sufficient for
cargo build times.

We could make this more compact by dropping the digits of precision from
9 to 6 but that would require a custom Timer which might be a paint to
keep in sync between packages.
2023-08-22 20:34:07 -05:00
Eric Huss 96da3c4872 Support hidden lines. 2023-08-17 18:18:10 -07:00
Eric Huss 4c1d8f1364 Document the special code block annotations. 2023-08-17 18:18:10 -07:00
Arlo Siemsen 763edbab09 rename crate to cargo-credential-libsecret 2023-08-17 16:05:31 -05:00
Weihang Lo 5691da2b79
chore(cargo-util): bump version to 0.2.6 2023-08-16 20:06:40 +01:00
Weihang Lo 1ee9db3123
fix(xtask-bump-check): query by package name to detect changes
versions and paths of a workspace members between the original and
a checked-out workspace are different, and shouldn't be included in
hash keys when querying packages.
2023-08-16 15:46:43 +01:00
Weihang Lo c07043b7cf
fix(log): enable ansi color only in terminal 2023-08-14 15:45:25 +01:00
Weihang Lo 9d707e4b9a
chore: remove log, env_logger, and pretty_env_logger 2023-08-07 12:02:19 +01:00
Weihang Lo 7e69050c64
refactor: setup tracing-subscriber 2023-08-07 12:02:19 +01:00
Weihang Lo 23561f36a1
chore: add tracing-subscriber crate 2023-08-07 11:25:41 +01:00
Weihang Lo af1a78b424
refactor: find & replace log:: -> tracing::
Except HTTP network debugging
2023-08-07 11:25:40 +01:00
Weihang Lo 9f0565e985
chore: add tracing crate 2023-08-07 11:21:55 +01:00
bors 6145d0c4d2 Auto merge of #12395 - weihanglo:cargo-semver-checks, r=epage
ci: rewrite bump check and respect semver

### What does this PR try to resolve?

This ports `ci/validate-version-bump.sh` and #12200 to the new xtask `bump-check`. It also adds the ability to set the correct baseline revision when checking version bump. That is, it fixes #12347.

In addition, this integrates the community tool `cargo-semver-checks`. SemVer violation can now be detected earlier.

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

This PR extracts the registry query part from `xtask-unpublished` and removes other pars. I don't feel like we need it in the short term.

For how it works, please the check doc comment in each function.

One concern is that this check is still a required job for bors. I believe `@obi1kenobi` is quite responsive and willing to help if there is something wrong. So, waiting for an upstream fix won't be a problem for cargo. Also as a good citizen in the community, we can always contribute back.
(Take it easy `@obi1kenobi,` don't be stressed out 🙂)
<!-- homu-ignore:end -->
2023-08-01 23:00:45 +00:00
Weihang Lo 8d31d626a2
chore: remove xtask-unpublished 2023-08-01 22:54:41 +01:00
Weihang Lo 9cca5721e4
chore: new xtask bump-check
This is a rewrite of old `ci/validate-version-bump.sh` in Rust.
2023-08-01 22:54:40 +01:00
renovate[bot] a63bc76577
chore(deps): update alpine docker tag to v3.18 2023-08-01 02:18:33 +00:00
Weihang Lo 46bf05dcaf
chore: update home to 0.5.7 2023-07-26 11:26:49 +01:00