Commit graph

426 commits

Author SHA1 Message Date
Dale Wijnand 2fe2ea9e71
Use p.cargo's ability to split on whitespace more 2018-08-02 15:18:44 +01:00
bors 63a08ee7d5 Auto merge of #5831 - Eh2406:i5684, r=alexcrichton
cargo can silently fix some bad lockfiles (use --locked to disable)

Lock files often get corrupted by git merge. This makes all cargo commands silently fix that kind of corruption.

If you want to be sure that your CI does not change the lock file you have commited
---

Then make sure to use `--locked` in your CI

Edit: original description below

---------------

This is a continuation of @dwijnand work in #5809, and closes #5684

This adds a `ignore_errors` arg to reading a lock file which ignores sections it doesn't understand. Specifically things that depend on versions that don't exist in the lock file. Then all users pass false except for the two that relate to `update` command.

I think the open questions for this pr relate to testing.
- Now that we are passing false in all other commands, do they each need a test for a bad lockfile?
- Do we need a test with a more subtly corrupted lock file, or is this always sufficient for `update` to clean up?
2018-08-01 16:39:58 +00:00
bors f14aea53ad Auto merge of #5834 - Undin:metadata-edition, r=alexcrichton
Add edition info into metadata

Since edition feature was introduced, external tools have to support this new feature.
But cargo metadata doesn't provide info about package edition.
This commit adds edition field to `SerializedPackage` struct to add the corresponding field into metadata output.
2018-08-01 15:51:56 +00:00
Alex Crichton adbd625e35 Upgrade to failure 0.1.2 idioms
Fixes some deprecation warnings in Cargo
2018-08-01 07:20:04 -07:00
Arseniy Pendryak 3fdce227b4 fix tests on Windows 2018-08-01 09:04:55 +03:00
bors 0b80061cac Auto merge of #5842 - alexcrichton:fix-lots, r=ehuss
fix: Iteratively apply suggestions from the compiler

This commit updates the `cargo fix` implementation to iteratively apply fixes
from the compiler instead of only once. Currently the compiler can sometimes
emit overlapping suggestions, such as in the case of transitioning

    ::foo::<::Bar>();

to ...

    crate::foo::<crate::Bar>();

and `rustfix` rightfully can't handle overlapping suggestions as there's no
clear way of how to disambiguate the fixes. To fix this problem Cargo will now
run `rustc` and `rustfix` multiple times, attempting to reach a steady state
where no fixes failed to apply.

Naturally this is a pretty tricky thing to do and we want to be sure that Cargo
doesn't loop forever, for example. A number of safeguards are in place to
prevent Cargo from going off into the weeds when fixing files, notably avoiding
to reattempt fixes if no successful fixes ended up being applied.

Closes #5813
Closes rust-lang/rust#52754
2018-08-01 02:52:35 +00:00
Arseniy Pendryak 5dcc4f1794 Add edition field into target object in metadata as well 2018-08-01 02:24:49 +03:00
bors b8dc28f126 Auto merge of #5836 - kornelski:profiledebug, r=alexcrichton
Hint correct name of profile.debug

