Skip to content

Commit

Permalink
Auto merge of #2091 - winger:master, r=alexcrichton
Browse files Browse the repository at this point in the history
API changes needed for https://github.com/winger/cargo-metadata external command.
See #1434 for previous discussion.
  • Loading branch information
bors committed Nov 3, 2015
2 parents 4e5f84e + 17726d3 commit 3767ad2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
81 changes: 46 additions & 35 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;

use core::registry::PackageRegistry;
use core::{Source, SourceId, PackageSet, Package, Target};
use core::{Source, SourceId, SourceMap, PackageSet, Package, Target};
use core::{Profile, TargetKind, Profiles};
use core::resolver::Method;
use core::resolver::{Method, Resolve};
use ops::{self, BuildOutput, ExecEngine};
use util::config::{ConfigValue, Config};
use util::{CargoResult, internal, human, ChainError, profile};
Expand Down Expand Up @@ -95,6 +95,48 @@ pub fn compile<'a>(manifest_path: &Path,
compile_pkg(&package, None, options)
}

pub fn resolve_dependencies<'a>(root_package: &Package,
config: &'a Config,
source: Option<Box<Source + 'a>>,
features: Vec<String>,
no_default_features: bool)
-> CargoResult<(Vec<Package>, Resolve, SourceMap<'a>)> {

let override_ids = try!(source_ids_from_config(config, root_package.root()));

let mut registry = PackageRegistry::new(config);

if let Some(source) = source {
registry.add_preloaded(root_package.package_id().source_id(), source);
}

// First, resolve the root_package's *listed* dependencies, as well as
// downloading and updating all remotes and such.
let resolve = try!(ops::resolve_pkg(&mut registry, root_package));

// Second, resolve with precisely what we're doing. Filter out
// transitive dependencies if necessary, specify features, handle
// overrides, etc.
let _p = profile::start("resolving w/ overrides...");

try!(registry.add_overrides(override_ids));

let method = Method::Required{
dev_deps: true, // TODO: remove this option?
features: &features,
uses_default_features: !no_default_features,
};

let resolved_with_overrides =
try!(ops::resolve_with_previous(&mut registry, root_package,
method, Some(&resolve), None));

let packages = try!(ops::get_resolved_packages(&resolved_with_overrides,
&mut registry));

Ok((packages, resolved_with_overrides, registry.move_sources()))
}

#[allow(deprecated)] // connect => join in 1.3
pub fn compile_pkg<'a>(root_package: &Package,
source: Option<Box<Source + 'a>>,
Expand All @@ -114,40 +156,9 @@ pub fn compile_pkg<'a>(root_package: &Package,
return Err(human("jobs must be at least 1"))
}

let override_ids = try!(source_ids_from_config(options.config, root_package.root()));

let (packages, resolve_with_overrides, sources) = {
let mut registry = PackageRegistry::new(options.config);

if let Some(source) = source {
registry.add_preloaded(root_package.package_id().source_id(), source);
}

// First, resolve the root_package's *listed* dependencies, as well as
// downloading and updating all remotes and such.
let resolve = try!(ops::resolve_pkg(&mut registry, root_package));

// Second, resolve with precisely what we're doing. Filter out
// transitive dependencies if necessary, specify features, handle
// overrides, etc.
let _p = profile::start("resolving w/ overrides...");

try!(registry.add_overrides(override_ids));

let method = Method::Required{
dev_deps: true, // TODO: remove this option?
features: &features,
uses_default_features: !no_default_features,
};

let resolved_with_overrides =
try!(ops::resolve_with_previous(&mut registry, root_package,
method, Some(&resolve), None));

let packages = try!(ops::get_resolved_packages(&resolved_with_overrides,
&mut registry));

(packages, resolved_with_overrides, registry.move_sources())
try!(resolve_dependencies(root_package, config, source, features,
no_default_features))
};

let mut invalid_spec = vec![];
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use self::cargo_clean::{clean, CleanOptions};
pub use self::cargo_compile::{compile, compile_pkg, CompileOptions};
pub use self::cargo_compile::{compile, compile_pkg, resolve_dependencies, CompileOptions};
pub use self::cargo_compile::{CompileFilter, CompileMode};
pub use self::cargo_read_manifest::{read_manifest,read_package,read_packages};
pub use self::cargo_rustc::{compile_targets, Compilation, Layout, Kind, Unit};
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/util/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ from_error! {
ProcessError,
git2::Error,
json::DecoderError,
json::EncoderError,
curl::ErrCode,
CliError,
toml::Error,
Expand All @@ -317,6 +318,7 @@ impl CargoError for semver::ReqParseError {}
impl CargoError for io::Error {}
impl CargoError for git2::Error {}
impl CargoError for json::DecoderError {}
impl CargoError for json::EncoderError {}
impl CargoError for curl::ErrCode {}
impl CargoError for ProcessError {}
impl CargoError for CargoTestError {}
Expand Down

0 comments on commit 3767ad2

Please sign in to comment.