Skip to content

Commit

Permalink
Auto merge of #3310 - alexcrichton:more-metadata-hashing, r=brson
Browse files Browse the repository at this point in the history
Apply new fingerprinting to build dir outputs

We now much more aggressively cache the output of the compiler based on feature
sets and profile configuration. Unfortunately we forgot to extend this caching
to build script output directories as well so this commit ensures that build
script outputs are cached the same way with a directory per configuration of
features and output settings.

Closes #3302
  • Loading branch information
bors committed Dec 2, 2016
2 parents 33d20b4 + 41579ba commit c82fd7f
Show file tree
Hide file tree
Showing 13 changed files with 217 additions and 263 deletions.
27 changes: 7 additions & 20 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustc_serialize::{Encoder, Encodable};

use core::{Dependency, PackageId, Summary, SourceId, PackageIdSpec};
use core::WorkspaceConfig;
use core::package_id::Metadata;

pub enum EitherManifest {
Real(Manifest),
Expand Down Expand Up @@ -159,7 +158,6 @@ pub struct Target {
kind: TargetKind,
name: String,
src_path: PathBuf,
metadata: Option<Metadata>,
tested: bool,
benched: bool,
doc: bool,
Expand Down Expand Up @@ -279,7 +277,6 @@ impl Target {
kind: TargetKind::Bin,
name: String::new(),
src_path: PathBuf::new(),
metadata: None,
doc: false,
doctest: false,
harness: true,
Expand All @@ -289,40 +286,35 @@ impl Target {
}
}

pub fn lib_target(name: &str, crate_targets: Vec<LibKind>,
src_path: &Path,
metadata: Metadata) -> Target {
pub fn lib_target(name: &str,
crate_targets: Vec<LibKind>,
src_path: &Path) -> Target {
Target {
kind: TargetKind::Lib(crate_targets),
name: name.to_string(),
src_path: src_path.to_path_buf(),
metadata: Some(metadata),
doctest: true,
doc: true,
..Target::blank()
}
}

pub fn bin_target(name: &str, src_path: &Path,
metadata: Option<Metadata>) -> Target {
pub fn bin_target(name: &str, src_path: &Path) -> Target {
Target {
kind: TargetKind::Bin,
name: name.to_string(),
src_path: src_path.to_path_buf(),
metadata: metadata,
doc: true,
..Target::blank()
}
}

/// Builds a `Target` corresponding to the `build = "build.rs"` entry.
pub fn custom_build_target(name: &str, src_path: &Path,
metadata: Option<Metadata>) -> Target {
pub fn custom_build_target(name: &str, src_path: &Path) -> Target {
Target {
kind: TargetKind::CustomBuild,
name: name.to_string(),
src_path: src_path.to_path_buf(),
metadata: metadata,
for_host: true,
benched: false,
tested: false,
Expand All @@ -340,25 +332,21 @@ impl Target {
}
}

pub fn test_target(name: &str, src_path: &Path,
metadata: Metadata) -> Target {
pub fn test_target(name: &str, src_path: &Path) -> Target {
Target {
kind: TargetKind::Test,
name: name.to_string(),
src_path: src_path.to_path_buf(),
metadata: Some(metadata),
benched: false,
..Target::blank()
}
}

pub fn bench_target(name: &str, src_path: &Path,
metadata: Metadata) -> Target {
pub fn bench_target(name: &str, src_path: &Path) -> Target {
Target {
kind: TargetKind::Bench,
name: name.to_string(),
src_path: src_path.to_path_buf(),
metadata: Some(metadata),
tested: false,
..Target::blank()
}
Expand All @@ -367,7 +355,6 @@ impl Target {
pub fn name(&self) -> &str { &self.name }
pub fn crate_name(&self) -> String { self.name.replace("-", "_") }
pub fn src_path(&self) -> &Path { &self.src_path }
pub fn metadata(&self) -> Option<&Metadata> { self.metadata.as_ref() }
pub fn kind(&self) -> &TargetKind { &self.kind }
pub fn tested(&self) -> bool { self.tested }
pub fn harness(&self) -> bool { self.harness }
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub use self::dependency::{Dependency, DependencyInner};
pub use self::manifest::{Manifest, Target, TargetKind, Profile, LibKind, Profiles};
pub use self::manifest::{EitherManifest, VirtualManifest};
pub use self::package::{Package, PackageSet};
pub use self::package_id::{PackageId, Metadata};
pub use self::package_id::PackageId;
pub use self::package_id_spec::PackageIdSpec;
pub use self::registry::Registry;
pub use self::resolver::Resolve;
Expand Down
6 changes: 1 addition & 5 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf};
use semver::Version;

use core::{Dependency, Manifest, PackageId, SourceId, Target, TargetKind};
use core::{Summary, Metadata, SourceMap};
use core::{Summary, SourceMap};
use ops;
use util::{CargoResult, Config, LazyCell, ChainError, internal, human, lev_distance};
use rustc_serialize::{Encoder,Encodable};
Expand Down Expand Up @@ -94,10 +94,6 @@ impl Package {
self.targets().iter().any(|t| t.is_custom_build())
}

pub fn generate_metadata(&self) -> Metadata {
self.package_id().generate_metadata()
}

pub fn find_closest_target(&self, target: &str, kind: TargetKind) -> Option<&Target> {
let targets = self.targets();

Expand Down
23 changes: 1 addition & 22 deletions src/cargo/core/package_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use regex::Regex;
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
use semver;

use util::{CargoResult, CargoError, short_hash, ToSemver};
use util::{CargoResult, CargoError, ToSemver};
use core::source::SourceId;

/// Identifier for a specific version of a package in a specific source.
Expand Down Expand Up @@ -118,12 +118,6 @@ impl From<PackageIdError> for Box<CargoError> {
fn from(t: PackageIdError) -> Box<CargoError> { Box::new(t) }
}

#[derive(PartialEq, Eq, Hash, Clone, RustcEncodable, Debug)]
pub struct Metadata {
pub metadata: String,
pub extra_filename: String
}

impl PackageId {
pub fn new<T: ToSemver>(name: &str, version: T,
sid: &SourceId) -> CargoResult<PackageId> {
Expand All @@ -141,13 +135,6 @@ impl PackageId {
pub fn version(&self) -> &semver::Version { &self.inner.version }
pub fn source_id(&self) -> &SourceId { &self.inner.source_id }

pub fn generate_metadata(&self) -> Metadata {
let metadata = short_hash(self);
let extra_filename = format!("-{}", metadata);

Metadata { metadata: metadata, extra_filename: extra_filename }
}

pub fn with_precise(&self, precise: Option<String>) -> PackageId {
PackageId {
inner: Arc::new(PackageIdInner {
Expand All @@ -169,14 +156,6 @@ impl PackageId {
}
}

impl Metadata {
pub fn mix<T: Hash>(&mut self, t: &T) {
let new_metadata = short_hash(&(&self.metadata, t));
self.extra_filename = format!("-{}", new_metadata);
self.metadata = new_metadata;
}
}

impl fmt::Display for PackageId {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{} v{}", self.inner.name, self.inner.version)?;
Expand Down
14 changes: 10 additions & 4 deletions src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
cx.probe_target_info(&units)?;

for unit in units.iter() {
let layout = cx.layout(unit);
rm_rf(&layout.proxy().fingerprint(&unit.pkg))?;
rm_rf(&layout.build(&unit.pkg))?;
rm_rf(&cx.fingerprint_dir(unit))?;
if unit.target.is_custom_build() {
if unit.profile.run_custom_build {
rm_rf(&cx.build_script_out_dir(unit))?;
} else {
rm_rf(&cx.build_script_dir(unit))?;
}
continue
}

for (src, link_dst, _) in cx.target_filenames(&unit)? {
for (src, link_dst, _) in cx.target_filenames(unit)? {
rm_rf(&src)?;
if let Some(dst) = link_dst {
rm_rf(&dst)?;
Expand Down
Loading

0 comments on commit c82fd7f

Please sign in to comment.