From f51a2f923409176420b84611176a059d03d9ffce Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 6 Aug 2014 13:54:24 -0700 Subject: [PATCH] Remove the update_remotes flag entirely This will inadvertently fix #337 as no lockfile will imply that all dependencies are not precise, and will hence be fetched. --- src/bin/cargo-generate-lockfile.rs | 2 +- src/bin/cargo-git-checkout.rs | 2 +- src/cargo/ops/cargo_compile.rs | 6 +-- src/cargo/ops/cargo_generate_lockfile.rs | 7 ++- src/cargo/sources/git/source.rs | 3 +- src/cargo/util/config.rs | 7 --- tests/test_cargo_compile_git_deps.rs | 68 +++++++++++++++++++++++- 7 files changed, 77 insertions(+), 18 deletions(-) diff --git a/src/bin/cargo-generate-lockfile.rs b/src/bin/cargo-generate-lockfile.rs index d15cb22aa..19304abc1 100644 --- a/src/bin/cargo-generate-lockfile.rs +++ b/src/bin/cargo-generate-lockfile.rs @@ -34,6 +34,6 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult> { shell.set_verbose(options.flag_verbose); let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); - ops::generate_lockfile(&root, shell, true) + ops::generate_lockfile(&root, shell) .map(|_| None).map_err(|err| CliError::from_boxed(err, 101)) } diff --git a/src/bin/cargo-git-checkout.rs b/src/bin/cargo-git-checkout.rs index 8994e840b..14a58eda1 100644 --- a/src/bin/cargo-git-checkout.rs +++ b/src/bin/cargo-git-checkout.rs @@ -38,7 +38,7 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult> { let source_id = SourceId::for_git(&url, reference.as_slice(), None); - let mut config = try!(Config::new(shell, true, None, None).map_err(|e| { + let mut config = try!(Config::new(shell, None, None).map_err(|e| { CliError::from_boxed(e, 1) })); let mut source = GitSource::new(&source_id, &mut config); diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index c0effe7d2..5bb076a35 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -52,7 +52,7 @@ pub fn compile(manifest_path: &Path, log!(4, "compile; manifest-path={}", manifest_path.display()); - if options.update { + if update { return Err(human("The -u flag has been deprecated, please use the \ `cargo update` command instead")); } @@ -77,7 +77,7 @@ pub fn compile(manifest_path: &Path, let lockfile = manifest_path.dir_path().join("Cargo.lock"); let source_id = package.get_package_id().get_source_id(); - let mut config = try!(Config::new(*shell, update, jobs, target.clone())); + let mut config = try!(Config::new(*shell, jobs, target.clone())); let mut registry = PackageRegistry::new(&mut config); match try!(ops::load_lockfile(&lockfile, source_id)) { @@ -117,7 +117,7 @@ pub fn compile(manifest_path: &Path, let ret = { let _p = profile::start("compiling"); - let mut config = try!(Config::new(*shell, update, jobs, target)); + let mut config = try!(Config::new(*shell, jobs, target)); try!(scrape_target_config(&mut config, &user_configs)); try!(ops::compile_targets(env.as_slice(), targets.as_slice(), &package, diff --git a/src/cargo/ops/cargo_generate_lockfile.rs b/src/cargo/ops/cargo_generate_lockfile.rs index 2851da52f..ced7788ee 100644 --- a/src/cargo/ops/cargo_generate_lockfile.rs +++ b/src/cargo/ops/cargo_generate_lockfile.rs @@ -15,8 +15,7 @@ use util::{CargoResult, human}; use cargo_toml = util::toml; pub fn generate_lockfile(manifest_path: &Path, - shell: &mut MultiShell, - update: bool) + shell: &mut MultiShell) -> CargoResult<()> { log!(4, "compile; manifest-path={}", manifest_path.display()); @@ -31,7 +30,7 @@ pub fn generate_lockfile(manifest_path: &Path, let source_ids = package.get_source_ids(); let resolve = { - let mut config = try!(Config::new(shell, update, None, None)); + let mut config = try!(Config::new(shell, None, None)); let mut registry = PackageRegistry::new(&mut config); try!(registry.add_sources(source_ids)); @@ -58,7 +57,7 @@ pub fn update_lockfile(manifest_path: &Path, None => return Err(human("A Cargo.lock must exist before it is updated")) }; - let mut config = try!(Config::new(shell, true, None, None)); + let mut config = try!(Config::new(shell, None, None)); let mut registry = PackageRegistry::new(&mut config); let sources = match to_update { diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index 743a2c391..0fa87f2bb 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -159,7 +159,8 @@ impl<'a, 'b> Source for GitSource<'a, 'b> { fn update(&mut self) -> CargoResult<()> { let actual_rev = self.remote.rev_for(&self.db_path, self.reference.as_slice()); - let should_update = self.config.update_remotes() || actual_rev.is_err(); + let should_update = actual_rev.is_err() || + self.source_id.precise.is_none(); let (repo, actual_rev) = if should_update { try!(self.config.shell().status("Updating", diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 4ed519ab1..9878fe29e 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -9,7 +9,6 @@ use cargo_toml = util::toml; pub struct Config<'a> { home_path: Path, - update_remotes: bool, shell: &'a mut MultiShell, jobs: uint, target: Option, @@ -19,7 +18,6 @@ pub struct Config<'a> { impl<'a> Config<'a> { pub fn new<'a>(shell: &'a mut MultiShell, - update_remotes: bool, jobs: Option, target: Option) -> CargoResult> { if jobs == Some(0) { @@ -30,7 +28,6 @@ impl<'a> Config<'a> { human("Cargo couldn't find your home directory. \ This probably means that $HOME was not set.") })), - update_remotes: update_remotes, shell: shell, jobs: jobs.unwrap_or(os::num_cpus()), target: target, @@ -53,10 +50,6 @@ impl<'a> Config<'a> { &mut *self.shell } - pub fn update_remotes(&mut self) -> bool { - self.update_remotes - } - pub fn jobs(&self) -> uint { self.jobs } diff --git a/tests/test_cargo_compile_git_deps.rs b/tests/test_cargo_compile_git_deps.rs index 88c9ca6c2..ed7c38ef9 100644 --- a/tests/test_cargo_compile_git_deps.rs +++ b/tests/test_cargo_compile_git_deps.rs @@ -665,7 +665,7 @@ test!(update_with_shared_deps { git_project.url()))); // Make sure we still only compile one version of the git repo - assert_that(p.cargo_process("cargo-build"), + assert_that(p.process(cargo_dir().join("cargo-build")), execs().with_stdout(format!("\ {compiling} bar v0.5.0 ({git}#[..]) {compiling} [..] v0.5.0 ({dir}) @@ -727,3 +727,69 @@ test!(dep_with_submodule { COMPILING, root)) .with_stderr("")); }) + +test!(two_deps_only_update_one { + let project = project("foo"); + let git1 = git_repo("dep1", |project| { + project + .file("Cargo.toml", r#" + [package] + name = "dep1" + version = "0.5.0" + authors = ["carlhuda@example.com"] + "#) + .file("src/lib.rs", "") + }).assert(); + let git2 = git_repo("dep2", |project| { + project + .file("Cargo.toml", r#" + [package] + name = "dep2" + version = "0.5.0" + authors = ["carlhuda@example.com"] + "#) + .file("src/lib.rs", "") + }).assert(); + + let project = project + .file("Cargo.toml", format!(r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [dependencies.dep1] + git = '{}' + [dependencies.dep2] + git = '{}' + "#, git1.url(), git2.url())) + .file("src/main.rs", "fn main() {}"); + + assert_that(project.cargo_process("cargo-build"), + execs() + .with_stdout(format!("{} git repository `[..]`\n\ + {} git repository `[..]`\n\ + {} [..] v0.5.0 ([..])\n\ + {} [..] v0.5.0 ([..])\n\ + {} foo v0.5.0 ({})\n", + UPDATING, + UPDATING, + COMPILING, + COMPILING, + COMPILING, project.url())) + .with_stderr("")); + + File::create(&git1.root().join("src/lib.rs")).write_str(r#" + pub fn foo() {} + "#).assert(); + git1.process("git").args(["add", "."]).exec_with_output().assert(); + git1.process("git").args(["commit", "-m", "test"]).exec_with_output() + .assert(); + + assert_that(project.process(cargo_dir().join("cargo-update")).arg("dep1"), + execs() + .with_stdout(format!("{} git repository `{}`\n", + UPDATING, git1.url())) + .with_stderr("")); +})