update contributing to show how to build the docs
The contributing guide referenced a script that was deleted in
1271bb4de0c0 so it wasn't possible to follow the contributing guide
successfully prior to contributing doc improvements.
When -v is passed with --list, display path to custom commands
With this change, output of `cargo --list` changes slightly when 1 or more `-v` flags are passed:
```
± ./target/debug/cargo --list -v
Installed Commands:
add /path/to/home/.cargo/bin/cargo-add
bench
build
canoe /path/to/home/.cargo/bin/cargo-canoe
check
clean
do /path/to/home/.cargo/bin/cargo-do
doc
fetch
fmt /path/to/home/.cargo/bin/cargo-fmt
...
```
Implement renaming dependencies in the manifest
This commit implements a new unstable feature for manifests which allows
renaming a crate when depending on it. For example you can do:
```toml
cargo-features = ["dependencies-as"]
...
[dependencies]
foo = "0.1"
bar = { version = "0.1", registry = "custom", package = "foo" }
baz = { git = "https://github.com/foo/bar", package = "foo" }
```
Here three crates will be imported but they'll be made available to the Rust
source code via the names `foo` (crates.io), `bar` (the custom registry), and
`baz` (the git dependency). The *package* name, however, will be `foo` for all
of them. In other words the git repository here would be searched for a crate
called `foo`. For example:
```rust
extern crate foo; // crates.io
extern crate bar; // registry `custom`
extern crate baz; // git repository
```
The intention here is to enable a few use cases:
* Enable depending on the same named crate from different registries
* Allow depending on multiple versions of a crate from one registry
* Removing the need for `extern crate foo as bar` syntactically in Rust source
Currently I don't think we're ready to stabilize this so it's just a nightly
feature, but I'm hoping we can continue to iterate on it!
cc #1311
doc: add explicit example with ^ and leading 0
Since the leading 0 is treated a bit special, its worth it to have an
explicit example to match the above example of the major version being >
0.
The contributing guide referenced a script that was deleted in
1271bb4de0c0 so it wasn't possible to follow the contributing guide
successfully prior to contributing doc improvements.
Conflict tracking
This is an alternative implementation of #4834. This is slower but hopefully more flexible and clearer. The idea is to keep a list of `PackageId`'s that have caused us to skip a `Candidate`. Then we can use the list when we are backtracking if any items in our list have not been activated then we will have new `Candidate`'s to try so we should stop backtracking. Or to say that another way; We can continue backtracking as long as all the items in our list is still activated.
Next this new framework was used to make the error messages more focused. We only need to list the versions that conflict, as opposed to all previously activated versions.
Why is this more flexible?
1. It is not limited to conflicts within the same package. If `RemainingCandidates.next` skips something because of a links attribute, that is easy to record, just add the `PackageId` to the set `conflicting_prev_active`.
2. Arbitrary things can add conflicts to the backtracking. If we fail to activate because some dependency needs a feature that does not exist, that is easy to record, just add the `PackageId` to the set `conflicting_activations`.
3. All things that could cause use to fail will be in the error messages, as the error messages loop over the set.
4. With a simple extension, replacing the `HashSet` with a `HashMap<_, Reason>`, we can customize the error messages to show the nature of the conflict.
@alexcrichton, @aidanhs, Does the logic look right? Does this seem clearer to you?
Fix DocOpt deserialization type bounds
This is wrt https://github.com/docopt/docopt.rs/pull/222
DocOpt does not support deserializing borrowed types.
This change was reverted in
7292a374e6
because it broke crates like Cargo etc.
New defaults to bin
So this switches `cargo new` default from `--lib` to `--bin`, as discussed on IRC.
The first two commits are just refactorings, and the last one actually flips the switch. Surprisingly enough, no tests need to be modified it seems!
r? @withoutboats
This commit implements a new unstable feature for manifests which allows
renaming a crate when depending on it. For example you can do:
```toml
cargo-features = ["dependencies-as"]
...
[dependencies]
foo = "0.1"
bar = { version = "0.1", registry = "custom", package = "foo" }
baz = { git = "https://github.com/foo/bar", package = "foo" }
```
Here three crates will be imported but they'll be made available to the Rust
source code via the names `foo` (crates.io), `bar` (the custom registry), and
`baz` (the git dependency). The *package* name, however, will be `foo` for all
of them. In other words the git repository here would be searched for a crate
called `foo`. For example:
```rust
extern crate foo; // crates.io
extern crate bar; // registry `custom`
extern crate baz; // git repository
```
The intention here is to enable a few use cases:
* Enable depending on the same named crate from different registries
* Allow depending on multiple versions of a crate from one registry
* Removing the need for `extern crate foo as bar` syntactically in Rust source
Currently I don't think we're ready to stabilize this so it's just a nightly
feature, but I'm hoping we can continue to iterate on it!
Switch to lazycell from crate.io
This switches from a home-grown implementation of `lazycell` to the one from crates.io.
There are no particularly large improvements here, but our own lazy cell is definitely unsafe in theory, because of potential reentrancy in `get_or_try_init`, and the one from crates.io does not have at least this hole :-)
Note that `rustc` already has `lazycell` in its Cargo.lock (because of clippy I guess?), albeit with a lower version, 0.5.
readme: add link to the cargo documentation on docs.rs
[Rendered](https://github.com/matthiaskrgr/cargo/blob/readme_docs/README.md)
Background: I was searching for cargo source code doc a while back, found the cargo book and crates.io doc relatively quickly but not the actual source code doc which I only found (after way to much time had passed) when I looked up the cargo crate on crates.io and found the "Documentation" link :/
Hope this improves the situation a bit in the future.
Don't spin on empty fds in `read2` on Unix
This commit fixes what I think is some pathological behavior in Cargo where if
one stdio stream is closed before another then Cargo can accidentally spin in a
tight loop and not block appropriately. Previously, for example, if stderr
closed before stdout then Cargo would spin in a `poll` loop continuously getting
notified that stderr is closed.
The behavior is now changed so after a file descriptor is done we stop passing
it to `poll` and instead only pass the one remaining readable file descriptor.
This commit fixes what I think is some pathological behavior in Cargo where if
one stdio stream is closed before another then Cargo can accidentally spin in a
tight loop and not block appropriately. Previously, for example, if stderr
closed before stdout then Cargo would spin in a `poll` loop continuously getting
notified that stderr is closed.
The behavior is now changed so after a file descriptor is done we stop passing
it to `poll` and instead only pass the one remaining readable file descriptor.
better resolver error messages
This is a start on beter resolver error messages. This is mostly trying to copy the `links` messages. In the process I found that we wor not testing the common case of having found candidates and still not resolving.
Any advice?
Add helpful message when running cargo doc --open
Add helpful message when running cargo doc --open in the root of the workspace.
closes#4962
old output:
```
Documenting foo v0.1.0 (file:///Users/marek/projects/ethcore/tmp/dupa/foo)
Documenting bar v0.1.0 (file:///Users/marek/projects/ethcore/tmp/dupa/bar)
Finished dev [unoptimized + debuginfo] target(s) in 0.78 secs
error: Passing multiple packages and `open` is not supported
```
new output:
```
Documenting foo v0.1.0 (file:///Users/marek/projects/ethcore/tmp/dupa/foo)
Documenting bar v0.1.0 (file:///Users/marek/projects/ethcore/tmp/dupa/bar)
Finished dev [unoptimized + debuginfo] target(s) in 0.81 secs
error: Passing multiple packages and `open` is not supported.
Please re-run this command with `-p <spec>` where `<spec>` is one of the following:
foo
bar
```
apply clippy suggestions
I want to try if this actually works =)
There are many other clippy suggestions. I wonder if I can take them for granted or if some of them would be refused.
For example:
```
warning: Constants have by default a `'static` lifetime
--> src/cargo/lib.rs:53:23
|
53 | pub const CARGO_ENV: &'static str = "CARGO";
| -^^^^^^^---- help: consider removing `'static`: `&str`
|
= note: #[warn(const_static_lifetime)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.185/index.html#const_static_lifetime
```
Make resolution backtracking smarter
There's no need to try every candidate for every dependency when backtracking - instead, only try candidates if they *could* change the eventual failure that caused backtracking in the first place, i.e.
1. if we've backtracked past the parent of the dep that failed
2. the number of activations for the dep has changed (activations are only ever added during resolution I believe)
The two new tests before:
```
$ /usr/bin/time cargo test --test resolve -- --test-threads 1 --nocapture resolving_with_constrained_sibling_
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
Running target/debug/deps/resolve-19b2a13e5a19eed8
38.45user 2.16system 0:42.00elapsed 96%CPU (0avgtext+0avgdata 47672maxresident)k
0inputs+1664096outputs (0major+10921minor)pagefaults 0swaps
```
After:
```
$ /usr/bin/time cargo test --test resolve -- --test-threads 1 --nocapture resolving_with_constrained_sibling_
Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
Running target/debug/deps/resolve-19b2a13e5a19eed8
[...]
0.36user 0.01system 0:00.49elapsed 76%CPU (0avgtext+0avgdata 47464maxresident)k
0inputs+32outputs (0major+11602minor)pagefaults 0swaps
```
You observe the issue yourself with the following (it should fail, but hangs for a while instead - I didn't bother timing it and waiting for it to finish. With this PR it terminates almost instantly):
```
$ cargo new --bin x
Created binary (application) `x` project
$ /bin/echo -e 'serde = "=1.0.9"\nrust-s3 = "0.8"' >> x/Cargo.toml
$ cd x && cargo build
Updating registry `https://github.com/rust-lang/crates.io-index`
Resolving dependency graph...
```
Do not rename packages on `cargo new`.
Prior to this commit, packages beginning with `rust` or ending with
`rs` were renamed automatically when created, unless they were
binaries. The ostensible purpose of this code was to avoid people
uploading "redundant" names to crates.io, which is a repository of
Rust packages.
This behavior was overly opinionated. It is not cargo's
responsibility to discourage users from naming their packages any
particular way. Without a sound technical reasons why packages
cannot be named a certain way, cargo should not be intervening in
users' package naming decisions.
It also did this by automatically renaming the package for the
user, as opposed to erroring. Though it printed a message about
the behavior, it did not give the user a choice to abort the
process; to overrule cargo they had to delete the new project
and start again using the `--name` argument.
`cargo new` is many users' first entrypoint to the Rust ecosystem.
This behavior teaches a user that Rust is opinionated and magical,
both of which are divisive attributes for a tool, and attributes
which do not generally describe Rust's attitude toward things like
names and formatting.
If crates.io wishes to enforce that users not upload packages with
names like this, it should be enforced by crates.io at publish
time.