Skip to content

Refactor the backend and improve fingerprint diagnostics #2022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: rust
rust:
- 1.1.0
- 1.2.0
- stable
- beta
Expand Down
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ path = "src/cargo/lib.rs"

[dependencies]
advapi32-sys = "0.1"
crates-io = { path = "src/crates-io", version = "0.1" }
crossbeam = "0.1"
curl = "0.2"
docopt = "0.6"
env_logger = "0.3"
Expand All @@ -32,12 +34,10 @@ libgit2-sys = "0.2"
log = "0.3"
num_cpus = "0.2"
regex = "0.1"
crates-io = { path = "src/crates-io", version = "0.1" }
rustc-serialize = "0.3"
semver = "0.1"
tar = "0.3"
term = "0.2"
threadpool = "0.1"
time = "0.1"
toml = "0.1"
url = "0.2"
Expand Down
39 changes: 39 additions & 0 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::default::Default;
use std::fmt;
use std::path::{PathBuf, Path};

use semver::Version;
Expand Down Expand Up @@ -116,6 +117,7 @@ pub struct Profile {
pub rpath: bool,
pub test: bool,
pub doc: bool,
pub run_custom_build: bool,
}

#[derive(Default, Clone, Debug)]
Expand All @@ -125,6 +127,7 @@ pub struct Profiles {
pub test: Profile,
pub bench: Profile,
pub doc: Profile,
pub custom_build: Profile,
}

/// Informations about a binary, a library, an example, etc. that is part of the
Expand Down Expand Up @@ -405,6 +408,19 @@ impl Target {
}
}

impl fmt::Display for Target {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self.kind {
TargetKind::Lib(..) => write!(f, "Target(lib)"),
TargetKind::Bin => write!(f, "Target(bin: {})", self.name),
TargetKind::Test => write!(f, "Target(test: {})", self.name),
TargetKind::Bench => write!(f, "Target(bench: {})", self.name),
TargetKind::Example => write!(f, "Target(example: {})", self.name),
TargetKind::CustomBuild => write!(f, "Target(script)"),
}
}
}

impl Profile {
pub fn default_dev() -> Profile {
Profile {
Expand Down Expand Up @@ -442,6 +458,13 @@ impl Profile {
..Profile::default_dev()
}
}

pub fn default_custom_build() -> Profile {
Profile {
run_custom_build: true,
..Profile::default_dev()
}
}
}

impl Default for Profile {
Expand All @@ -456,6 +479,22 @@ impl Default for Profile {
rpath: false,
test: false,
doc: false,
run_custom_build: false,
}
}
}

impl fmt::Display for Profile {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
if self.test {
write!(f, "Profile(test)")
} else if self.doc {
write!(f, "Profile(doc)")
} else if self.run_custom_build {
write!(f, "Profile(run)")
} else {
write!(f, "Profile(build)")
}

}
}
2 changes: 1 addition & 1 deletion src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#[cfg(test)] extern crate hamcrest;
#[macro_use] extern crate log;
extern crate crates_io as registry;
extern crate crossbeam;
extern crate curl;
extern crate docopt;
extern crate filetime;
Expand All @@ -18,7 +19,6 @@ extern crate rustc_serialize;
extern crate semver;
extern crate tar;
extern crate term;
extern crate threadpool;
extern crate time;
extern crate toml;
extern crate url;
Expand Down
11 changes: 8 additions & 3 deletions src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::Path;
use core::{Package, PackageSet, Profiles, Profile};
use core::source::{Source, SourceMap};
use util::{CargoResult, human, ChainError, Config};
use ops::{self, Layout, Context, BuildConfig, Kind};
use ops::{self, Layout, Context, BuildConfig, Kind, Unit};

