mirror of
https://github.com/rust-lang/cargo
synced 2024-10-01 05:23:56 +00:00
Use a hash for -C metadata instead of a string
This ends up serving the same purpose, but a critical change is that it canonicalizes the relevant git url (if one is used) to ensure that the same package from two slightly different locations is always built the same way. Sadly I'm not quite sure how to add a test for this as it involves using remote git urls which are unusable during tests.
This commit is contained in:
parent
c3f9f9e700
commit
5dc5381fcc
|
@ -118,11 +118,11 @@ impl PackageId {
|
|||
}
|
||||
|
||||
pub fn generate_metadata(&self) -> Metadata {
|
||||
let metadata = format!("{}:-:{}:-:{}", self.name, self.version, self.source_id);
|
||||
let extra_filename = short_hash(
|
||||
let metadata = short_hash(
|
||||
&(self.name.as_slice(), self.version.to_string(), &self.source_id));
|
||||
let extra_filename = format!("-{}", metadata);
|
||||
|
||||
Metadata { metadata: metadata, extra_filename: format!("-{}", extra_filename) }
|
||||
Metadata { metadata: metadata, extra_filename: extra_filename }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ pub fn prepare(cx: &mut Context, pkg: &Package,
|
|||
fn is_fresh(dep: &Package, loc: &Path, cx: &mut Context, targets: &[&Target])
|
||||
-> CargoResult<(bool, String)> {
|
||||
let new_pkg_fingerprint = format!("{}{}", cx.rustc_version,
|
||||
try!(dep.get_fingerprint(cx.config)));
|
||||
try!(dep.get_fingerprint(cx.config)));
|
||||
|
||||
let new_fingerprint = fingerprint(new_pkg_fingerprint, hash_targets(targets));
|
||||
|
||||
|
|
|
@ -990,12 +990,12 @@ test!(verbose_build {
|
|||
let output = p.cargo_process("cargo-build").arg("-v")
|
||||
.exec_with_output().assert();
|
||||
let out = str::from_utf8(output.output.as_slice()).assert();
|
||||
let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 15);
|
||||
let hash = hash.slice_to(17);
|
||||
let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 16);
|
||||
let hash = hash.slice_to(16);
|
||||
assert_eq!(out, format!("\
|
||||
{} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
|
||||
-C metadata=test:-:0.0.0:-:file:{dir} \
|
||||
-C extra-filename={hash} \
|
||||
-C metadata={hash} \
|
||||
-C extra-filename=-{hash} \
|
||||
--out-dir {dir}{sep}target \
|
||||
-L {dir}{sep}target \
|
||||
-L {dir}{sep}target{sep}deps`
|
||||
|
@ -1020,14 +1020,14 @@ test!(verbose_release_build {
|
|||
let output = p.cargo_process("cargo-build").arg("-v").arg("--release")
|
||||
.exec_with_output().assert();
|
||||
let out = str::from_utf8(output.output.as_slice()).assert();
|
||||
let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 15);
|
||||
let hash = hash.slice_to(17);
|
||||
let hash = out.slice_from(out.find_str("extra-filename=").unwrap() + 16);
|
||||
let hash = hash.slice_to(16);
|
||||
assert_eq!(out, format!("\
|
||||
{} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
|
||||
--opt-level 3 \
|
||||
--cfg ndebug \
|
||||
-C metadata=test:-:0.0.0:-:file:{dir} \
|
||||
-C extra-filename={hash} \
|
||||
-C metadata={hash} \
|
||||
-C extra-filename=-{hash} \
|
||||
--out-dir {dir}{sep}target{sep}release \
|
||||
-L {dir}{sep}target{sep}release \
|
||||
-L {dir}{sep}target{sep}release{sep}deps`
|
||||
|
@ -1068,30 +1068,30 @@ test!(verbose_release_build_deps {
|
|||
.exec_with_output().assert();
|
||||
let out = str::from_utf8(output.output.as_slice()).assert();
|
||||
let pos1 = out.find_str("extra-filename=").unwrap();
|
||||
let hash1 = out.slice_from(pos1 + 15).slice_to(17);
|
||||
let hash1 = out.slice_from(pos1 + 16).slice_to(16);
|
||||
let pos2 = out.slice_from(pos1 + 10).find_str("extra-filename=").unwrap();
|
||||
let hash2 = out.slice_from(pos1 + 10 + pos2 + 15).slice_to(17);
|
||||
let hash2 = out.slice_from(pos1 + 10 + pos2 + 16).slice_to(16);
|
||||
assert_eq!(out, format!("\
|
||||
{running} `rustc {dir}{sep}foo{sep}src{sep}lib.rs --crate-name foo \
|
||||
--crate-type dylib --crate-type rlib \
|
||||
--opt-level 3 \
|
||||
--cfg ndebug \
|
||||
-C metadata=foo:-:0.0.0:-:file:{dir} \
|
||||
-C extra-filename={hash1} \
|
||||
-C metadata={hash1} \
|
||||
-C extra-filename=-{hash1} \
|
||||
--out-dir {dir}{sep}target{sep}release{sep}deps \
|
||||
-L {dir}{sep}target{sep}release{sep}deps \
|
||||
-L {dir}{sep}target{sep}release{sep}deps`
|
||||
{running} `rustc {dir}{sep}src{sep}lib.rs --crate-name test --crate-type lib \
|
||||
--opt-level 3 \
|
||||
--cfg ndebug \
|
||||
-C metadata=test:-:0.0.0:-:file:{dir} \
|
||||
-C extra-filename={hash2} \
|
||||
-C metadata={hash2} \
|
||||
-C extra-filename=-{hash2} \
|
||||
--out-dir {dir}{sep}target{sep}release \
|
||||
-L {dir}{sep}target{sep}release \
|
||||
-L {dir}{sep}target{sep}release{sep}deps \
|
||||
--extern foo={dir}{sep}target{sep}release{sep}deps/\
|
||||
{prefix}foo{hash1}{suffix} \
|
||||
--extern foo={dir}{sep}target{sep}release{sep}deps/libfoo{hash1}.rlib`
|
||||
{prefix}foo-{hash1}{suffix} \
|
||||
--extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-{hash1}.rlib`
|
||||
{compiling} foo v0.0.0 (file:{dir})
|
||||
{compiling} test v0.0.0 (file:{dir})\n",
|
||||
running = RUNNING,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::io::{File, TempDir};
|
||||
use std::io::File;
|
||||
|
||||
use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths};
|
||||
use support::{cargo_dir};
|
||||
|
|
Loading…
Reference in a new issue