Skip to content

Commit

Permalink
Debugging session for rust-lang#26.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibabushkin committed Aug 10, 2017
1 parent 60881e9 commit 03d63ed
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/bin/cargo_semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extern crate cargo;
extern crate crates_io;
extern crate env_logger;
extern crate getopts;
#[macro_use]
extern crate log;

use crates_io::{Crate, Registry};

Expand Down Expand Up @@ -61,6 +63,8 @@ impl<'a> SourceInfo<'a> {
let source_id = SourceId::crates_io(config)?;
let source = source_id.load(config);

debug!("source id loaded: {:?}", source_id);

Ok(SourceInfo {
id: source_id,
source: source,
Expand Down Expand Up @@ -99,6 +103,7 @@ impl<'a> WorkInfo<'a> {
// TODO: fall back to locally cached package instance, or better yet, search for it
// first.
let package_id = PackageId::new(info.name, info.version, &source.id)?;
debug!("(remote) package id: {:?}", package_id);
let package = source.source.download(&package_id)?;
let workspace = Workspace::ephemeral(package.clone(), config, None, false)?;

Expand Down Expand Up @@ -130,7 +135,7 @@ impl<'a> WorkInfo<'a> {
/// and/or defaults, and dispatch the actual analysis.
// TODO: possibly reduce the complexity by finding where some info can be taken from directly
fn do_main(config: &Config, matches: &Matches) -> CargoResult<()> {
fn parse_arg(opt: &str) -> CargoResult<(&str, &str)> {
fn parse_arg(opt: &str) -> CargoResult<NameAndVersion> {
let mut split = opt.split('-');
let name = if let Some(n) = split.next() {
n
Expand All @@ -147,29 +152,26 @@ fn do_main(config: &Config, matches: &Matches) -> CargoResult<()> {
return Err("spec has to be of form `name-version`".into());
}

Ok((name, version))
Ok(NameAndVersion { name: name, version: version })
}

let mut source = SourceInfo::new(config)?;

let current = if let Some(opt) = matches.opt_str("C") {
let (name, version) = parse_arg(&opt)?;

let info = NameAndVersion { name: name, version: version };
WorkInfo::remote(config, &mut source, info)?
WorkInfo::remote(config, &mut source, parse_arg(&opt)?)?
} else {
WorkInfo::local(config, matches.opt_str("c").map(PathBuf::from))?
};

let name = current.package.name().to_owned();

let (stable, stable_version) = if let Some(opt) = matches.opt_str("S") {
let (name, version) = parse_arg(&opt)?;
let info = parse_arg(&opt)?;
let version = info.version.to_owned();

let info = NameAndVersion { name: name, version: version };
let work_info = WorkInfo::remote(config, &mut source, info)?;

(work_info, version.to_owned())
(work_info, version)
} else if let Some(path) = matches.opt_str("s") {
let work_info = WorkInfo::local(config, Some(PathBuf::from(path)))?;
let version = format!("{}", work_info.package.version());
Expand Down

0 comments on commit 03d63ed

Please sign in to comment.