Skip to content

Commit

Permalink
Remove source from compile_ws.
Browse files Browse the repository at this point in the history
This was added for `cargo install` to avoid updating the source multiple times.
Now that multiple updates are guarded via `Config::updated_sources`, it is
no longer necessary.
  • Loading branch information
ehuss committed Apr 16, 2019
1 parent 5553284 commit 8a30158
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 21 deletions.
7 changes: 3 additions & 4 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::core::compiler::{
use crate::core::compiler::{CompileMode, Kind, Unit};
use crate::core::profiles::{Profiles, UnitFor};
use crate::core::resolver::{Method, Resolve};
use crate::core::{Package, Source, Target};
use crate::core::{Package, Target};
use crate::core::{PackageId, PackageIdSpec, TargetKind, Workspace};
use crate::ops;
use crate::util::config::Config;
Expand Down Expand Up @@ -247,12 +247,11 @@ pub fn compile_with_exec<'a>(
exec: &Arc<dyn Executor>,
) -> CargoResult<Compilation<'a>> {
ws.emit_warnings()?;
compile_ws(ws, None, options, exec)
compile_ws(ws, options, exec)
}

pub fn compile_ws<'a>(
ws: &Workspace<'a>,
source: Option<Box<dyn Source + 'a>>,
options: &CompileOptions<'a>,
exec: &Arc<dyn Executor>,
) -> CargoResult<Compilation<'a>> {
Expand Down Expand Up @@ -305,7 +304,7 @@ pub fn compile_ws<'a>(
all_features,
uses_default_features: !no_default_features,
};
let resolve = ops::resolve_ws_with_method(ws, source, method, &specs)?;
let resolve = ops::resolve_ws_with_method(ws, method, &specs)?;
let (packages, resolve_with_overrides) = resolve;

