Fix testing bins with lib deps

If a package had both bin and lib deps, `cargo test` was not building the `lib`
dependency when building the bins with `--test`. This commit adds an extra
"test" profile (not compiled with --test) for situations such as this which is
filtered out normally but kept around for the `cargo test` case.
Fix --release not compiling upstream deps with -O3

This touches up the filtering logic to ensure that upstream dependencies as well
as local dependencies are built with optimizations when `cargo build --release`
is used.
Disable passing -g for now
Resolve more correctly and add --extern

This commit adds support for passing --extern to dependencies. It allows
multiple copies of the same named dependency in the system, as long as
they come from different repos.
Fixed a number of bugs related to rustc building

Most notably, `resolve` now takes the root, so it can properly link the
root package with its dependencies (which is required to build the
--externs for the root package).
Add some unit tests
auto merge of #157 : rust-lang/cargo/graph-resolve, r=alexcrichton

This incorporates previous bugfixes by @alexcrichton that are still stuck in bors.