mirror of
https://github.com/rust-lang/cargo
synced 2024-10-14 03:32:39 +00:00
Don't require current package in resolve_ws
This commit is contained in:
parent
9f8c4691e4
commit
a2f687a57b
|
@ -6,7 +6,7 @@ use std::slice;
|
|||
use core::{Package, VirtualManifest, EitherManifest, SourceId};
|
||||
use core::{PackageIdSpec, Dependency};
|
||||
use ops;
|
||||
use util::{Config, CargoResult, Filesystem};
|
||||
use util::{Config, CargoResult, Filesystem, human};
|
||||
use util::paths;
|
||||
|
||||
/// The core abstraction in Cargo for working with a workspace of crates.
|
||||
|
@ -143,13 +143,17 @@ impl<'cfg> Workspace<'cfg> {
|
|||
/// actually a "virtual Cargo.toml", in which case an error is returned
|
||||
/// indicating that something else should be passed.
|
||||
pub fn current(&self) -> CargoResult<&Package> {
|
||||
self.current_opt().ok_or_else(||
|
||||
human(format!("manifest path `{}` is a virtual manifest, but this \
|
||||
command requires running against an actual package in \
|
||||
this workspace", self.current_manifest.display()))
|
||||
)
|
||||
}
|
||||
|
||||
pub fn current_opt(&self) -> Option<&Package> {
|
||||
match *self.packages.get(&self.current_manifest) {
|
||||
MaybePackage::Package(ref p) => Ok(p),
|
||||
MaybePackage::Virtual(..) => {
|
||||
bail!("manifest path `{}` is a virtual manifest, but this \
|
||||
command requires running against an actual package in \
|
||||
this workspace", self.current_manifest.display())
|
||||
}
|
||||
MaybePackage::Package(ref p) => Some(p),
|
||||
MaybePackage::Virtual(..) => None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,9 @@ pub fn resolve_ws(registry: &mut PackageRegistry, ws: &Workspace)
|
|||
let resolve = try!(resolve_with_previous(registry, ws,
|
||||
Method::Everything,
|
||||
prev.as_ref(), None));
|
||||
if try!(ws.current()).package_id().source_id().is_path() {
|
||||
|
||||
// Avoid writing a lockfile if we are `cargo install`ing a non local package.
|
||||
if ws.current_opt().map(|pkg| pkg.package_id().source_id().is_path()).unwrap_or(true) {
|
||||
try!(ops::write_pkg_lockfile(ws, &resolve));
|
||||
}
|
||||
Ok(resolve)
|
||||
|
|
|
@ -555,7 +555,8 @@ fn git_repo() {
|
|||
.file("src/main.rs", "fn main() {}");
|
||||
p.build();
|
||||
|
||||
assert_that(cargo_process("install").arg("--git").arg(p.url().to_string()),
|
||||
// use `--locked` to test that we don't even try to write a lockfile
|
||||
assert_that(cargo_process("install").arg("--locked").arg("--git").arg(p.url().to_string()),
|
||||
execs().with_status(0).with_stderr(&format!("\
|
||||
[UPDATING] git repository `[..]`
|
||||
[COMPILING] foo v0.1.0 ([..])
|
||||
|
|
Loading…
Reference in a new issue