pub struct CleanOptions<'a> {
pub spec: &'a [String],
Expand Down Expand Up @@ -61,8 +61,13 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> {
try!(rm_rf(&layout.fingerprint(&pkg)));
let profiles = [Profile::default_dev(), Profile::default_test()];
for profile in profiles.iter() {
for filename in try!(cx.target_filenames(&pkg, target, profile,
Kind::Target)).iter() {
let unit = Unit {
pkg: &pkg,
target: target,
profile: profile,
kind: Kind::Target,
};
for filename in try!(cx.target_filenames(&unit)).iter() {
try!(rm_rf(&layout.dest().join(&filename)));
try!(rm_rf(&layout.deps().join(&filename)));
}
Expand Down
19 changes: 7 additions & 12 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::env;
use std::fs::{self, File};
use std::fs;
use std::io::prelude::*;
use std::io;
use std::path::Path;

use rustc_serialize::{Decodable, Decoder};
Expand All @@ -11,7 +10,7 @@ use git2::Config as GitConfig;
use term::color::BLACK;

use util::{GitRepo, HgRepo, CargoResult, human, ChainError, internal};
use util::Config;
use util::{Config, paths};

use toml;

Expand Down Expand Up @@ -102,10 +101,6 @@ fn existing_vcs_repo(path: &Path) -> bool {
GitRepo::discover(path).is_ok() || HgRepo::discover(path).is_ok()
}

fn file(p: &Path, contents: &[u8]) -> io::Result<()> {
try!(File::create(p)).write_all(contents)
}

fn mk(config: &Config, path: &Path, name: &str,
opts: &NewOptions) -> CargoResult<()> {
let cfg = try!(global_config(config));
Expand All @@ -125,11 +120,11 @@ fn mk(config: &Config, path: &Path, name: &str,
match vcs {
VersionControl::Git => {
try!(GitRepo::init(path));
try!(file(&path.join(".gitignore"), ignore.as_bytes()));
try!(paths::write(&path.join(".gitignore"), ignore.as_bytes()));
},
VersionControl::Hg => {
try!(HgRepo::init(path));
try!(file(&path.join(".hgignore"), ignore.as_bytes()));
try!(paths::write(&path.join(".hgignore"), ignore.as_bytes()));
},
VersionControl::NoVcs => {
try!(fs::create_dir(path));
Expand All @@ -147,7 +142,7 @@ fn mk(config: &Config, path: &Path, name: &str,
(None, None, name, None) => name,
};

try!(file(&path.join("Cargo.toml"), format!(
try!(paths::write(&path.join("Cargo.toml"), format!(
r#"[package]
name = "{}"
version = "0.1.0"
Expand All @@ -157,13 +152,13 @@ authors = [{}]
try!(fs::create_dir(&path.join("src")));

if opts.bin {
try!(file(&path.join("src/main.rs"), b"\
try!(paths::write(&path.join("src/main.rs"), b"\
fn main() {
println!(\"Hello, world!\");
}
"));
} else {
try!(file(&path.join("src/lib.rs"), b"\
try!(paths::write(&path.join("src/lib.rs"), b"\
#[test]
fn it_works() {
}
Expand Down
13 changes: 8 additions & 5 deletions src/cargo/ops/cargo_rustc/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Compilation<'cfg> {
pub libraries: HashMap<PackageId, Vec<(Target, PathBuf)>>,

/// An array of all tests created during this compilation.
pub tests: Vec<(Package, Vec<(String, PathBuf)>)>,
pub tests: Vec<(Package, String, PathBuf)>,

/// An array of all binaries created.
pub binaries: Vec<PathBuf>,
Expand All @@ -37,7 +37,7 @@ pub struct Compilation<'cfg> {

/// Extra environment variables that were passed to compilations and should
/// be passed to future invocations of programs.
pub extra_env: HashMap<String, String>,
pub extra_env: HashMap<PackageId, Vec<(String, String)>>,

pub to_doc_test: Vec<Package>,

Expand Down Expand Up @@ -69,7 +69,8 @@ impl<'cfg> Compilation<'cfg> {
}

/// See `process`.
pub fn rustdoc_process(&self, pkg: &Package) -> CargoResult<CommandPrototype> {
pub fn rustdoc_process(&self, pkg: &Package)
-> CargoResult<CommandPrototype> {
self.process(CommandType::Rustdoc, pkg)
}

Expand Down Expand Up @@ -102,8 +103,10 @@ impl<'cfg> Compilation<'cfg> {
util::dylib_path_envvar()));
let mut cmd = try!(CommandPrototype::new(cmd, self.config));
cmd.env(util::dylib_path_envvar(), &search_path);
for (k, v) in self.extra_env.iter() {
cmd.env(k, v);
if let Some(env) = self.extra_env.get(pkg.package_id()) {
for &(ref k, ref v) in env {
cmd.env(k, v);
}
}

cmd.env("CARGO_MANIFEST_DIR", pkg.root())
Expand Down
Loading