]> git.proxmox.com Git - cargo.git/commitdiff
Move generated tarballs under target/package
authorAlex Crichton <alex@alexcrichton.com>
Wed, 5 Nov 2014 02:56:08 +0000 (18:56 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 5 Nov 2014 19:40:15 +0000 (11:40 -0800)
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

src/cargo/core/manifest.rs
src/cargo/ops/cargo_package.rs
src/cargo/sources/registry.rs
tests/test_cargo_package.rs
tests/test_cargo_publish.rs
tests/test_cargo_registry.rs

index bd95992796c6e20738f589be58e97f5121d0ff4c..b2034d6a28041fa2c0301e745831411745c7dc1b 100644 (file)
@@ -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 {
index 99444fdabb4350eef6c370325f2c29c7fb521822..807e0166bd810d7fb41da3424b9a55900131c022 100644 (file)
@@ -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!
index e762d9feb4962356f3a54f27c20500cb49f1c2d2..886fcbee6f7121f25f19b3a16a06439fdf86e4b6 100644 (file)
 //!     # This folder is a cache for all downloaded tarballs from a registry.
 //!     # Once downloaded and verified, a tarball never changes.
 //!     cache/
-//!         registry1-<hash>/<pkg>-<version>.tar.gz
+//!         registry1-<hash>/<pkg>-<version>.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<Path> {
         // 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));
index cc5776c9d33ccdfd2e27a09c73479ada73d8ae42..d1a9da43df5d645f274b7135fe8471ce7157a66e 100644 (file)
@@ -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));
index bf291d6fbf8965e33f42da50855e1c5d97678ede..9ab09a23fe9f458daffe16523da1df2b306b6f2e 100644 (file)
@@ -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() {
index 596764b26a3816410f30ccd8e66cea59b9a2dd09..992b40a03f7ee003605b86e3a8d3071bfd62a372 100644 (file)
@@ -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,