Don't require current package in resolve_ws

This commit is contained in:
Aleksey Kladov 2016-08-19 21:00:21 +03:00
parent 9f8c4691e4
commit a2f687a57b
3 changed files with 16 additions and 9 deletions

View file

@ -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
}
}

View file

@ -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)

View file

@ -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 ([..])