Cargo talks about "debug" and "release" builds, but there are "dev" and "release" profiles. [This is a gotcha](https://users.rust-lang.org/t/rust-emscripten-emterpreter/19215/5). I've added an explicit hint that `profile.debug` is supposed to be `profile.dev`.
2018-07-31 21:37:35 +00:00
Alex Crichton 876a50366b fix: Iteratively apply suggestions from the compiler
This commit updates the `cargo fix` implementation to iteratively apply fixes
from the compiler instead of only once. Currently the compiler can sometimes
emit overlapping suggestions, such as in the case of transitioning

    ::foo::<::Bar>();

to ...

    crate::foo::<crate::Bar>();

and `rustfix` rightfully can't handle overlapping suggestions as there's no
clear way of how to disambiguate the fixes. To fix this problem Cargo will now
run `rustc` and `rustfix` multiple times, attempting to reach a steady state
where no fixes failed to apply.

Naturally this is a pretty tricky thing to do and we want to be sure that Cargo
doesn't loop forever, for example. A number of safeguards are in place to
prevent Cargo from going off into the weeds when fixing files, notably avoiding
to reattempt fixes if no successful fixes ended up being applied.

Closes #5813
Closes rust-lang/rust#52754
2018-07-31 14:20:58 -07:00
bors 72eee12f0d Auto merge of #5835 - dwijnand:clippy, r=alexcrichton
Resolve some Clippy warnings

I'm not sure how these popped up since my PR 8 days ago.

My current hypotheses:
* changes in latest nightly rust/clippy
* new or changed cargo code
* I missed these as I was only touching `src/bin/cargo/main.rs`

For future reference I now iterate with:

    touch src/bin/cargo/main.rs src/cargo/lib.rs && cargo +nightly clippy
2018-07-31 20:26:45 +00:00
Arseniy Pendryak 62cd0dbe51 Add edition field into metadata.
Since edition feature was introduced, external tools have to support this new feature.
But cargo metadata doesn't provide info about package edition.
This commit adds edition field to SerializedPackage struct
to add the corresponding field into metadata output.
2018-07-31 22:46:31 +03:00
bors 9bbab73a75 Auto merge of #5824 - alexcrichton:careful-transition, r=alexcrichton
Add more diagnostics to smooth edition transition

This commit adds two diagnostics in particular to ease the transition into the
2018 edition. The current transition process is pretty particular and must be
done carefully, so let's try to automate things to make it as painless as
possible! Notably the new diagnostics are:

* If you `cargo fix --prepare-for 2018` a crate which already has the 2018
  edition enabled, then an error is generated. This is because the compiler
  can't prepare for the 2018 edition if you're already in the 2018 edition, the
  lints won't have a chance to fire. You can only execute `--prepare-for 2018`
  over crates in the 2015 edition.

* If you `cargo fix --prepare-for 2018` and have forgotten the
  `rust_2018_preview` feature, a warning is issued. The lints don't fire unless
  the feature is enabled, so this is intended to warn in this situation to
  ensure that lints fire as much as they can.

After this commit if `cargo fix --prepare-for` exits successfully with zero
warnings then crates should be guaranteed to be compatible!

Closes #5778
2018-07-31 19:28:52 +00:00
Eh2406 a418364dda remove missing from the package list error and fmt 2018-07-31 15:04:12 -04:00
bors d9feff2b88 Auto merge of #5811 - alexcrichton:rename-crate-feature-names, r=ehuss
Use listed dependency name for feature names

This commit updates the implementation of renamed dependencies to use the listed
name of a dependency in Cargo.toml for the name of the associated feature,
rather than using the package name. This'll allow disambiguating between
different packages of the same name and was the intention all along!

Closes #5753
2018-07-31 18:18:17 +00:00
bors 4b95e8c50e Auto merge of #5816 - dwijnand:edtion-per-target, r=alexcrichton
Edition key should be per-target, not per-package

Fixes #5661

I've pushed this WIP PR as I'd love some early feedback on it and some tips on:

* how to best to make it fail if edition is set on a target, but the feature isn't set; and
* what tests this should include (i.e how exhaustive should I go)

Thanks!
2018-07-31 17:10:10 +00:00
Alex Crichton 5295caddd5 Use listed dependency name for feature names
This commit updates the implementation of renamed dependencies to use the listed
name of a dependency in Cargo.toml for the name of the associated feature,
rather than using the package name. This'll allow disambiguating between
different packages of the same name and was the intention all along!

Closes #5753
2018-07-31 07:28:53 -07:00
Alex Crichton fa7a387740 Add more diagnostics to smooth edition transition
This commit adds two diagnostics in particular to ease the transition into the
2018 edition. The current transition process is pretty particular and must be
done carefully, so let's try to automate things to make it as painless as
possible! Notably the new diagnostics are:

* If you `cargo fix --prepare-for 2018` a crate which already has the 2018
  edition enabled, then an error is generated. This is because the compiler
  can't prepare for the 2018 edition if you're already in the 2018 edition, the
  lints won't have a chance to fire. You can only execute `--prepare-for 2018`
  over crates in the 2015 edition.

* If you `cargo fix --prepare-for 2018` and have forgotten the
  `rust_2018_preview` feature, a warning is issued. The lints don't fire unless
  the feature is enabled, so this is intended to warn in this situation to
  ensure that lints fire as much as they can.

After this commit if `cargo fix --prepare-for` exits successfully with zero
warnings then crates should be guaranteed to be compatible!

Closes #5778
2018-07-31 07:28:07 -07:00
Dale Wijnand 689f412c2f
Resolve 2 needless_pass_by_value lint warnings
TIL Rust doesn't have equational reasoning.. :-/
(can't inline the new "exec" bindings)
2018-07-31 15:12:43 +01:00
Dale Wijnand 67c52ffe58
Add tests for per-target edition
Test:
* enabling edition feature & setting at target level (happy path)
* overriding the package-level edition with per-target edition
* feature gating of per-target edition
* per-target edition usage for rustdoc
2018-07-31 14:49:33 +01:00
Kornel Lesiński 5f3e8cbfa2 Hint correct name of profile.debug 2018-07-31 10:18:10 +01:00
Alex Crichton 7691deb325 fix: Only fix "primary" packages by default
The previous heuristic for fixing packages was to fix all packages in a
workspace, aka those with path dependencies. Instead this commit switches cargo
over to only fixing the "primary" package, or those requested on the command
line or implicitly via cwd.

This will later help us identify which packages are being targeted so we can
provide tailored warnings and errors for mixed up transition steps.
2018-07-30 16:27:31 -07:00
bors af6e295d20 Auto merge of #5814 - alexcrichton:fix-all-targets, r=alexcrichton
cargo fix: Pass `--all-targets` to `cargo fix` by default

This'll help fix as much code as possible, including tests!

Closes #5739
2018-07-30 22:11:58 +00:00
Eh2406 86feda12fa cargo update can deal with some bad lockfiles 2018-07-30 12:12:04 -04:00
Alex Crichton ff8a95e296 fix: Pass --all-targets to cargo fix by default
This'll help fix as much code as possible, including tests!

Closes #5739
2018-07-27 08:54:40 -07:00
bors 03e89340f7 Auto merge of #5810 - Eh2406:test-fix, r=alexcrichton
now that we respect gitignore tests can be simplified

There are a lot of test that used a tempfile to avoid the fact that cargo would not init a git in the test folder. (or because they were copy/pasted from one that did.) Now that #5733 landed we can remove them all.
2018-07-27 03:51:35 +00:00
bors dab09a065b Auto merge of #5807 - dwijnand:cargo-list-summary, r=alexcrichton
Show the command summary when running cargo --list

Fixes #3726
2018-07-27 02:49:04 +00:00
bors 5a5bbc20cc Auto merge of #5801 - ehuss:fix-doctestable, r=alexcrichton
Fix `test --doc` with incompatible lib types.

When I recently changed the doctest handling, I forgot to check the lib type in
the `test --doc` scenario.

I also added the package name to a nearby error message, since it can be
confusing in a workspace setting.
2018-07-27 02:17:52 +00:00
Dale Wijnand 09cd53832c
Adapt --list output in find_closest_biuld_to_build test 2018-07-26 21:41:43 +01:00
Eh2406 7fc0dffed2 remove all of the (now) unnecessary temp file usage in tests 2018-07-26 15:10:48 -04:00
Eh2406 acf89e946c update test for #5733 2018-07-26 14:39:10 -04:00
Dale Wijnand 316622afd6
Test verbose error output for a bad lockfile 2018-07-26 17:14:08 +01:00
Dale Wijnand fcc3044e83
Suggest "update -p" to fix a bad lockfile 2018-07-26 17:12:09 +01:00
Without Boats 064a1461d7
Respect .gitignore during cargo new
When running `cargo new`, we check to see if you are inside a git
repository. If you are, we do not initialize a new git repo for
your project unless you specifically asked for it using --vcs.
(See #1210 for more background).

This commit changes that behavior to *also* create a new repo if
the project would be an ignored path in the parent repository.
This way, if your home directory is a git repository, as long as
you have ignored the directory you are creating a new project in,
we will instantiate a git repository without you having to
specifically request it.
2018-07-26 15:39:42 +02:00
Dale Wijnand a838f8fa9c
Fix read-manifest summary printing under cargo --list 2018-07-26 12:09:04 +01:00
Dale Wijnand af2c355585
Show the command summary when running cargo --list 2018-07-26 12:08:39 +01:00
Eric Huss dd6c6102a1 Fix test --doc with incompatible lib types.
When I recently changed the doctest handling, I forgot to check the lib type in
the `test --doc` scenario.

I also added the package name to a nearby error message, since it can be
confusing in a workspace setting.
2018-07-25 22:40:46 -07:00
bors 191bfbfaf2 Auto merge of #5794 - Nemo157:rustdoc-rename-extern, r=alexcrichton
Apply dependency renamings when running rustdoc

Fixes #5792
2018-07-26 00:36:42 +00:00
Wim Looman a432619806 Apply dependency renamings when running rustdoc
Fixes #5792
2018-07-25 18:58:28 +02:00
Dale Wijnand 6ca32be8a2
Declare one-line write_all contents on one line, too 2018-07-25 10:00:45 +01:00
Dale Wijnand ca7d9ee292
Declare one-line files on one line, in test projects 2018-07-25 09:58:50 +01:00
Dale Wijnand ab19c48358
Dedup a bunch more manifest 2018-07-25 00:43:30 +01:00
Dale Wijnand 5659b78b76
Replace const BASIC_MANIFEST with basic_manifest("foo", "0.0.1") 2018-07-24 23:35:50 +01:00
bors 4e53ce48d1 Auto merge of #5782 - dwijnand:dedup-manifest, r=alexcrichton
Add a default template for Cargo.toml

Fixes #5743

r? @alexcrichton
2018-07-24 20:47:57 +00:00
bors 5bb850141a Auto merge of #5621 - knight42:cargo-search-relaced-registry, r=alexcrichton
Update replaced registry before search

Close #5550.

It seems that updating the replaced registry before search has not been well considered in cargo and I have to add a function to trait `core::source::Source` to get the replaced `SourceId`.

I am not sure whether this is a good design, any advice is welcome.
2018-07-24 16:10:11 +00:00
Dale Wijnand 081e7930d2
Drop now unnecessary basic manifests 2018-07-24 16:33:55 +01:00
Dale Wijnand 252f6e8e9f
Opt-out all other failing tests
Looks like cargo traverses the filesystem & fails if it runs into a
Cargo.toml that doesn't declare a target.  I couldn't find a nice way to
re-engineer the test to avoid this issue.  So I'll leave that as someone
else's exercise.
2018-07-24 13:59:42 +01:00
Dale Wijnand d2c815be22
Add an opt-out to the auto-generated Cargo.toml 2018-07-24 13:19:47 +01:00
Dale Wijnand 2e6e5f880b
Insert a basic Cargo.toml if one is not defined. 2018-07-24 11:35:39 +01:00
Alex Crichton 6cdee674fc Don't warn about ignored files in cargo-fix
They're not being tracked, so no worries if we stomp over them!
2018-07-23 07:33:51 -07:00
knight42 7d279fe85c test: add test for replaced source 2018-07-23 09:35:27 +08:00