From: Alex Crichton Date: Wed, 5 Nov 2014 02:56:08 +0000 (-0800) Subject: Move generated tarballs under target/package X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=291c7747630622761dc90b9b5d0839e636709154;p=cargo.git Move generated tarballs under target/package At the same time this commit renames the `.tar.gz` extension to `.crate`. This helps our perception on Windows as we're not trying to leave them out in the dark, and we'd also like the ability to modify the format later in the future. Closes #777 --- diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index bd9599279..b2034d6a2 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -433,6 +433,10 @@ impl Manifest { pub fn set_summary(&mut self, summary: Summary) { self.summary = summary; } + + pub fn set_target_dir(&mut self, target_dir: Path) { + self.target_dir = target_dir; + } } impl Target { diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 99444fdab..807e0166b 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -1,4 +1,4 @@ -use std::io::{fs, File}; +use std::io::{fs, File, USER_DIR}; use std::io::fs::PathExtensions; use std::path; @@ -30,8 +30,9 @@ pub fn package(manifest_path: &Path, try!(src.update()); let pkg = try!(src.get_root_package()); - let filename = format!("{}-{}.tar.gz", pkg.get_name(), pkg.get_version()); - let dst = pkg.get_manifest_path().dir_path().join(filename); + let filename = format!("package/{}-{}.crate", pkg.get_name(), + pkg.get_version()); + let dst = pkg.get_absolute_target_dir().join(filename); if dst.exists() { return Ok(dst) } let mut bomb = Bomb { path: Some(dst.clone()) }; @@ -55,6 +56,9 @@ fn tar(pkg: &Package, src: &PathSource, shell: &mut MultiShell, return Err(human(format!("destination already exists: {}", dst.display()))) } + + try!(fs::mkdir_recursive(&dst.dir_path(), USER_DIR)) + let tmpfile = try!(File::create(dst)); // Prepare the encoder and its header @@ -63,9 +67,10 @@ fn tar(pkg: &Package, src: &PathSource, shell: &mut MultiShell, // Put all package files into a compressed archive let ar = Archive::new(encoder); + let root = pkg.get_manifest_path().dir_path(); for file in try!(src.list_files(pkg)).iter() { if file == dst { continue } - let relative = file.path_relative_from(&dst.dir_path()).unwrap(); + let relative = file.path_relative_from(&root).unwrap(); let relative = try!(relative.as_str().require(|| { human(format!("non-utf8 path in source directory: {}", relative.display())) @@ -89,14 +94,14 @@ fn run_verify(pkg: &Package, shell: &mut MultiShell, tar: &Path) try!(shell.status("Verifying", pkg)); let f = try!(GzDecoder::new(try!(File::open(tar)))); - let dst = pkg.get_root().join("target/package"); + let dst = pkg.get_root().join(format!("target/package/{}-{}", + pkg.get_name(), pkg.get_version())); if dst.exists() { try!(fs::rmdir_recursive(&dst)); } let mut archive = Archive::new(f); - try!(archive.unpack(&dst)); - let manifest_path = dst.join(format!("{}-{}/Cargo.toml", pkg.get_name(), - pkg.get_version())); + try!(archive.unpack(&dst.dir_path())); + let manifest_path = dst.join("Cargo.toml"); // When packages are uploaded to the registry, all path dependencies are // implicitly converted to registry-based dependencies, so we rewrite those @@ -108,8 +113,7 @@ fn run_verify(pkg: &Package, shell: &mut MultiShell, tar: &Path) }); let mut new_manifest = pkg.get_manifest().clone(); new_manifest.set_summary(new_summary); - let new_pkg = Package::new(new_manifest, - &manifest_path, + let new_pkg = Package::new(new_manifest, &manifest_path, pkg.get_package_id().get_source_id()); // Now that we've rewritten all our path dependencies, compile it! diff --git a/src/cargo/sources/registry.rs b/src/cargo/sources/registry.rs index e762d9feb..886fcbee6 100644 --- a/src/cargo/sources/registry.rs +++ b/src/cargo/sources/registry.rs @@ -147,7 +147,7 @@ //! # This folder is a cache for all downloaded tarballs from a registry. //! # Once downloaded and verified, a tarball never changes. //! cache/ -//! registry1-/-.tar.gz +//! registry1-/-.crate //! ... //! //! # Location in which all tarballs are unpacked. Each tarball is known to @@ -296,7 +296,7 @@ impl<'a, 'b> RegistrySource<'a, 'b> { fn download_package(&mut self, pkg: &PackageId, url: &Url) -> CargoResult { // TODO: should discover from the S3 redirect - let filename = format!("{}-{}.tar.gz", pkg.get_name(), pkg.get_version()); + let filename = format!("{}-{}.crate", pkg.get_name(), pkg.get_version()); let dst = self.cache_path.join(filename); if dst.exists() { return Ok(dst) } try!(self.config.shell().status("Downloading", pkg)); diff --git a/tests/test_cargo_package.rs b/tests/test_cargo_package.rs index cc5776c9d..d1a9da43d 100644 --- a/tests/test_cargo_package.rs +++ b/tests/test_cargo_package.rs @@ -34,11 +34,11 @@ test!(simple { verifying = VERIFYING, compiling = COMPILING, dir = p.url()).as_slice())); - assert_that(&p.root().join("foo-0.0.1.tar.gz"), existing_file()); + assert_that(&p.root().join("target/package/foo-0.0.1.crate"), existing_file()); assert_that(p.process(cargo_dir().join("cargo")).arg("package"), execs().with_status(0).with_stdout("")); - let f = File::open(&p.root().join("foo-0.0.1.tar.gz")).assert(); + let f = File::open(&p.root().join("target/package/foo-0.0.1.crate")).assert(); let mut rdr = GzDecoder::new(f); let contents = rdr.read_to_end().assert(); let ar = Archive::new(MemReader::new(contents)); diff --git a/tests/test_cargo_publish.rs b/tests/test_cargo_publish.rs index bf291d6fb..9ab09a23f 100644 --- a/tests/test_cargo_publish.rs +++ b/tests/test_cargo_publish.rs @@ -63,7 +63,7 @@ test!(simple { // Verify the tarball let mut rdr = GzDecoder::new(f).unwrap(); - assert_eq!(rdr.header().filename(), Some(b"foo-0.0.1.tar.gz")); + assert_eq!(rdr.header().filename(), Some(b"foo-0.0.1.crate")); let inner = MemReader::new(rdr.read_to_end().unwrap()); let ar = Archive::new(inner); for file in ar.files().unwrap() { diff --git a/tests/test_cargo_registry.rs b/tests/test_cargo_registry.rs index 596764b26..992b40a03 100644 --- a/tests/test_cargo_registry.rs +++ b/tests/test_cargo_registry.rs @@ -209,7 +209,7 @@ version required: ^0.0.1 {updating} registry `[..]` {downloading} notyet v0.0.1 (the package registry) {compiling} notyet v0.0.1 (the package registry) -{compiling} foo v0.0.1 ({dir}) +{compiling} foo v0.0.1 ({dir}[..]) ", packaging = PACKAGING, verifying = VERIFYING,