Skip to content

Commit

Permalink
update to nightly cargo
Browse files Browse the repository at this point in the history
  • Loading branch information
QuietMisdreavus committed Oct 16, 2018
1 parent 960e3e4 commit 8f4691f
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 24 deletions.
91 changes: 83 additions & 8 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ failure = "0.1"
comrak = { version = "0.2.10", default-features = false }
toml = "0.4"
html5ever = "0.22"
cargo = "0.30"
cargo = { git = "https://github.com/rust-lang/cargo.git" }

# iron dependencies
iron = "0.5"
Expand Down
6 changes: 3 additions & 3 deletions src/db/add_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ fn get_readme(pkg: &Package) -> Result<Option<String>> {


fn get_rustdoc(pkg: &Package) -> Result<Option<String>> {
if pkg.manifest().targets()[0].src_path().is_absolute() {
read_rust_doc(pkg.manifest().targets()[0].src_path())
if pkg.manifest().targets()[0].src_path().path().is_absolute() {
read_rust_doc(pkg.manifest().targets()[0].src_path().path())
} else {
let mut path = PathBuf::from(try!(source_path(&pkg).ok_or_else(|| err_msg("File not found"))));
path.push(pkg.manifest().targets()[0].src_path());
path.push(pkg.manifest().targets()[0].src_path().path());
read_rust_doc(path.as_path())
}
}
Expand Down
40 changes: 28 additions & 12 deletions src/utils/build_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use std::sync::Arc;

use cargo::core::{SourceId, Dependency, Source, Package, Workspace};
use cargo::core::compiler::{DefaultExecutor, CompileMode, MessageFormat, BuildConfig, Executor};
use cargo::core::package::PackageSet;
use cargo::core::source::SourceMap;
use cargo::util::{CargoResult, Config, internal, Filesystem};
use cargo::sources::SourceConfigMap;
use cargo::ops::{self, Packages};
Expand All @@ -31,19 +33,25 @@ pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> Result
let config = try!(Config::default());
let source_id = try!(SourceId::crates_io(&config));

let source_map = try!(SourceConfigMap::new(&config));
let mut source = try!(source_map.load(&source_id));
let source_cfg_map = try!(SourceConfigMap::new(&config));
let mut source = try!(source_cfg_map.load(&source_id));

// update crates.io-index registry
try!(source.update());

let dep = try!(Dependency::parse_no_deprecated(name, vers, &source_id));
let deps = try!(source.query_vec(&dep));
let pkg = try!(deps.iter().map(|p| p.package_id()).max()
// FIXME: This is probably not a rusty way to handle options and results
// or maybe it is who knows...
.map(|pkgid| source.download(pkgid))
.unwrap_or(Err(internal("PKG download error"))));
let pkgid = try!(deps.iter().map(|p| p.package_id()).max()
// FIXME: This is probably not a rusty way to handle options and results
// or maybe it is who knows...
.ok_or(internal("no package id available")));

let mut source_map = SourceMap::new();
source_map.insert(source);

let pkg_set = try!(PackageSet::new(&[pkgid.clone()], source_map, &config));

let pkg = try!(pkg_set.get_one(&pkgid)).clone();

let current_dir = try!(env::current_dir());
let target_dir = PathBuf::from(current_dir).join("cratesfyi");
Expand Down Expand Up @@ -93,11 +101,13 @@ pub fn build_doc(name: &str, vers: Option<&str>, target: Option<&str>) -> Result
false),
target_rustc_args: None,
target_rustdoc_args: Some(rustdoc_args),
local_rustdoc_args: None,
export_dir: None,
};

let ws = try!(Workspace::ephemeral(pkg, &config, Some(Filesystem::new(target_dir)), false));
let exec: Arc<Executor> = Arc::new(DefaultExecutor);
let source = try!(source_cfg_map.load(&source_id));
try!(ops::compile_ws(&ws, Some(source), &opts, &exec));

Ok(try!(ws.current()).clone())
Expand All @@ -118,11 +128,17 @@ pub fn get_package(name: &str, vers: Option<&str>) -> CargoResult<Package> {

let dep = try!(Dependency::parse_no_deprecated(name, vers, &source_id));
let deps = try!(source.query_vec(&dep));
let pkg = try!(deps.iter().map(|p| p.package_id()).max()
// FIXME: This is probably not a rusty way to handle options and results
// or maybe it is who knows...
.map(|pkgid| source.download(pkgid))
.unwrap_or(Err(internal("PKG download error"))));
let pkgid = try!(deps.iter().map(|p| p.package_id()).max()
// FIXME: This is probably not a rusty way to handle options and results
// or maybe it is who knows...
.ok_or(internal("no package id available")));

let mut source_map = SourceMap::new();
source_map.insert(source);

let pkg_set = try!(PackageSet::new(&[pkgid.clone()], source_map, &config));

let pkg = try!(pkg_set.get_one(&pkgid)).clone();

Ok(pkg)
}
Expand Down

0 comments on commit 8f4691f

Please sign in to comment.