let to_build_ids = specs
Expand Down
1 change: 0 additions & 1 deletion src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions<'_>) -> CargoResult<()> {
let specs = options.compile_opts.spec.to_package_id_specs(ws)?;
let resolve = ops::resolve_ws_precisely(
ws,
None,
&options.compile_opts.features,
options.compile_opts.all_features,
options.compile_opts.no_default_features,
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/ops/cargo_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn install_one(
) -> CargoResult<()> {
let config = opts.config;

let (pkg, source) = if source_id.is_git() {
let pkg = if source_id.is_git() {
select_pkg(
GitSource::new(source_id, config)?,
krate,
Expand Down Expand Up @@ -307,7 +307,7 @@ fn install_one(
check_yanked_install(&ws)?;

let exec: Arc<dyn Executor> = Arc::new(DefaultExecutor);
let compile = ops::compile_ws(&ws, Some(source), opts, &exec).chain_err(|| {
let compile = ops::compile_ws(&ws, opts, &exec).chain_err(|| {
if let Some(td) = td_opt.take() {
// preserve the temporary directory, so the user can inspect it
td.into_path();
Expand Down Expand Up @@ -489,7 +489,7 @@ fn check_yanked_install(ws: &Workspace<'_>) -> CargoResult<()> {
// It would be best if `source` could be passed in here to avoid a
// duplicate "Updating", but since `source` is taken by value, then it
// wouldn't be available for `compile_ws`.
let (pkg_set, resolve) = ops::resolve_ws_with_method(ws, None, Method::Everything, &specs)?;
let (pkg_set, resolve) = ops::resolve_ws_with_method(ws, Method::Everything, &specs)?;
let mut sources = pkg_set.sources_mut();
for pkg_id in resolve.iter() {
if let Some(source) = sources.get_mut(pkg_id.source_id()) {
Expand Down
1 change: 0 additions & 1 deletion src/cargo/ops/cargo_output_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ fn metadata_full(ws: &Workspace<'_>, opt: &OutputMetadataOptions) -> CargoResult
let specs = Packages::All.to_package_id_specs(ws)?;
let (package_set, resolve) = ops::resolve_ws_precisely(
ws,
None,
&opt.features,
opt.all_features,
opt.no_default_features,
Expand Down
3 changes: 1 addition & 2 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn build_lock(ws: &Workspace<'_>) -> CargoResult<String> {
let specs = vec![PackageIdSpec::from_package_id(new_pkg.package_id())];
let tmp_ws = Workspace::ephemeral(new_pkg, ws.config(), None, true)?;
let (pkg_set, new_resolve) =
ops::resolve_ws_with_method(&tmp_ws, None, Method::Everything, &specs)?;
ops::resolve_ws_with_method(&tmp_ws, Method::Everything, &specs)?;

if let Some(orig_resolve) = orig_resolve {
compare_resolve(config, tmp_ws.current()?, &orig_resolve, &new_resolve)?;
Expand Down Expand Up @@ -587,7 +587,6 @@ fn run_verify(ws: &Workspace<'_>, tar: &FileLock, opts: &PackageOpts<'_>) -> Car
let exec: Arc<dyn Executor> = Arc::new(DefaultExecutor);
ops::compile_ws(
&ws,
None,
&ops::CompileOptions {
config,
build_config: BuildConfig::new(config, opts.jobs, &opts.target, CompileMode::Build)?,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn uninstall_cwd(root: &Filesystem, bins: &[String], config: &Config) -> CargoRe
let tracker = InstallTracker::load(config, root)?;
let source_id = SourceId::for_path(config.cwd())?;
let src = path_source(source_id, config)?;
let (pkg, _source) = select_pkg(src, None, None, config, true, &mut |path| {
let pkg = select_pkg(src, None, None, config, true, &mut |path| {
path.read_packages()
})?;
let pkgid = pkg.package_id();
Expand Down
6 changes: 3 additions & 3 deletions src/cargo/ops/common_for_install_and_uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ pub fn select_pkg<'a, T>(
config: &Config,
needs_update: bool,
list_all: &mut dyn FnMut(&mut T) -> CargoResult<Vec<Package>>,
) -> CargoResult<(Package, Box<dyn Source + 'a>)>
) -> CargoResult<Package>
where
T: Source + 'a,
{
Expand Down Expand Up @@ -647,7 +647,7 @@ where
match deps.iter().map(|p| p.package_id()).max() {
Some(pkgid) => {
let pkg = Box::new(&mut source).download_now(pkgid, config)?;
Ok((pkg, Box::new(source)))
Ok(pkg)
}
None => {
let vers_info = vers
Expand Down Expand Up @@ -679,7 +679,7 @@ where
),
},
};
return Ok((pkg.clone(), Box::new(source)));
return Ok(pkg.clone());

fn multi_err(kind: &str, mut pkgs: Vec<&Package>) -> String {
pkgs.sort_unstable_by_key(|a| a.name());
Expand Down
7 changes: 1 addition & 6 deletions src/cargo/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ pub fn resolve_ws<'a>(ws: &Workspace<'a>) -> CargoResult<(PackageSet<'a>, Resolv
/// taking into account `paths` overrides and activated features.
pub fn resolve_ws_precisely<'a>(
ws: &Workspace<'a>,
source: Option<Box<dyn Source + 'a>>,
features: &[String],
all_features: bool,
no_default_features: bool,
Expand All @@ -49,19 +48,15 @@ pub fn resolve_ws_precisely<'a>(
uses_default_features: !no_default_features,
}
};
resolve_ws_with_method(ws, source, method, specs)
resolve_ws_with_method(ws, method, specs)
}

pub fn resolve_ws_with_method<'a>(
ws: &Workspace<'a>,
source: Option<Box<dyn Source + 'a>>,
method: Method<'_>,
specs: &[PackageIdSpec],
) -> CargoResult<(PackageSet<'a>, Resolve)> {
let mut registry = PackageRegistry::new(ws.config())?;
if let Some(source) = source {
registry.add_preloaded(source);
}
let mut add_patches = true;

let resolve = if ws.ignore_lock() {
Expand Down

0 comments on commit 8a30158

Please sign in to comment.