Skip to content

Commit

Permalink
Move 'source_ids_from_config' function into 'resolve' module
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-t authored and winger committed Mar 20, 2015
1 parent f841530 commit 2e7b2ba
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
34 changes: 5 additions & 29 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;

use core::registry::PackageRegistry;
use core::{Source, SourceId, PackageSet, Package, Target, PackageId};
use core::{Source, PackageSet, Package, Target, PackageId};
use core::resolver::Method;
use ops::{self, BuildOutput, ExecEngine};
use sources::{PathSource};
use util::config::{ConfigValue, Config};
use util::{CargoResult, internal, human, ChainError, profile};
use util::config::Config;
use util::{CargoResult, human, ChainError, profile};

/// Contains informations about how a package should be compiled.
pub struct CompileOptions<'a, 'b: 'a> {
Expand Down Expand Up @@ -91,7 +91,8 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
return Err(human("jobs must be at least 1"))
}

let override_ids = try!(source_ids_from_config(config, package.root()));
let override_ids = try!(ops::source_ids_from_config(config,
package.get_root()));

let (packages, resolve_with_overrides, sources) = {
let rustc_host = config.rustc_host().to_string();
Expand Down Expand Up @@ -160,31 +161,6 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
return Ok(ret);
}

fn source_ids_from_config(config: &Config, cur_path: &Path)
-> CargoResult<Vec<SourceId>> {

let configs = try!(config.values());
debug!("loaded config; configs={:?}", configs);
let config_paths = match configs.get("paths") {
Some(cfg) => cfg,
None => return Ok(Vec::new())
};
let paths = try!(config_paths.list().chain_error(|| {
internal("invalid configuration for the key `paths`")
}));

paths.iter().map(|&(ref s, ref p)| {
// The path listed next to the string is the config file in which the
// key was located, so we want to pop off the `.cargo/config` component
// to get the directory containing the `.cargo` folder.
p.parent().unwrap().parent().unwrap().join(s)
}).filter(|p| {
// Make sure we don't override the local package, even if it's in the
// list of override paths.
cur_path != &**p
}).map(|p| SourceId::for_path(&p)).collect()
}

fn scrape_build_config(config: &Config,
jobs: Option<u32>,
target: Option<String>) -> CargoResult<ops::BuildConfig> {
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pub use self::registry::{registry_login, search, http_proxy_exists, http_handle}
pub use self::registry::{modify_owners, yank, OwnersOptions};
pub use self::cargo_fetch::{fetch};
pub use self::cargo_pkgid::pkgid;
pub use self::resolve::{resolve_pkg, resolve_with_previous};
pub use self::resolve::{resolve_pkg, resolve_with_previous, source_ids_from_config};
pub use self::cargo_output_dependencies::{output_dependencies, OutputTo, OutputOptions};

mod cargo_clean;
mod cargo_compile;
Expand Down
26 changes: 25 additions & 1 deletion src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use core::{Package, PackageId, SourceId};
use core::registry::PackageRegistry;
use core::resolver::{self, Resolve, Method};
use ops;
use util::CargoResult;
use util::{CargoResult, ChainError, internal};
use util::config::Config;

/// Resolve all dependencies for the specified `package` using the previous
/// lockfile as a guide if present.
Expand Down Expand Up @@ -122,3 +123,26 @@ pub fn resolve_with_previous<'a>(registry: &mut PackageRegistry,
}
}
}

pub fn source_ids_from_config(config: &Config, cur_path: Path) -> CargoResult<Vec<SourceId>> {
let configs = try!(config.values());
debug!("loaded config; configs={:?}", configs);
let config_paths = match configs.get("paths") {
Some(cfg) => cfg,
None => return Ok(Vec::new())
};
let paths = try!(config_paths.list().chain_error(|| {
internal("invalid configuration for the key `paths`")
}));

paths.iter().map(|&(ref s, ref p)| {
// The path listed next to the string is the config file in which the
// key was located, so we want to pop off the `.cargo/config` component
// to get the directory containing the `.cargo` folder.
p.dir_path().dir_path().join(s.as_slice())
}).filter(|p| {
// Make sure we don't override the local package, even if it's in the
// list of override paths.
cur_path != *p
}).map(|p| SourceId::for_path(&p)).collect()
}

0 comments on commit 2e7b2ba

Please sign in to comment.